Updated API to new specs
MODIFY
shim/examples/simple.html
shim/examples/simple.html
// Root realm
const r1 = new Realm();
- console.log(1.1, r1.eval('( JSON )'));
- console.log(1.2, r1.eval('( JSON )') !== JSON);
- console.log(1.3, r1.eval('( JSON )') === r1.eval('( JSON )'));
- console.log(1.4, r1.eval('( JSON )') === r1.eval('( eval("JSON") )'));
- console.log(1.5, r1.eval('( eval instanceof Function )'));
+ console.log(1.1, r1.evaluate('( JSON )'));
+ console.log(1.2, r1.evaluate('( JSON )') !== JSON);
+ console.log(1.3, r1.evaluate('( JSON )') === r1.evaluate('( JSON )'));
+ console.log(1.4, r1.evaluate('( JSON )') === r1.evaluate('( eval("JSON") )'));
+ console.log(1.5, r1.evaluate('( eval instanceof Function )'));
// Root realm vs root realm
const r2 = new Realm();
- console.log(2.1, r2.eval('( JSON )'));
- console.log(2.2, r2.eval('( JSON )') !== JSON);
- console.log(2.3, r2.eval('( JSON )') === r2.eval('( JSON )'));
- console.log(2.4, r2.eval('( JSON )') === r2.eval('( eval("JSON") )'));
- console.log(2.5, r2.eval('( eval instanceof Function )'));
+ console.log(2.1, r2.evaluate('( JSON )'));
+ console.log(2.2, r2.evaluate('( JSON )') !== JSON);
+ console.log(2.3, r2.evaluate('( JSON )') === r2.evaluate('( JSON )'));
+ console.log(2.4, r2.evaluate('( JSON )') === r2.evaluate('( eval("JSON") )'));
+ console.log(2.5, r2.evaluate('( eval instanceof Function )'));
- console.log(2.6, r2.eval('( JSON )') !== r1.eval('( JSON )'));
- console.log(2.7, r2.eval('( eval("JSON") )') !== r1.eval('( eval("JSON") )'));
+ console.log(2.6, r2.evaluate('( JSON )') !== r1.evaluate('( JSON )'));
+ console.log(2.7, r2.evaluate('( eval("JSON") )') !== r1.evaluate('( eval("JSON") )'));
// Compartment realm vs root realm
const r3 = new r1.global.Realm({ intrinsics: 'inherit' });
- console.log(3.1, r3.eval('( JSON )'));
- console.log(3.2, r3.eval('( JSON )') !== JSON);
- console.log(3.3, r3.eval('( JSON )') === r3.eval('( JSON )'));
- console.log(3.4, r3.eval('( JSON )') === r3.eval('( eval("JSON") )'));
- console.log(3.5, r1.eval('( eval instanceof Function )'));
+ console.log(3.1, r3.evaluate('( JSON )'));
+ console.log(3.2, r3.evaluate('( JSON )') !== JSON);
+ console.log(3.3, r3.evaluate('( JSON )') === r3.evaluate('( JSON )'));
+ console.log(3.4, r3.evaluate('( JSON )') === r3.evaluate('( eval("JSON") )'));
+ console.log(3.5, r1.evaluate('( eval instanceof Function )'));
- console.log(3.6, r3.eval('( JSON )') === r1.eval('( JSON )'));
- console.log(3.7, r3.eval('( eval("JSON") )') === r1.eval('( eval("JSON") )'));
+ console.log(3.6, r3.evaluate('( JSON )') === r1.evaluate('( JSON )'));
+ console.log(3.7, r3.evaluate('( eval("JSON") )') === r1.evaluate('( eval("JSON") )'));
const r = new Realm();
document.getElementById('run').addEventListener('click', function () {
const sourceText = document.getElementById('sourceText').value;
let result, output;
try {
- result = r.eval(sourceText);
+ result = r.evaluate(sourceText);
} catch (e) {
result = 'Error: ' + e;
}

MODIFY
shim/src/realm.js
shim/src/realm.js
@@ -56,9 +56,9 @@ Object.defineProperties(Realm.prototype, {
return descs.global.get.call(this);
}
},
- eval: {
+ evaluate: {
value(x) {
- return descs.eval.value.call(this, x);
+ return descs.evaluate.value.call(this, x);
}
}
});
@@ -167,7 +167,7 @@ defineProperties(Realm.prototype, {
return O[RealmRecord][GlobalObject];
}
},
- eval: {
+ evaluate: {
value(x) {
const O = this;
if (typeof O !== 'object') throw new TypeError();

Updated API to new specs