Skip to content

Commit 5eb213d

Browse files
committed
update with new api
1 parent 4b9828c commit 5eb213d

2 files changed

Lines changed: 49 additions & 55 deletions

File tree

src/classic/worker.mjs

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import {
1515
createTest262Intrinsics,
1616
importBundledTest262Harness,
1717
boostTest262Harness,
18-
runJobQueue,
1918
} from '../../lib/engine262.mjs';
2019

2120
postMessage({
@@ -67,36 +66,36 @@ addEventListener('message', ({ data }) => {
6766

6867
const realm = new ManagedRealm({});
6968

70-
realm.scope(() => {
71-
const print = CreateBuiltinFunction((args) => {
69+
const pop = realm.pushTopContext();
70+
const print = CreateBuiltinFunction((args) => {
71+
postMessage({
72+
type: 'console',
73+
value: {
74+
method: 'log',
75+
values: args.map((a) => inspect(a)),
76+
},
77+
});
78+
return Value.undefined;
79+
}, 1, Value('print'), []);
80+
skipDebugger(CreateDataProperty(realm.GlobalObject, Value('print'), print));
81+
82+
createConsole(realm, {
83+
* default(method, args) {
7284
postMessage({
7385
type: 'console',
7486
value: {
75-
method: 'log',
76-
values: args.map((a) => inspect(a)),
87+
method,
88+
values: args.map((a, i) => {
89+
if (i === 0 && a instanceof JSStringValue) {
90+
return a.stringValue();
91+
}
92+
return inspect(a);
93+
}),
7794
},
7895
});
79-
return Value.undefined;
80-
}, 1, Value('print'), []);
81-
skipDebugger(CreateDataProperty(realm.GlobalObject, Value('print'), print));
82-
83-
createConsole(realm, {
84-
* default(method, args) {
85-
postMessage({
86-
type: 'console',
87-
value: {
88-
method,
89-
values: args.map((a, i) => {
90-
if (i === 0 && a instanceof JSStringValue) {
91-
return a.stringValue();
92-
}
93-
return inspect(a);
94-
}),
95-
},
96-
});
97-
}
98-
})
99-
});
96+
}
97+
})
98+
pop?.();
10099

101100
postMessage({
102101
type: 'console',
@@ -134,11 +133,9 @@ addEventListener('message', ({ data }) => {
134133
}
135134
}
136135
if (state.get('mode') === 'script') {
137-
result = realm.evaluateScript(code, { specifier: 'code.js' }, handleResult);
136+
realm.evaluateScript(code, { specifier: 'code.js' }, handleResult);
138137
} else {
139-
result = realm.evaluateModule(code, 'code.mjs', handleResult);
138+
realm.evaluateModule(code, 'code.mjs', handleResult);
140139
}
141-
if (!result) agent.resumeEvaluate({});
142-
runJobQueue();
143140
}
144141
});

src/devtools/262_worker.mjs

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ import {
44
Agent,
55
ManagedRealm,
66
createTest262Intrinsics,
7-
evalQ,
7+
X,
88
boostTest262Harness,
99
Get,
1010
Set,
1111
Value,
12-
Realm,
1312
Throw,
1413
CreateBuiltinFunction,
1514
JSStringValue,
@@ -76,34 +75,32 @@ function recreateAgent(features, signal) {
7675
});
7776
agent.hostDefinedOptions.hostHooks ??= {};
7877
agent.hostDefinedOptions.hostHooks.HostLoadImportedModule = composeModuleLoaders([builtinLoader])
79-
realm.scope(() => {
80-
const defineModule = CreateBuiltinFunction(function* defineModule([specifier, source]) {
81-
if (!(specifier instanceof JSStringValue)) {
82-
return Throw.TypeError('specifier is not a string');
83-
}
84-
if (!(source instanceof JSStringValue)) {
85-
return Throw.TypeError('source is not a string');
86-
}
87-
if (surroundingAgent.debugger_cannotPreview) {
88-
return surroundingAgent.debugger_cannotPreview;
89-
}
90-
virtualModuleSourceCache.set(specifier.stringValue(), source.stringValue());
91-
return Value.undefined;
92-
}, 2, 'defineModule', ['SourceText']);
93-
/** @type {import('../../lib/engine262.mjs').ECMAScriptFunctionObject} */ (/** @type {any} */ (defineModule)).SourceText = 'function defineModule(specifier, source) { [native code] }';
94-
CreateNonEnumerableDataPropertyOrThrow(realm.GlobalObject, Value('defineModule'), defineModule);
95-
});
78+
const pop = realm.pushTopContext();
79+
const defineModule = CreateBuiltinFunction(function* defineModule([specifier, source]) {
80+
if (!(specifier instanceof JSStringValue)) {
81+
return Throw.TypeError('specifier is not a string');
82+
}
83+
if (!(source instanceof JSStringValue)) {
84+
return Throw.TypeError('source is not a string');
85+
}
86+
if (surroundingAgent.debugger_cannotPreview) {
87+
return surroundingAgent.debugger_cannotPreview;
88+
}
89+
virtualModuleSourceCache.set(specifier.stringValue(), source.stringValue());
90+
return Value.undefined;
91+
}, 2, 'defineModule', ['SourceText']);
92+
/** @type {import('../../lib/engine262.mjs').ECMAScriptFunctionObject} */ (/** @type {any} */ (defineModule)).SourceText = 'function defineModule(specifier, source) { [native code] }';
93+
CreateNonEnumerableDataPropertyOrThrow(realm.GlobalObject, Value('defineModule'), defineModule);
94+
pop?.();
9695
}
9796

9897
if (features.includes('test262-harness')) {
9998
createTest262Intrinsics(realm, false, console.log);
10099
importBundledTest262Harness(realm);
101-
evalQ((_Q, X) => {
102-
realm.scope(() => {
103-
const consoleTrace = X(Get(X(Get(realm.GlobalObject, Value('console'))), Value('trace')));
104-
X(Set(realm.GlobalObject, Value('__consolePrintHandle__'), consoleTrace, Value.true));
105-
});
106-
});
100+
const pop = realm.pushTopContext();
101+
const consoleTrace = X(Get(X(Get(realm.GlobalObject, Value('console'))), Value('trace')));
102+
X(Set(realm.GlobalObject, Value('__consolePrintHandle__'), consoleTrace, Value.true));
103+
pop?.();
107104
boostTest262Harness(realm);
108105
}
109106
}

0 commit comments

Comments
 (0)