feat: ShadowRealm evaluate 与 importValue 真实现落地

This commit is contained in:
2026-10-19 04:47:57 +00:00
parent d765346e37
commit ed10209764
15 changed files with 629 additions and 72 deletions
@@ -3,6 +3,14 @@
use oxide_bytecode::module::CompiledModule;
/// 模块源码加载器:按 `base_dir` 与 `specifier` 定位依赖模块源码。
///
/// 供 `compile_module` 解析 ES module 依赖。返回 (源码, 规范路径)。
pub trait ModuleSourceLoader {
/// 解析依赖模块:返回 (源码, 规范路径)。
fn resolve(&mut self, base_dir: &str, specifier: &str) -> Result<(String, String), String>;
}
/// 动态编译服务:`Vm` 经它把源码编译为 `CompiledModule`。
///
/// 无状态实现 `Send + Sync`,`Arc<dyn CompilerService>` 可跨线程共享
@@ -19,4 +27,12 @@ pub trait CompilerService: Send + Sync {
///
/// 顶层 var/function 声明落全局属性 configurable:true。
fn compile_eval_script(&self, source: &str) -> Result<CompiledModule, String>;
/// 编译 ES module(含依赖加载),返回完整模块树。
///
/// `module_path` 为模块文件的规范路径(依赖解析基准 = 其父目录),
/// 依赖经 `loader` 解析。
fn compile_module(
&self, source: &str, module_path: &str, loader: &mut dyn ModuleSourceLoader,
) -> Result<CompiledModule, String>;
}
+1 -1
View File
@@ -30,7 +30,7 @@ pub use coercion::{
to_string_for_string_constructor, to_string_full, to_string_value_full, to_uint32, to_units_full,
well_known_symbol_name, write_number_into, ToPrimitiveHint,
};
pub use compiler_service::CompilerService;
pub use compiler_service::{CompilerService, ModuleSourceLoader};
pub use event_target::{EventTargetState, ListenerEntry};
pub use host::{ModuleEvalState, ProtoKind, ShapeNode, VmHost};
pub use native_result::NativeResult;