Skip to content

Commit e920718

Browse files
committed
update for api changes
1 parent 5b9715e commit e920718

File tree

2 files changed

+40
-31
lines changed

2 files changed

+40
-31
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
node_modules
22
.env
3+
4+
.vercel

src/worker.js

Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@ importScripts('/engine262/engine262.js');
77

88
const {
99
Agent,
10-
Realm,
11-
Abstract,
12-
AbruptCompletion,
1310
Value,
11+
ManagedRealm,
12+
13+
Type,
14+
CreateDataProperty,
15+
OrdinaryObjectCreate,
16+
17+
AbruptCompletion,
1418
Throw,
19+
20+
setSurroundingAgent,
1521
inspect,
16-
Object: APIObject,
1722
FEATURES,
1823
} = self.engine262;
1924

@@ -28,24 +33,26 @@ addEventListener('message', ({ data }) => {
2833
const agent = new Agent({
2934
features: [...state.get('features')],
3035
});
36+
setSurroundingAgent(agent);
3137

32-
agent.scope(() => {
33-
const promises = new Set();
34-
const realm = new Realm({
35-
promiseRejectionTracker(promise, operation) {
36-
switch (operation) {
37-
case 'reject':
38-
promises.add(promise);
39-
break;
40-
case 'handle':
41-
promises.delete(promise);
42-
break;
43-
default:
44-
break;
45-
}
46-
},
47-
});
48-
const print = new Value(realm, (args) => {
38+
const promises = new Set();
39+
const realm = new ManagedRealm({
40+
promiseRejectionTracker(promise, operation) {
41+
switch (operation) {
42+
case 'reject':
43+
promises.add(promise);
44+
break;
45+
case 'handle':
46+
promises.delete(promise);
47+
break;
48+
default:
49+
break;
50+
}
51+
},
52+
});
53+
54+
realm.scope(() => {
55+
const print = new Value((args) => {
4956
postMessage({
5057
type: 'console',
5158
value: {
@@ -54,12 +61,12 @@ addEventListener('message', ({ data }) => {
5461
},
5562
});
5663
return Value.undefined;
57-
}, [], realm);
58-
Abstract.CreateDataProperty(realm.global, new Value(realm, 'print'), print);
64+
});
65+
CreateDataProperty(realm.GlobalObject, new Value('print'), print);
5966

6067
{
61-
const console = new APIObject(realm);
62-
Abstract.CreateDataProperty(realm.global, new Value(realm, 'console'), console);
68+
const console = OrdinaryObjectCreate(agent.intrinsic('%Object.prototype%'));
69+
CreateDataProperty(realm.GlobalObject, new Value('console'), console);
6370

6471
[
6572
'log',
@@ -68,13 +75,13 @@ addEventListener('message', ({ data }) => {
6875
'error',
6976
'clear',
7077
].forEach((method) => {
71-
const fn = new Value(realm, (args) => {
78+
const fn = new Value((args) => {
7279
postMessage({
7380
type: 'console',
7481
value: {
7582
method,
7683
values: args.map((a, i) => {
77-
if (i === 0 && Abstract.Type(a) === 'String') {
84+
if (i === 0 && Type(a) === 'String') {
7885
return a.stringValue();
7986
}
8087
return inspect(a);
@@ -83,7 +90,7 @@ addEventListener('message', ({ data }) => {
8390
});
8491
return Value.undefined;
8592
});
86-
Abstract.CreateDataProperty(console, new Value(realm, method), fn);
93+
CreateDataProperty(console, new Value(method), fn);
8794
});
8895
}
8996

@@ -107,7 +114,7 @@ addEventListener('message', ({ data }) => {
107114
if (!(result instanceof AbruptCompletion)) {
108115
result = module.Evaluate();
109116
if (result.PromiseState === 'rejected') {
110-
result = Throw(realm, result.PromiseResult);
117+
result = Throw(result.PromiseResult);
111118
}
112119
}
113120
}
@@ -117,7 +124,7 @@ addEventListener('message', ({ data }) => {
117124
type: 'console',
118125
value: {
119126
method: 'error',
120-
values: [inspect(result, realm)],
127+
values: [inspect(result)],
121128
},
122129
});
123130
}
@@ -126,7 +133,7 @@ addEventListener('message', ({ data }) => {
126133
postMessage({
127134
type: 'unhandledRejection',
128135
// eslint-disable-next-line no-use-before-define
129-
value: inspect(promise.PromiseResult, realm),
136+
value: inspect(promise.PromiseResult),
130137
});
131138
}
132139
});

0 commit comments

Comments
 (0)