mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-26 11:41:13 +08:00
perf: run 签名改 &Arc<CompiledModule>,顶层模块跨 run 共享——collect_flat_modules 顶层改 Arc::clone 消除逐 run 常量池深拷贝,全调用点 Arc 包装迁移
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
//! sweep 变体与闭包捕获变体见 `vm_support.rs` 内部测试(需 crate 内 `resume_generator`
|
||||
//! 在模块表未重建时恢复执行,integration 层无法触达)。
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use oxide_compiler::compiler::Compiler;
|
||||
use oxide_parser::Allocator;
|
||||
use oxide_vm::vm::Vm;
|
||||
@@ -18,9 +20,9 @@ fn compile(source: &str) -> oxide_bytecode::module::CompiledModule {
|
||||
#[test]
|
||||
fn generator_promoted_to_global_survives_full_reset_cleanly() {
|
||||
let mut vm = Vm::new();
|
||||
vm.run(&compile(
|
||||
vm.run(&Arc::new(compile(
|
||||
"function* g(){ yield 1; yield 2; } globalThis.it = g(); globalThis.it.next(); 0",
|
||||
))
|
||||
)))
|
||||
.expect("run1");
|
||||
assert!(vm.session_object_count() > 0, "生成器挂 global 应被 promote 进 session");
|
||||
|
||||
@@ -29,12 +31,12 @@ fn generator_promoted_to_global_survives_full_reset_cleanly() {
|
||||
vm.full_reset();
|
||||
assert_eq!(vm.session_object_count(), 0, "full_reset 应清空 session 对象");
|
||||
|
||||
let result = vm.run(&compile("typeof it")).expect("run2");
|
||||
let result = vm.run(&Arc::new(compile("typeof it"))).expect("run2");
|
||||
let text = vm.lookup_str(result).expect("typeof 应返回字符串").to_string();
|
||||
assert_eq!(text, "undefined");
|
||||
// 新会话可正常创建并推进生成器。
|
||||
let ok = vm
|
||||
.run(&compile("function* h(){ yield 9; } var it2 = h(); it2.next().value"))
|
||||
.run(&Arc::new(compile("function* h(){ yield 9; } var it2 = h(); it2.next().value")))
|
||||
.expect("run3");
|
||||
assert_eq!(format!("{ok}"), "9");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user