Skip to content

Commit

Permalink
Merge 81d6161 into ae1e7c8
Browse files Browse the repository at this point in the history
  • Loading branch information
ximing committed Feb 10, 2024
2 parents ae1e7c8 + 81d6161 commit 5bb483d
Show file tree
Hide file tree
Showing 80 changed files with 9,841 additions and 15,224 deletions.
10 changes: 6 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
branches:
- master
- deploy
- v1
tags:
- v1
paths:
Expand All @@ -26,13 +27,14 @@ jobs:
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: use Node.js 10
- name: use Node.js 18
uses: actions/setup-node@v1
with:
node-version: '10.x'
- name: npm install
node-version: '18.x'
- name: pnpm install
run: |
npm install --registry=https://registry.npmjs.org
npm i -g pnpm
pnpm install --registry=https://registry.npmjs.org
npm run build
env:
CI: true
10 changes: 6 additions & 4 deletions .github/workflows/coveralls.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Use Node.js 10.x
- name: Use Node.js 18.x
uses: actions/setup-node@v1
with:
node-version: 10.x
node-version: 18.x

- name: npm install
run: npm install --registry=https://registry.npmjs.org
- name: pnpm install
run: |
npm i -g pnpm --registry=https://registry.npmjs.org
pnpm install --registry=https://registry.npmjs.org
- name: Run tests
run: npm run test:coverage
Expand Down
18 changes: 9 additions & 9 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
registry=https://registry.npm.taobao.org
disturl=https://npm.taobao.org/mirrors/node/
sass_binary_site=http://npm.taobao.org/mirrors/node-sass/
phantomjs_cdnurl=https://npm.taobao.org/mirrors/phantomjs/
profiler_binary_host_mirror=https://npm.taobao.org/mirrors/node-inspector/
fse_binary_host_mirror=https://npm.taobao.org/mirrors/fsevents/
chromedriver_cdnurl=http://npm.taobao.org/mirrors/chromedriver/
selenium_cdnurl=http://npm.taobao.org/mirrorss/selenium/
electron_mirror=https://npm.taobao.org/mirrors/electron/
registry=https://registry.npmmirror.com
disturl=https://npmmirror.com/mirrors/node/
sass_binary_site=http://npmmirror.com/mirrors/node-sass/
phantomjs_cdnurl=https://npmmirror.com/mirrors/phantomjs/
profiler_binary_host_mirror=https://npmmirror.com/mirrors/node-inspector/
fse_binary_host_mirror=https://npmmirror.com/mirrors/fsevents/
chromedriver_cdnurl=http://npmmirror.com/mirrors/chromedriver/
selenium_cdnurl=http://npmmirror.com/mirrorss/selenium/
electron_mirror=https://npmmirror.com/mirrors/electron/
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14
16
1 change: 0 additions & 1 deletion __tests__/es2015/hoisting.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ErrNotDefined } from '../../old-src/error';
import { run } from '../helper';

describe('es2015 hoisting spec:', () => {
Expand Down
1 change: 0 additions & 1 deletion __tests__/es5/assignment.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { run } from '../helper';
import { ErrNotDefined } from '../../old-src/error';

describe('assignment spec:', () => {
it('base', () => {
Expand Down
12 changes: 6 additions & 6 deletions __tests__/es5/scope.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { run } from '../helper';
import { ErrDuplicateDeclare } from '../../old-src/error';
import { ScopeType } from '../../old-src/types';
import { Scope } from '../../old-src/scope';
import { Context } from '../../old-src';
import { ScopeType } from 'jsvm2/lib';
import { Scope } from 'jsvm2/lib';
import { Context } from 'jsvm2/lib';

describe('for scope spec:', () => {
it('base root', function () {
Expand Down Expand Up @@ -60,7 +59,7 @@ describe('for scope spec:', () => {

expect(() => {
scope.declareLet('name', 'hello'); // redeclare
}).toThrowError(ErrDuplicateDeclare('name').message);
}).toThrowError(`Identifier 'name' has already been declared`);
});

it("onst can't be redeclare", () => {
Expand All @@ -72,9 +71,10 @@ describe('for scope spec:', () => {

expect(() => {
scope.declareConst('name', 'hello'); // redeclare
}).toThrowError(ErrDuplicateDeclare('name').message);
}).toThrowError( `Identifier 'name' has already been declared`);
});


it('delete variable from a scope', () => {
const scope = new Scope(ScopeType.Root, null);
scope.declareVar('name', 'ximing');
Expand Down
10 changes: 5 additions & 5 deletions __tests__/helper.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { transformEXP, transform } from '../src/compiler';
import { XYZ } from '../src/vm/vm';
import { JSVM } from '../src/vm/vm';

export const run = function (code, ctx = {}, hoisting = true, convertES5 = false) {
const script = transform(code, 'test.js', { hoisting, convertES5 });
const vm = new XYZ(Object.assign({ Map: Map, WeakMap: WeakMap, Set: Set, Proxy: Proxy }, ctx));
const vm = new JSVM(Object.assign({ Map: Map, WeakMap: WeakMap, Set: Set, Proxy: Proxy }, ctx));
// console.log(JSON.stringify(script.toJSON(), null, 2));
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const res = vm.go(script);
const res = vm.exec(script);
// console.log(res);
// console.log(JSON.stringify(script.toJSON(), null, 2));
// console.log(vm.realm.globalObj);
Expand All @@ -15,7 +15,7 @@ export const run = function (code, ctx = {}, hoisting = true, convertES5 = false

export const runExp = function (code: string, ctx = {}) {
const script = transformEXP(code);
const vm = new XYZ(ctx);
const res = vm.go(script);
const vm = new JSVM(ctx);
const res = vm.exec(script);
return res;
};
2 changes: 1 addition & 1 deletion benchmark/function.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as Benchmark from 'benchmark';

import { createContext, runInContext } from '../old-src/vm';
import { createContext, runInContext } from 'jsvm2';
import { parse } from '@babel/parser';

const ast = parse(
Expand Down
8 changes: 4 additions & 4 deletions benchmark/xyz.js → benchmark/jsvm3.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const { transform } = require('../lib/compiler');
const { XYZ } = require('../lib/vm/vm');
// const { XYZ } = require('../dist');
const { JSVM } = require('../lib/vm/vm');
// const { JSVM } = require('../dist');
const code = require('fs').readFileSync(require('path').join(__dirname, './benchmark.js'), 'utf-8');
const script = transform(code, 'sum.js', { hoisting: true, convertES5: false });

const vm1 = new XYZ({
const vm1 = new JSVM({
console,
require,
});

vm1.go(script);
vm1.exec(script);
Loading

0 comments on commit 5bb483d

Please sign in to comment.