現在提案中のtc39/proposal-realmsについて ToKyoto.js#1
Ecmascript Proposal-Realms
View Slide
せ: @brn (ꫬꅿ⨳ⵃa.k.a ـٕ٦ظ) 耵噟: ؿٗٝزؒٝسؒٝآص،٥iOSؒٝآص، ⠓爡: Cyberagent ،سذؙأةآؔRightSegment٥AI Messenger ـؚٗ: http://abcdef.gets.b6n.ch/ Twitter: https://twitter.com/brn227 GitHub: https://github.com/brn
What is Relms?Realmsהכءٝفٕח鎉ֲהծ DOM搀׃Iframe٥Node.JSךVMٌآُ٦ٕ ְזך
What can we do?Realms⢪ֲֿהדⴽךglobalؔـآؙؑز橆㞮ד ؝٦س晙evalֿׅהָדֹկ
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!
Hook some callsתRealmsך؝ٝأزؙٓة٦חؔـآؙؑز床ֿׅהדぐ珏Hook㹋鄲ֿׅהָדֹկ
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"!
Your own RealmsRealmsכؙٓأזךד竰䪫׃ג荈ⴓ杝荈ך橆㞮欰䧭ֿׅהָדֹկ
class FakeWindow extends Realm {!init() {!super.init();!// グローバルを初期化let global = this.global;!!// 各種グローバルオブジェクトを書き換えglobal.document = new FakeDocument(...);!global.alert = new Proxy(fakeAlert, { ... });!...!}!}!
Limitation植㖈ךהֿevalScriptח湫䱸؝٦س床ׁזְה꼽湡կ 㢩鿇أؙٔفزRealmsז橆㞮ד㹋遤׃ְկ https://github.com/tc39/proposal-realms/issues/71 Realms.prototype.importScript 䲿周׃גֶֹת׃կ
Status תStage-1זךד孡ꞿח䖉ְ
Summary➬✲ָ䎢デ噟歲זךד穠圓ⴖ㹋חק׃ְկ document.writeהַ剅ֹ䳔ְִׄׯ։