Skip to content

Commit

Permalink
update for api changes
Browse files Browse the repository at this point in the history
  • Loading branch information
devsnek committed Aug 5, 2020
1 parent 5b9715e commit e920718
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 31 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,2 +1,4 @@
node_modules
.env

.vercel
69 changes: 38 additions & 31 deletions src/worker.js
Expand Up @@ -7,13 +7,18 @@ importScripts('/engine262/engine262.js');

const {
Agent,
Realm,
Abstract,
AbruptCompletion,
Value,
ManagedRealm,

Type,
CreateDataProperty,
OrdinaryObjectCreate,

AbruptCompletion,
Throw,

setSurroundingAgent,
inspect,
Object: APIObject,
FEATURES,
} = self.engine262;

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

agent.scope(() => {
const promises = new Set();
const realm = new Realm({
promiseRejectionTracker(promise, operation) {
switch (operation) {
case 'reject':
promises.add(promise);
break;
case 'handle':
promises.delete(promise);
break;
default:
break;
}
},
});
const print = new Value(realm, (args) => {
const promises = new Set();
const realm = new ManagedRealm({
promiseRejectionTracker(promise, operation) {
switch (operation) {
case 'reject':
promises.add(promise);
break;
case 'handle':
promises.delete(promise);
break;
default:
break;
}
},
});

realm.scope(() => {
const print = new Value((args) => {
postMessage({
type: 'console',
value: {
Expand All @@ -54,12 +61,12 @@ addEventListener('message', ({ data }) => {
},
});
return Value.undefined;
}, [], realm);
Abstract.CreateDataProperty(realm.global, new Value(realm, 'print'), print);
});
CreateDataProperty(realm.GlobalObject, new Value('print'), print);

{
const console = new APIObject(realm);
Abstract.CreateDataProperty(realm.global, new Value(realm, 'console'), console);
const console = OrdinaryObjectCreate(agent.intrinsic('%Object.prototype%'));
CreateDataProperty(realm.GlobalObject, new Value('console'), console);

[
'log',
Expand All @@ -68,13 +75,13 @@ addEventListener('message', ({ data }) => {
'error',
'clear',
].forEach((method) => {
const fn = new Value(realm, (args) => {
const fn = new Value((args) => {
postMessage({
type: 'console',
value: {
method,
values: args.map((a, i) => {
if (i === 0 && Abstract.Type(a) === 'String') {
if (i === 0 && Type(a) === 'String') {
return a.stringValue();
}
return inspect(a);
Expand All @@ -83,7 +90,7 @@ addEventListener('message', ({ data }) => {
});
return Value.undefined;
});
Abstract.CreateDataProperty(console, new Value(realm, method), fn);
CreateDataProperty(console, new Value(method), fn);
});
}

Expand All @@ -107,7 +114,7 @@ addEventListener('message', ({ data }) => {
if (!(result instanceof AbruptCompletion)) {
result = module.Evaluate();
if (result.PromiseState === 'rejected') {
result = Throw(realm, result.PromiseResult);
result = Throw(result.PromiseResult);
}
}
}
Expand All @@ -117,7 +124,7 @@ addEventListener('message', ({ data }) => {
type: 'console',
value: {
method: 'error',
values: [inspect(result, realm)],
values: [inspect(result)],
},
});
}
Expand All @@ -126,7 +133,7 @@ addEventListener('message', ({ data }) => {
postMessage({
type: 'unhandledRejection',
// eslint-disable-next-line no-use-before-define
value: inspect(promise.PromiseResult, realm),
value: inspect(promise.PromiseResult),
});
}
});
Expand Down

1 comment on commit e920718

@vercel
Copy link

@vercel vercel bot commented on e920718 Aug 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.