@engine262/engine262 0.0.1-093c8cb33fc82c295390da3d9e124c21ad7e6281

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,12 @@
1
+ # These are supported funding model platforms
2
+
3
+ github: [engine262, devsnek] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
4
+ patreon: # Replace with a single Patreon username
5
+ open_collective: # Replace with a single Open Collective username
6
+ ko_fi: # Replace with a single Ko-fi username
7
+ tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8
+ community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9
+ liberapay: # Replace with a single Liberapay username
10
+ issuehunt: # Replace with a single IssueHunt username
11
+ otechie: # Replace with a single Otechie username
12
+ custom: # Replace with a single custom sponsorship URL
@@ -0,0 +1,50 @@
1
+ name: publish
2
+
3
+ on:
4
+ workflow_run:
5
+ workflows:
6
+ - test
7
+ branches: [main]
8
+ types:
9
+ - completed
10
+
11
+ jobs:
12
+ publish:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ # Set everything up
16
+ - uses: actions/checkout@v2
17
+ with:
18
+ persist-credentials: false
19
+ - uses: actions/setup-node@master
20
+ with:
21
+ node-version: 17
22
+ - run: git submodule update --init --recursive
23
+
24
+ # Run tests and whatnot
25
+ - run: npm install
26
+ - run: npm run build
27
+
28
+ # Publish to github registry
29
+ - run: npm set //npm.pkg.github.com/:_authToken ${{ github.token }}
30
+ - run: npm config set registry https://npm.pkg.github.com
31
+ - run: npm publish --access=public
32
+
33
+ # Publish to npm registry
34
+ - run: npm set //registry.npmjs.org/:_authToken ${{ secrets.NPM_TOKEN }}
35
+ - run: npm config set registry https://registry.npmjs.org
36
+ - run: npm publish --access=public
37
+
38
+ # Push build to to gh-pages
39
+ - run: |
40
+ git config --global user.email "gha@example.com"
41
+ git config --global user.name "GHA"
42
+ git remote add github "https://$GITHUB_ACTOR:$BETTER_GITHUB_TOKEN@github.com/$GITHUB_REPOSITORY.git"
43
+ git fetch github
44
+ git checkout gh-pages
45
+ cp dist/* .
46
+ git add engine262.*
47
+ git commit -m "autobuild" || exit 0 # exit silently if nothing changed
48
+ git push -u github gh-pages
49
+ env:
50
+ BETTER_GITHUB_TOKEN: ${{secrets.BETTER_GITHUB_TOKEN}}
@@ -0,0 +1,30 @@
1
+ name: test
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ runs-on: ubuntu-latest
8
+ steps:
9
+ # Set everything up
10
+ - uses: actions/checkout@v2
11
+ with:
12
+ persist-credentials: false
13
+ - uses: actions/setup-node@master
14
+ with:
15
+ node-version: 15
16
+ - run: git submodule update --init --recursive
17
+
18
+ # Run tests and whatnot
19
+ - run: npm install
20
+ - run: npm run build
21
+ - run: npm run lint
22
+ - run: npm run coverage
23
+ env:
24
+ CONTINUOUS_INTEGRATION: 1
25
+
26
+ # Upload coverage data
27
+ - name: Coveralls
28
+ uses: coverallsapp/github-action@master
29
+ with:
30
+ github-token: ${{github.token}}
package/.gitmodules ADDED
@@ -0,0 +1,6 @@
1
+ [submodule "test/JSONTestSuite"]
2
+ path = test/json/JSONTestSuite
3
+ url = https://github.com/nst/JSONTestSuite
4
+ [submodule "test/test262/test262"]
5
+ path = test/test262/test262
6
+ url = https://github.com/tc39/test262
@@ -0,0 +1,46 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ ## Our Standards
8
+
9
+ Examples of behavior that contributes to creating a positive environment include:
10
+
11
+ * Using welcoming and inclusive language
12
+ * Being respectful of differing viewpoints and experiences
13
+ * Gracefully accepting constructive criticism
14
+ * Focusing on what is best for the community
15
+ * Showing empathy towards other community members
16
+
17
+ Examples of unacceptable behavior by participants include:
18
+
19
+ * The use of sexualized language or imagery and unwelcome sexual attention or advances
20
+ * Trolling, insulting/derogatory comments, and personal or political attacks
21
+ * Public or private harassment
22
+ * Publishing others' private information, such as a physical or electronic address, without explicit permission
23
+ * Other conduct which could reasonably be considered inappropriate in a professional setting
24
+
25
+ ## Our Responsibilities
26
+
27
+ Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28
+
29
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30
+
31
+ ## Scope
32
+
33
+ This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34
+
35
+ ## Enforcement
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at devsnek@users.noreply.github.com. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38
+
39
+ Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40
+
41
+ ## Attribution
42
+
43
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]
44
+
45
+ [homepage]: http://contributor-covenant.org
46
+ [version]: http://contributor-covenant.org/version/1/4/
package/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2018 engine262 Contributors
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to
5
+ deal in the Software without restriction, including without limitation the
6
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
+ sell copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19
+ IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,163 @@
1
+ # engine262
2
+
3
+ An implementation of ECMA-262 in JavaScript
4
+
5
+ Goals
6
+ - 100% Spec Compliance
7
+ - Introspection
8
+ - Ease of modification
9
+
10
+ Non-Goals
11
+ - Speed at the expense of any of the goals
12
+
13
+ This project is bound by a [Code of Conduct][COC].
14
+
15
+ Join us on [#engine262 on freenode][irc] ([web][irc-webchat]).
16
+
17
+ ## Why this exists
18
+
19
+ While helping develop new features for JavaScript, I've found that one of the
20
+ most useful methods of finding what works and what doesn't is being able to
21
+ actually run code using the new feature. [Babel][] is fantastic for this, but
22
+ sometimes features just can't be nicely represented with it. Similarly,
23
+ implementing a feature in one of the engines is a large undertaking, involving
24
+ long compile times and annoying bugs with the optimizing compilers.
25
+
26
+ engine262 is a tool to allow JavaScript developers to have a sandbox where new
27
+ features can be quickly prototyped and explored. As an example, adding
28
+ [do expressions][] to this engine is as simple as the following diff:
29
+
30
+ ```diff
31
+ --- a/src/evaluator.mjs
32
+ +++ b/src/evaluator.mjs
33
+ @@ -232,6 +232,8 @@ export function* Evaluate(node) {
34
+ case 'GeneratorBody':
35
+ case 'AsyncGeneratorBody':
36
+ return yield* Evaluate_AnyFunctionBody(node);
37
+ + case 'DoExpression':
38
+ + return yield* Evaluate_Block(node.Block);
39
+ default:
40
+ throw new OutOfRange('Evaluate', node);
41
+ }
42
+ --- a/src/parser/ExpressionParser.mjs
43
+ +++ b/src/parser/ExpressionParser.mjs
44
+ @@ -579,6 +579,12 @@ export class ExpressionParser extends FunctionParser {
45
+ return this.parseRegularExpressionLiteral();
46
+ case Token.LPAREN:
47
+ return this.parseParenthesizedExpression();
48
+ + case Token.DO: {
49
+ + const node = this.startNode();
50
+ + this.next();
51
+ + node.Block = this.parseBlock();
52
+ + return this.finishNode(node, 'DoExpression');
53
+ + }
54
+ default:
55
+ return this.unexpected();
56
+ }
57
+ ```
58
+
59
+ This simplicity applies to many other proposals, such as [optional chaining][],
60
+ [pattern matching][], [the pipeline operator][], and more. This engine has also
61
+ been used to find bugs in ECMA-262 and test262, the test suite for
62
+ conforming JavaScript implementations.
63
+
64
+ ## Requirements
65
+
66
+ To run engine262 itself, a engine with support for recent ECMAScript features
67
+ is needed. Additionally, the CLI (`bin/engine262.js`) and test262 runner
68
+ (`test/test262.js`) require a recent version of Node.js.
69
+
70
+ ## Using engine262
71
+
72
+ Use it online: https://engine262.js.org
73
+
74
+ You can install the latest engine262 build from [GitHub Packages][].
75
+
76
+ If you install it globally, you can use the CLI like so:
77
+
78
+ `$ engine262`
79
+
80
+ Or, you can install it locally and use the API:
81
+
82
+ ```js
83
+ 'use strict';
84
+
85
+ const {
86
+ Agent,
87
+ setSurroundingAgent,
88
+ ManagedRealm,
89
+ Value,
90
+
91
+ CreateDataProperty,
92
+
93
+ inspect,
94
+ } = require('engine262');
95
+
96
+ const agent = new Agent({
97
+ // onDebugger() {},
98
+ // ensureCanCompileStrings() {},
99
+ // hasSourceTextAvailable() {},
100
+ // onNodeEvaluation() {},
101
+ // features: [],
102
+ });
103
+ setSurroundingAgent(agent);
104
+
105
+ const realm = new ManagedRealm({
106
+ // promiseRejectionTracker() {},
107
+ // resolveImportedModule() {},
108
+ // getImportMetaProperties() {},
109
+ // finalizeImportMeta() {},
110
+ // randomSeed() {},
111
+ });
112
+
113
+ realm.scope(() => {
114
+ // Add print function from host
115
+ const print = new Value((args) => {
116
+ console.log(...args.map((tmp) => inspect(tmp)));
117
+ return Value.undefined;
118
+ });
119
+ CreateDataProperty(realm.GlobalObject, new Value('print'), print);
120
+ });
121
+
122
+ realm.evaluateScript(`
123
+ 'use strict';
124
+
125
+ async function* numbers() {
126
+ let i = 0;
127
+ while (true) {
128
+ const n = await Promise.resolve(i++);
129
+ yield n;
130
+ }
131
+ }
132
+
133
+ (async () => {
134
+ for await (const item of numbers()) {
135
+ print(item);
136
+ }
137
+ })();
138
+ `);
139
+
140
+ // a stream of numbers fills your console. it fills you with determination.
141
+ ```
142
+
143
+ ## Related Projects
144
+
145
+ Many people and organizations have attempted to write a JavaScript interpreter
146
+ in JavaScript much like engine262, with different goals. Some of them are
147
+ included here for reference, though engine262 is not based on any of them.
148
+
149
+ - https://github.com/facebook/prepack
150
+ - https://github.com/mozilla/narcissus
151
+ - https://github.com/NeilFraser/JS-Interpreter
152
+ - https://github.com/metaes/metaes
153
+ - https://github.com/Siubaak/sval
154
+
155
+ [Babel]: https://babeljs.io/
156
+ [COC]: https://github.com/engine262/engine262/blob/master/CODE_OF_CONDUCT.md
157
+ [do expressions]: https://github.com/tc39/proposal-do-expressions
158
+ [irc]: ircs://chat.freenode.net:6697/engine262
159
+ [irc-webchat]: https://webchat.freenode.net/?channels=engine262
160
+ [optional chaining]: https://github.com/tc39/proposal-optional-chaining
161
+ [pattern matching]: https://github.com/tc39/proposal-pattern-matching
162
+ [the pipeline operator]: https://github.com/tc39/proposal-pipeline-operator
163
+ [GitHub Packages]: https://github.com/engine262/engine262/packages
@@ -0,0 +1,215 @@
1
+ #!/usr/bin/env node
2
+
3
+ 'use strict';
4
+
5
+ /* eslint-disable import/order */
6
+
7
+ try {
8
+ require('@snek/source-map-support/register');
9
+ } catch {
10
+ // empty
11
+ }
12
+
13
+ const repl = require('repl');
14
+ const fs = require('fs');
15
+ const path = require('path');
16
+ const util = require('util');
17
+ const packageJson = require('../package.json');
18
+ const snekparse = require('./snekparse');
19
+ const {
20
+ Agent,
21
+ setSurroundingAgent,
22
+
23
+ FEATURES,
24
+ inspect,
25
+
26
+ Value,
27
+
28
+ CreateBuiltinFunction,
29
+ CreateDataProperty,
30
+ OrdinaryObjectCreate,
31
+ Type,
32
+
33
+ Completion,
34
+ AbruptCompletion,
35
+ Throw,
36
+ } = require('..');
37
+ const { createRealm } = require('./test262_realm');
38
+
39
+ const execArgv = [];
40
+ let entry;
41
+ const programArgv = [];
42
+
43
+ {
44
+ let target = execArgv;
45
+ process.argv.slice(2).forEach((a) => {
46
+ if (a.startsWith('--')) {
47
+ target.push(a);
48
+ } else if (!entry) {
49
+ entry = a;
50
+ target = programArgv;
51
+ } else {
52
+ target.push(a);
53
+ }
54
+ });
55
+ }
56
+
57
+ const help = `
58
+ engine262 v${require('../package.json').version}
59
+
60
+ Usage:
61
+
62
+ engine262 [options]
63
+ engine262 [options] [input file]
64
+ engine262 [input file]
65
+
66
+ Options:
67
+
68
+ -h, --help Show help (this screen)
69
+ -m, --module Evaluate contents of input-file as a module.
70
+ Must be followed by input-file
71
+ --features=... A comma separated list of features. If no features
72
+ are provided, the available features are listed.
73
+
74
+ `;
75
+
76
+ const argv = snekparse(execArgv);
77
+
78
+ if (argv.h || argv.help) {
79
+ process.stdout.write(help);
80
+ process.exit(0);
81
+ } else if (argv.features === true) {
82
+ let nameLength = 0;
83
+ let flagLength = 0;
84
+ FEATURES.forEach((f) => {
85
+ if (f.name.length > nameLength) {
86
+ nameLength = f.name.length;
87
+ }
88
+ if (f.flag.length > flagLength) {
89
+ flagLength = f.flag.length;
90
+ }
91
+ });
92
+ const log = (n, f, u) => {
93
+ process.stdout.write(`${n.padEnd(nameLength, ' ')} ${f.padEnd(flagLength, ' ')} ${u}\n`);
94
+ };
95
+ log('name', 'flag', 'url');
96
+ log('----', '----', '---');
97
+ FEATURES.forEach((f) => {
98
+ log(f.name, f.flag, f.url);
99
+ });
100
+ process.exit(0);
101
+ }
102
+
103
+ let features;
104
+ if (argv.features === 'all') {
105
+ features = FEATURES.map((f) => f.flag);
106
+ } else if (argv.features) {
107
+ features = argv.features.split(',');
108
+ } else {
109
+ features = [];
110
+ }
111
+
112
+ const agent = new Agent({ features });
113
+ setSurroundingAgent(agent);
114
+
115
+ const { realm, resolverCache } = createRealm({ printCompatMode: true });
116
+ realm.scope(() => {
117
+ const console = OrdinaryObjectCreate(realm.Intrinsics['%Object.prototype%']);
118
+ CreateDataProperty(realm.GlobalObject, new Value('console'), console);
119
+
120
+ const format = (args) => args.map((a, i) => {
121
+ if (i === 0 && Type(a) === 'String') {
122
+ return a.stringValue();
123
+ }
124
+ return inspect(a);
125
+ }).join(' ');
126
+
127
+ const log = CreateBuiltinFunction((args) => {
128
+ process.stdout.write(`${format(args)}\n`);
129
+ return Value.undefined;
130
+ }, 1, new Value('log'), []);
131
+ CreateDataProperty(console, new Value('log'), log);
132
+
133
+ const error = CreateBuiltinFunction((args) => {
134
+ process.stderr.write(`${format(args)}\n`);
135
+ return Value.undefined;
136
+ }, 1, new Value('error'), []);
137
+ CreateDataProperty(console, new Value('error'), error);
138
+
139
+ const debug = CreateBuiltinFunction((args) => {
140
+ process.stderr.write(`${util.format(...args)}\n`);
141
+ return Value.undefined;
142
+ }, 1, new Value('debug'), []);
143
+ CreateDataProperty(console, new Value('debug'), debug);
144
+ });
145
+
146
+ if (argv.inspector) {
147
+ const inspector = require('../inspector');
148
+ inspector.attachRealm(realm);
149
+ }
150
+
151
+ function oneShotEval(source, filename) {
152
+ realm.scope(() => {
153
+ let result;
154
+ if (argv.m || argv.module || filename.endsWith('.mjs')) {
155
+ result = realm.createSourceTextModule(filename, source);
156
+ if (!(result instanceof AbruptCompletion)) {
157
+ const module = result;
158
+ resolverCache.set(filename, result);
159
+ result = module.Link();
160
+ if (!(result instanceof AbruptCompletion)) {
161
+ result = module.Evaluate();
162
+ }
163
+ if (!(result instanceof AbruptCompletion)) {
164
+ if (result.PromiseState === 'rejected') {
165
+ result = Throw(result.PromiseResult);
166
+ }
167
+ }
168
+ }
169
+ } else {
170
+ result = realm.evaluateScript(source, { specifier: filename });
171
+ }
172
+ if (result instanceof AbruptCompletion) {
173
+ const inspected = inspect(result);
174
+ process.stderr.write(`${inspected}\n`);
175
+ process.exit(1);
176
+ }
177
+ });
178
+ }
179
+
180
+ if (entry) {
181
+ const source = fs.readFileSync(entry, 'utf8');
182
+ oneShotEval(source, path.resolve(entry));
183
+ } else if (!process.stdin.isTTY) {
184
+ process.stdin.setEncoding('utf8');
185
+ let source = '';
186
+ process.stdin.on('data', (data) => {
187
+ source += data;
188
+ });
189
+ process.stdin.once('end', () => {
190
+ oneShotEval(source, process.cwd());
191
+ });
192
+ } else {
193
+ process.stdout.write(`${packageJson.name} v${packageJson.version}
194
+ Please report bugs to ${packageJson.bugs.url}
195
+ `);
196
+ repl.start({
197
+ prompt: '> ',
198
+ eval: (cmd, context, filename, callback) => {
199
+ try {
200
+ const result = realm.evaluateScript(cmd, { specifier: '(engine262)' });
201
+ callback(null, result);
202
+ } catch (e) {
203
+ callback(e, null);
204
+ }
205
+ },
206
+ preview: false,
207
+ completer: () => [],
208
+ writer: (o) => realm.scope(() => {
209
+ if (o instanceof Value || o instanceof Completion) {
210
+ return inspect(o);
211
+ }
212
+ return util.inspect(o);
213
+ }),
214
+ });
215
+ }
@@ -0,0 +1,76 @@
1
+ 'use strict';
2
+
3
+ function snekparse(args) {
4
+ if (typeof args === 'string') {
5
+ args = args.split(' ');
6
+ }
7
+ const argv = [];
8
+ for (let i = 0; i < args.length; i += 1) {
9
+ const arg = args[i];
10
+ if (/^--.+=/.test(arg)) {
11
+ const match = arg.match(/^--([^=]+)=([\s\S]*)$/);
12
+ argv[match[1]] = match[2];
13
+ } else if (/^--no-.+/.test(arg)) {
14
+ argv[arg.match(/^--no-(.+)/)[1]] = false;
15
+ } else if (/^--.+/.test(arg)) {
16
+ const key = arg.match(/^--(.+)/)[1];
17
+ const next = args[i + 1];
18
+ if (typeof next !== 'undefined' && !/^-/.test(next)) {
19
+ argv[key] = next;
20
+ } else if (/^(true|false)$/.test(next)) {
21
+ argv[key] = next === 'true';
22
+ } else {
23
+ argv[key] = true;
24
+ }
25
+ } else if (/^-[^-]+/.test(arg)) {
26
+ const letters = arg.slice(1, -1).split('');
27
+ let broken = false;
28
+ for (const j of letters) {
29
+ const next = arg.slice(j + 2);
30
+
31
+ if (next === '-') {
32
+ argv[letters[j]] = next;
33
+ continue;
34
+ }
35
+
36
+ if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {
37
+ argv[letters[j]] = next.split('=')[1];
38
+ broken = true;
39
+ break;
40
+ }
41
+
42
+ if (/[A-Za-z]/.test(letters[j])
43
+ && /-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) {
44
+ argv[letters[j]] = next;
45
+ broken = true;
46
+ break;
47
+ }
48
+
49
+ if (letters[j + 1] && letters[j + 1].match(/\W/)) {
50
+ argv[letters[j]] = arg.slice(j + 2);
51
+ broken = true;
52
+ break;
53
+ } else {
54
+ argv[letters[j]] = true;
55
+ }
56
+ }
57
+
58
+ const key = arg.slice(-1)[0];
59
+ if (!broken && key !== '-') {
60
+ if (args[i + 1] && !/^(-|--)[^-]/.test(args[i + 1])) {
61
+ argv[key] = args[i + 1];
62
+ } else if (args[i + 1] && /true|false/.test(args[i + 1])) {
63
+ argv[key] = args[i + 1] === 'true';
64
+ } else {
65
+ argv[key] = true;
66
+ }
67
+ }
68
+ } else {
69
+ argv.push(arg);
70
+ }
71
+ }
72
+
73
+ return argv;
74
+ }
75
+
76
+ module.exports = snekparse;