Implementation of ECMA-262 in JavaScript
npm install @casual-simulation/engine262#engine262:matrix.org.
.next() on the returned iterator.
thisValue for standard library functions.
unwind() function is used and replace it with yield*.
yield forces you to make the containing function to be a generator function, which means that callers of that function now also need to use yield or unwind().
diff
--- a/src/evaluator.mjs
+++ b/src/evaluator.mjs
@@ -232,6 +232,8 @@ export function* Evaluate(node) {
case 'GeneratorBody':
case 'AsyncGeneratorBody':
return yield* Evaluate_AnyFunctionBody(node);
+ case 'DoExpression':
+ return yield* Evaluate_Block(node.Block);
default:
throw new OutOfRange('Evaluate', node);
}
--- a/src/parser/ExpressionParser.mjs
+++ b/src/parser/ExpressionParser.mjs
@@ -579,6 +579,12 @@ export class ExpressionParser extends FunctionParser {
return this.parseRegularExpressionLiteral();
case Token.LPAREN:
return this.parseParenthesizedExpression();
+ case Token.DO: {
+ const node = this.startNode();
+ this.next();
+ node.Block = this.parseBlock();
+ return this.finishNode(node, 'DoExpression');
+ }
default:
return this.unexpected();
}
`
This simplicity applies to many other proposals, such as [optional chaining][],
[pattern matching][], [the pipeline operator][], and more. This engine has also
been used to find bugs in ECMA-262 and [test262][], the test suite for
conforming JavaScript implementations.
Requirements
To run engine262 itself, a engine with support for recent ECMAScript features
is needed. Additionally, the CLI (bin/engine262.js) and test262 runner
(test/test262/test262.js) require a recent version of Node.js.
Using engine262
Use it online: https://engine262.js.org
You can install the latest engine262 build from [GitHub Packages][].
If you install it globally, you can use the CLI like so:
$ engine262
Or, you can install it locally and use the API:
`js
'use strict';
const {
Agent,
setSurroundingAgent,
ManagedRealm,
Value,
CreateDataProperty,
inspect,
} = require('engine262');
const agent = new Agent({
// onDebugger() {},
// ensureCanCompileStrings() {},
// hasSourceTextAvailable() {},
// onNodeEvaluation() {},
// features: [],
});
setSurroundingAgent(agent);
const realm = new ManagedRealm({
// promiseRejectionTracker() {},
// resolveImportedModule() {},
// getImportMetaProperties() {},
// finalizeImportMeta() {},
// randomSeed() {},
});
realm.scope(() => {
// Add print function from host
const print = new Value((args) => {
console.log(...args.map((tmp) => inspect(tmp)));
return Value.undefined;
});
CreateDataProperty(realm.GlobalObject, new Value('print'), print);
});
realm.evaluateScript(
);
// a stream of numbers fills your console. it fills you with determination.
`
Testing engine262
This project can be run against [test262][], which is particularly useful
for developing new features and/or tests:
`sh
$ # build engine262
$ npm build
$ # update local test262 in test/test262/test262
$ git submodule update --init --recursive
$ # update local test262 to a pull request
$ pushd test/test262/test262
$ git fetch origin refs/pull/$PR_NUMBER/head && git checkout FETCH_HEAD
$ popd
$ # run specific tests
$ npm run test:test262 built-ins/AsyncGenerator*
$ # run all tests
$ npm run test:test262
``