Skip to content

Commit 2a79413

Browse files
committed
Add more harness file
1 parent 8178c1b commit 2a79413

File tree

4 files changed

+98
-27
lines changed

4 files changed

+98
-27
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
!.eslintrc.js
22
src/types.d.ts
33
lib/*
4+
src/harness.mjs

src/262_worker.mjs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
evalQ,
77
} from '../lib/engine262.mjs';
88
import { Inspector, createConsole } from '../lib/inspector.mjs';
9-
import { file1, file2 } from './harness.mjs';
9+
import { Test262HarnessFiles } from './harness.mjs';
1010

1111
let abortController = new AbortController();
1212
class WorkerInspector extends Inspector {
@@ -41,8 +41,6 @@ function recreateAgent(features, signal) {
4141
setSurroundingAgent(agent);
4242

4343
inspector.attachAgent(agent, []);
44-
inspector.preference.preview = true;
45-
// inspector.preference.previewDebug = true
4644
signal.addEventListener('abort', () => inspector.detachAgent(agent), { once: true });
4745

4846
const realm = new ManagedRealm({});
@@ -51,14 +49,12 @@ function recreateAgent(features, signal) {
5149
if (features.includes('test262-harness')) {
5250
createTest262Intrinsics(realm, false);
5351
evalQ((Q, X) => {
54-
const script1 = X(
55-
realm.compileScript(file1, { specifier: 'https://github.com/tc39/test262/blob/main/harness/assert.js' }),
56-
);
57-
const script2 = X(
58-
realm.compileScript(file2, { specifier: 'https://github.com/tc39/test262/blob/main/harness/sta.js' }),
59-
);
60-
realm.evaluateScript(script1);
61-
realm.evaluateScript(script2);
52+
for (const [specifier, file] of Object.entries(Test262HarnessFiles)) {
53+
const script = X(
54+
realm.compileScript(file, { specifier }),
55+
);
56+
realm.evaluateScript(script);
57+
}
6258
});
6359
}
6460
}

src/harness.mjs

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
export const file1 = `// Copyright (C) 2017 Ecma International. All rights reserved.
1+
// @ts-nocheck
2+
function assert_file() {
3+
// Copyright (C) 2017 Ecma International. All rights reserved.
24
// This code is governed by the BSD license found in the LICENSE file.
35
/*---
46
description: |
@@ -104,9 +106,9 @@ assert.throws = function (expectedErrorConstructor, func, message) {
104106
assert._formatIdentityFreeValue = function formatIdentityFreeValue(value) {
105107
switch (value === null ? 'null' : typeof value) {
106108
case 'string':
107-
return typeof JSON !== "undefined" ? JSON.stringify(value) : \`"$\{value}"\`;
109+
return typeof JSON !== "undefined" ? JSON.stringify(value) : `"${value}"`;
108110
case 'bigint':
109-
return \`$\{value}n\`;
111+
return `${value}n`;
110112
case 'number':
111113
if (value === 0 && 1 / value === -Infinity) return '-0';
112114
// falls through
@@ -128,8 +130,12 @@ assert._toString = function (value) {
128130
}
129131
throw err;
130132
}
131-
};`;
132-
export const file2 = `/// Copyright (c) 2012 Ecma International. All rights reserved.
133+
};
134+
135+
}
136+
137+
function sta() {
138+
// Copyright (c) 2012 Ecma International. All rights reserved.
133139
// This code is governed by the BSD license found in the LICENSE file.
134140
/*---
135141
description: |
@@ -153,4 +159,71 @@ Test262Error.thrower = function (message) {
153159

154160
function $DONOTEVALUATE() {
155161
throw "Test262: This statement should not be evaluated.";
156-
}`;
162+
}
163+
}
164+
165+
function compareArray() {
166+
// Copyright (C) 2017 Ecma International. All rights reserved.
167+
// This code is governed by the BSD license found in the LICENSE file.
168+
/*---
169+
description: |
170+
Compare the contents of two arrays
171+
defines: [compareArray]
172+
---*/
173+
174+
function compareArray(a, b) {
175+
if (b.length !== a.length) {
176+
return false;
177+
}
178+
179+
for (var i = 0; i < a.length; i++) {
180+
if (!compareArray.isSameValue(b[i], a[i])) {
181+
return false;
182+
}
183+
}
184+
return true;
185+
}
186+
187+
compareArray.isSameValue = function(a, b) {
188+
if (a === 0 && b === 0) return 1 / a === 1 / b;
189+
if (a !== a && b !== b) return true;
190+
191+
return a === b;
192+
};
193+
194+
compareArray.format = function(arrayLike) {
195+
return `[${[].map.call(arrayLike, String).join(', ')}]`;
196+
};
197+
198+
assert.compareArray = function(actual, expected, message) {
199+
message = message === undefined ? '' : message;
200+
201+
if (typeof message === 'symbol') {
202+
message = message.toString();
203+
}
204+
205+
assert(actual != null, `Actual argument shouldn't be nullish. ${message}`);
206+
assert(expected != null, `Expected argument shouldn't be nullish. ${message}`);
207+
var format = compareArray.format;
208+
var result = compareArray(actual, expected);
209+
210+
// The following prevents actual and expected from being iterated and evaluated
211+
// more than once unless absolutely necessary.
212+
if (!result) {
213+
assert(false, `Actual ${format(actual)} and expected ${format(expected)} should have the same contents. ${message}`);
214+
}
215+
};
216+
}
217+
218+
function toSource(f) {
219+
const str = f.toString();
220+
const start = str.indexOf('{') + 2;
221+
const end = str.lastIndexOf('}');
222+
return str.slice(start, end);
223+
}
224+
225+
export const Test262HarnessFiles = {
226+
'https://github.com/tc39/test262/blob/main/harness/assert.js': toSource(assert_file),
227+
'https://github.com/tc39/test262/blob/main/harness/sta.js': toSource(sta),
228+
'https://github.com/tc39/test262/blob/main/harness/compareArray.js': toSource(compareArray),
229+
};

src/worker.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const {
2323
setSurroundingAgent,
2424
inspect,
2525
FEATURES,
26-
} = /** @type {import('../../engine262/declaration/index.d.mts')} */ (self['@engine262/engine262'])
26+
} = /** @type {import('../../engine262/declaration/index.d.mts')} */ (self['@engine262/engine262']);
2727

2828
postMessage({ type: 'initialize', value: { FEATURES } });
2929

@@ -68,7 +68,7 @@ addEventListener('message', ({ data }) => {
6868
});
6969
return Value.undefined;
7070
}, 1, Value('print'), []);
71-
skipDebugger(CreateDataProperty(realm.GlobalObject, Value('print'), print))
71+
skipDebugger(CreateDataProperty(realm.GlobalObject, Value('print'), print));
7272

7373
{
7474
const console = OrdinaryObjectCreate(agent.intrinsic('%Object.prototype%'));
@@ -113,14 +113,15 @@ addEventListener('message', ({ data }) => {
113113
result = realm.evaluateScript(code, { specifier: 'code.js' });
114114
} else {
115115
result = evalQ((Q) => {
116-
const module = Q(realm.createSourceTextModule('code.mjs', code))
117-
Q(module.LoadRequestedModules())
118-
Q(module.Link())
119-
const promise = Q(skipDebugger(module.Evaluate()))
120-
if (promise.PromiseState === 'rejected') {
121-
return ThrowCompletion(promise.PromiseResult || Value.undefined)
122-
}
123-
})
116+
const module = Q(realm.createSourceTextModule('code.mjs', code));
117+
Q(module.LoadRequestedModules());
118+
Q(module.Link());
119+
const promise = Q(skipDebugger(module.Evaluate()));
120+
if (promise.PromiseState === 'rejected') {
121+
return ThrowCompletion(promise.PromiseResult || Value.undefined);
122+
}
123+
return undefined;
124+
});
124125
}
125126
if (result instanceof AbruptCompletion) {
126127
postMessage({

0 commit comments

Comments
 (0)