SpiderMonkey engine wrapper. Core types are provided by bun_sm;
this crate retains only the modules that have complex inter-dependencies
(context, job_queue).
Re-export Architecture
Layer order (bottom → top):
bun_sm — 底层:SpiderMonkey 值类型 + JSC API 兼容层 + module_loader
JSValue, JSGlobalObject, VirtualMachine, CallFrame, JSType, ModuleLoader
bao_engine — Re-export 层:从 bun_sm re-export 公共类型,保留自有模块
context, job_queue (复杂内部依赖)
bao_runtime — 消费层:pub use bao_engine::* (最终替换 bun_jsc::*)
bao_browser — 消费层:依赖 bao_engine 的 context + dispatch_sm
迁移步骤 (bun_jsc → bun_sm)
- Phase 1 (已完成): bao_engine 依赖 bun_sm,re-export 核心类型
- Phase 2 (进行中): bao_runtime 将
pub use bun_jsc::*改为pub use bun_sm::* - Phase 3 (计划中): 移除 bun_jsc 依赖,所有 8,500+ JSC 引用指向 bun_sm
约定
-
下游 crate 必须通过
bao_engine::Type访问类型,禁止直接use bun_sm::Type- 唯一例外:crate 确实需要 bun_sm 中未被 bao_engine re-export 的类型
- 目的:维护单一依赖表面,避免下游 crate 同时依赖 bao_engine 和 bun_sm
-
新代码直接使用
bun_sm::JSValue等类型 -
bao_engine 仅 re-export,不定义值类型
-
保留在 bao_engine 的模块(context/job_queue)因内部依赖复杂不迁移
-
module_loader 已迁移到 bun_sm,通过回调模式(JobQueueDrainFn)避免循环依赖
迁移模块到 bun_sm 的步骤
- 复制
.rs文件到bun_sm/src/ - 更新
use crate::引用为 bun_sm 自身路径 - 从
bao_engine/src/删除原文件 - 在下方 Re-exports 区域添加
pub use bun_sm::xxx; - 验证:
cargo check -p bao_engine通过