Skip to content

Commit

Permalink
runtime/jsc: update to use JavaScriptCore's built-in $/$262
Browse files Browse the repository at this point in the history
  • Loading branch information
rwaldron committed Feb 27, 2018
1 parent b09f64f commit 91604b0
Showing 1 changed file with 8 additions and 27 deletions.
35 changes: 8 additions & 27 deletions runtimes/jsc.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,12 @@
/* JavaScriptCore exposes a "$" object to its runtime */
/* Using this["\x24"]; prevents overwrite by ConsoleAgent */
var jsc = this["\x24"];
var $ = {
global: this,
createRealm(options) {
options = options || {};
options.globals = options.globals || {};

var realm = createGlobalObject();
realm.eval(this.source);
realm.$.source = this.source;
realm.$.destroy = function () {
if (options.destroy) {
options.destroy();
}
};
for(var glob in options.globals) {
realm.$.global[glob] = options.globals[glob];
}

return realm.$;
},
evalScript(code) {
try {
loadString(code);
return { type: 'normal', value: undefined };
} catch (e) {
return { type: 'throw', value: e }
}
},
agent: jsc.agent,
global: jsc.global,
createRealm: jsc.createRealm,
detachArrayBuffer: jsc.detachArrayBuffer,
evalScript: jsc.evalScript,
getGlobal(name) {
return this.global[name];
},
Expand Down

0 comments on commit 91604b0

Please sign in to comment.