Arrays, symbols, and Realms

Tags
javascript
Created
Jan 30, 2018 2:43 AM

https://jakearchibald.com/2017/arrays-symbols-realms/

isArray polypill:

Object.prototype.toString.call(arg) === '[object Array]’;

isArray 能跨 realms

Array 在不同 realms 不同

已知 symbol 在不同 realms 相同

// realm 类似 nodejs 的 vm

https://github.com/Agoric/realms-shim 使用:

  • Function // 提供非严格模式环境执行 with
  • with(proxy) // 将全局名称查找转换为属性查找,默认包含 iframe 的 js 全局对象
  • eval // iframe 中的所以没有主域 csp 限制,间接调用

实现相关细节:

https://agoric.com/realms-shim-security-updates/

```

new iframe.contentWindow.Function('code', 'sandbox', 'with(sandbox){eval(code)}')

```

https://github.com/tc39/proposal-shadowrealm/blob/main/explainer.md

  • 支持 ESM
  • The ShadowRealm#importValue() method, equivalent to the import() expression, but capturing a primitive or callable values.
  • The get ShadowRealm#evaluate method promotes an indirect eval in the shadowRealm but only allows the return of primitive or callable values.

问题:

  • 如何向 ShadowRealm 导入全局变量?// Node.js vm.createContext 能指定上下文对象
    • 前端微服务渲染代理对象到基座 App
    • 传递大对象时需要共享内存
  • 想要和 WebAssembly 一样的 memory 管理 // js 环境动态内存分配啥的应该实现不了
SuperMade with Super