feat: Function.prototype 调用返回 undefined 且动态函数 prototype 不可配置

This commit is contained in:
2026-10-16 12:22:01 +00:00
parent 9af3041ff5
commit 97779b901a
8 changed files with 133 additions and 37 deletions
+6
View File
@@ -191,6 +191,12 @@ impl Vm {
};
}
// 无本体函数对象(Function.prototype):[[Call]] 接受任意实参返回
// undefined,不执行函数体。此处 callee 已确认为非 native 的函数对象,
// sub_module_index == 0 即无本体(accessor 非函数,已在上方拦截)。
if callee_obj.sub_module_index() == 0 {
return Ok(JsValue::undefined());
}
// 字节码函数在自身(同一 epoch)内联执行,防止 use-after-free。
// 独立子 VM 拥有不同 epoch:返回含子 VM epoch 指针的 JsValue 后再销毁子 VM,
// 会在 release 构建中产生悬垂指针 / 访问违规。
+3 -1
View File
@@ -98,7 +98,9 @@ impl Vm {
table.immutables.resize(table.modules.len(), OnceLock::new());
table.si_tables.resize(table.modules.len(), OnceLock::new());
let func_val = self.create_function_object(base, self.current_gen, FunctionFlags::none());
// 动态函数对象置 DYNAMIC 旗:`prototype` 属性按规范不可配置
// (区别于普通函数的可配置面)。
let func_val = self.create_function_object(base, self.current_gen, FunctionFlags(FunctionFlags::DYNAMIC));
let func_obj = unsafe { &mut *func_val.as_js_object_ptr() };
let length_si = self.kernel_core.perm_interner().intern("length").0;
let name_si = self.kernel_core.perm_interner().intern("name").0;