History
January 25, 2017 ยท View on GitHub
- worked on this during ES2015 time frame, so never went through stages process
- got punted to later (rightly so!)
- goal for today: resume work on this, reassert committee interest via advancing to stage 1
Intuitions
- sandbox
- iframe without DOM
- principled version of Node's
'vm'module - sync Worker
Use cases
- security isolation (with synchronous but coarse-grained communication channel)
- plugins (e.g., spreadsheet functions)
- in-browser code editors
- server-side rendering
- testing/mocking (e.g., jsdom)
- in-browser transpilation
Example: simple realm
let realm = new Realm();
let outerGlobal = window;
let innerGlobal = realm.global;
let f = realm.evalScript("(function() { return 17 })");
f() === 17 // true
Reflect.getPrototypeOf(f) === outerFlobal.Function.prototype // false
Reflect.getPrototypeOf(f) === innerGlobal.Function.prototype // true
Example: simple subclass
class EmptyRealm extends Realm {
constructor(...args) { super(...args); }
init() { /* do nothing */ }
}
Example: DOM mocking
class FakeWindow extends Realm {
init() {
super.init(); // install the standard primordials
let global = this.global;
global.document = new FakeDocument(...);
global.alert = new Proxy(fakeAlert, { ... });
...
}
}
Example: language hooks
class ESNextRealm extends Realm {
[Realm.directEval](source) { return compile(source); }
[Realm.indirectEval](source) { ... }
...
}
Further considerations
realm.evalModule()- module registry
- hooks for manipulating module requests