Slide 1

Slide 1 text

Ecmascript Proposal-Realms

Slide 2

Slide 2 text

せ⵸: @brn (ꫬꅿ⨳ⵃa.k.a ـٕ٦ظ) 耵噟: ؿٗٝزؒٝسؒٝآص،٥iOSؒٝآص، ⠓爡: Cyberagent ،سذؙأةآؔRightSegment٥AI Messenger ـؚٗ: http://abcdef.gets.b6n.ch/ Twitter: https://twitter.com/brn227 GitHub: https://github.com/brn

Slide 3

Slide 3 text

What is Relms? Realmsהכءٝفٕח鎉ֲהծ DOM搀׃Iframe٥Node.JSךVMٌآُ٦ٕ ׫׋ְז׮ך

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

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!

Slide 6

Slide 6 text

Hook some calls ת׋Realmsך؝ٝأزؙٓة٦חؔـآؙؑز׾床ֿׅהדぐ珏 Hook׾㹋鄲ׅ׷ֿהָדֹ׷կ

Slide 7

Slide 7 text

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"!

Slide 8

Slide 8 text

Your own Realms Realmsכؙٓأזךד竰䪫׃ג荈ⴓ杝荈ך橆㞮׾欰䧭ׅ׷ֿהָד ֹ׷կ

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

Limitation 植㖈ךהֿ׹evalScriptח湫䱸؝٦س׾床ׁזְה꼽湡կ 㢩鿇أؙٔفز׾Realmsז橆㞮ד㹋遤׃׋ְկ https://github.com/tc39/proposal-realms/issues/71 Realms.prototype.importScript ׾䲿周׃גֶֹת׃׋կ

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

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