Parent: #22
Depends on: none
Feeds: #15 Runtime, #20 Security, #16 Stealth
目标
把 Bao 当前“persistent Realm + Page/Node Realm 逻辑概念”升级为显式利用 SpiderMonkey Realm / Compartment / Zone 拓扑的 Runtime 模型,并证明 page/host/worker 生命周期、GC 和权限隔离与该拓扑一致。
不是为了多造一层抽象,而是裁决:哪些 Bao 隔离边界应直接绑定 SM 原生 Realm/Compartment/Zone,哪些必须继续由 Servo/Bao 自己管理。
当前基线
bao_engine::context::JsContext 已持久持有一个 realm global,并用 extra roots 保活。
- 进程级 JSEngine + 每 ScriptThread thread-local JSContext 已成为铁律。
- Page Realm / Node Realm 已有产品语义,但当前 topology 没有形成 machine-readable mapping。
- multi-page / worker / navigation / Node host realm 的 Zone/Compartment ownership 尚未系统审计。
必须先做的审计
- 锁定当前 vendored mozjs 的 RealmOptions/Compartment/Zone API。
- 扫描 Servo 当前如何为 Window/Worker 建 Realm/Compartment/Zone,禁止与 Servo 重复建 ownership。
- 扫描 Bao
JsContext、Node realm、vm sandbox、Page/Worker bridge 的所有 global/realm 创建点。
- 在
.plans/spidermonkey-evolution.md 形成拓扑表:
- owner thread
- JSContext
- Zone
- Compartment
- Realm/global
- Bao PageId/WorkerId/Host identity
- lifecycle owner
- capability set
设计要求
Page/Web
- 页面代码继续由 Servo 创建/拥有正确 Web Realm。
- Bao 不为了“统一”绕过 Servo 新建重复 Window Realm。
- navigation 后旧 Realm/global/object handle 的失效与回收必须明确。
Node Host
- Node/Bun host realm 与 Web Realm 的隔离边界必须显式。
- Host capability 不得因共享 JSContext 自动泄露到 Page Realm。
- DOM proxy/bridge 必须在正确 Realm 中访问,禁止跨 Realm 裸对象借用。
Workers
- DedicatedWorker/Worklet/其他目标 worker 的 Realm/Zone ownership 进入同一拓扑账本。
- worker shutdown 后根、job、callback、bridge 不残留。
Zone strategy
必须以实测/源码事实裁决以下方案,不预设答案:
- 每 page 独立 Zone;
- 多 page 共 Zone、独立 Compartment/Realm;
- Servo upstream 默认 Zone 规则原样保留;
- Host realm 独立 Zone。
选择必须比较:GC isolation、memory reclamation、cross-realm wrapper cost、Servo compatibility、page churn RSS。
测试
- repeated navigation stale-object negative tests
- page A/B global/object/capability isolation
- host↔page cross-realm access positive/negative tests
- worker create/post/shutdown/recreate
- GC between page close/navigation
- 10/100 page topology stress
- multi-runtime/multi-thread isolation
Definition of Done
禁止
- 不因 SM 有 Zone API 就强行覆盖 Servo 的 ownership。
- 不把 Compartment/Realm 当安全沙箱宣传。
- 不允许 JSObject/GC cell 跨线程进入全局表。
Parent: #22
Depends on: none
Feeds: #15 Runtime, #20 Security, #16 Stealth
目标
把 Bao 当前“persistent Realm + Page/Node Realm 逻辑概念”升级为显式利用 SpiderMonkey Realm / Compartment / Zone 拓扑的 Runtime 模型,并证明 page/host/worker 生命周期、GC 和权限隔离与该拓扑一致。
不是为了多造一层抽象,而是裁决:哪些 Bao 隔离边界应直接绑定 SM 原生 Realm/Compartment/Zone,哪些必须继续由 Servo/Bao 自己管理。
当前基线
bao_engine::context::JsContext已持久持有一个 realm global,并用 extra roots 保活。必须先做的审计
JsContext、Node realm、vm sandbox、Page/Worker bridge 的所有 global/realm 创建点。.plans/spidermonkey-evolution.md形成拓扑表:设计要求
Page/Web
Node Host
Workers
Zone strategy
必须以实测/源码事实裁决以下方案,不预设答案:
选择必须比较:GC isolation、memory reclamation、cross-realm wrapper cost、Servo compatibility、page churn RSS。
测试
Definition of Done
.plans/spidermonkey-evolution.md有当前 topology + 目标 topology + 裁决证据。禁止