Ecmascript proposal-realms

Ecmascript proposal-realms

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

Transcript

  1. Ecmascript Proposal-Realms

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

    ـؚٗ: http://abcdef.gets.b6n.ch/ Twitter: https://twitter.com/brn227 GitHub: https://github.com/brn
  3. What is Relms? Realmsהכءٝفٕח鎉ֲהծ DOM搀׃Iframe٥Node.JSךVMٌآُ٦ٕ ׫׋ְז׮ך

  4. What can we do? Realms׾⢪ֲֿהדⴽךglobalؔـآؙؑز橆㞮ד ؝٦س晙׾evalׅ׷ֿהָדֹ׷կ

  5. 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!
  6. Hook some calls ת׋Realmsך؝ٝأزؙٓة٦חؔـآؙؑز׾床ֿׅהדぐ珏 Hook׾㹋鄲ׅ׷ֿהָדֹ׷կ

  7. 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"!
  8. Your own Realms Realmsכؙٓأזךד竰䪫׃ג荈ⴓ杝荈ך橆㞮׾欰䧭ׅ׷ֿהָד ֹ׷կ

  9. class FakeWindow extends Realm {! init() {! super.init();! // グローバルを初期化

    let global = this.global;! ! // 各種グローバルオブジェクトを書き換え global.document = new FakeDocument(...);! global.alert = new Proxy(fakeAlert, { ... });! ...! }! }!
  10. Limitation 植㖈ךהֿ׹evalScriptח湫䱸؝٦س׾床ׁזְה꼽湡կ 㢩鿇أؙٔفز׾Realmsז橆㞮ד㹋遤׃׋ְկ https://github.com/tc39/proposal-realms/issues/71 Realms.prototype.importScript ׾䲿周׃גֶֹת׃׋կ

  11. Status ת׌Stage-1זךד孡ꞿח䖉׍׋ְ

  12. Summary ➬✲ָ䎢デ噟歲זךד穠圓ⴖ㹋חק׃ְկ document.writeהַ׾剅ֹ䳔ִ׋ְ׿ׄׯ։