perf: typeof 改 js_type 单次提取并复用进程级静态字符串消除每次分配

This commit is contained in:
2026-08-15 16:09:19 +08:00
parent 31296ed16d
commit 3d1ece321b
8 changed files with 128 additions and 57 deletions
@@ -20,9 +20,14 @@ fn run(module: &CompiledModule) -> JsValue {
}
fn eval_str(source: &str) -> String {
let v = eval(source);
let allocator = Allocator::default();
let program = oxide_parser::parse(&allocator, source).expect("parse failed");
let module = Compiler::new().compile(&program).expect("compile failed");
let mut vm = Vm::new();
let v = vm.run(&module).expect("vm run failed");
// 字符串结果须在同一 VM 上读:perm 串指向 VM 私有内核,VM drop 后指针悬垂。
if v.is_string() {
oxide_runtime_api::to_string(v)
vm.lookup_str(v).unwrap_or_default()
} else {
format!("{v}")
}