Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Ecmascript proposal-realms

Ecmascript proposal-realms

現在提案中のtc39/proposal-realmsについて
ToKyoto.js#1

More Decks by Taketoshi Aono(青野健利 a.k.a brn)

Other Decks in Programming

Transcript

  1. せ⵸: @brn (ꫬꅿ⨳ⵃa.k.a ـٕ٦ظ) 耵噟: ؿٗٝزؒٝسؒٝآص،٥iOSؒٝآص، ⠓爡: Cyberagent ،سذؙأةآؔRightSegment٥AI Messenger

    ـؚٗ: http://abcdef.gets.b6n.ch/ Twitter: https://twitter.com/brn227 GitHub: https://github.com/brn
  2. let realm = new Realm();! ! let outerGlobal = window;!

    let innerGlobal = realm.global;! ! let f = realm.evalScript("(function() { return 17 })");! ! f() === 17 // true! ! Reflect.getPrototypeOf(f) === outerGlobal.Function.prototype // false! ! Reflect.getPrototypeOf(f) === innerGlobal.Function.prototype // true!
  3. const r = new Realm({! evalHook(sourceText) {! return compile(sourceText);! },!

    importHook(referrerNamespace, specifier) {! ...! }! });! const result = r.eval('eval("1")');! // compile('1')を呼び出して、戻り値を評価する const ns = r.eval('import("foo")');! // referrerNamespaceがnullでspecifierが"foo"!
  4. class FakeWindow extends Realm {! init() {! super.init();! // グローバルを初期化

    let global = this.global;! ! // 各種グローバルオブジェクトを書き換え global.document = new FakeDocument(...);! global.alert = new Proxy(fakeAlert, { ... });! ...! }! }!