feat: Function.prototype[Symbol.hasInstance] 绑定与 bound 函数构造语义

@@hasInstance 按 OrdinaryHasInstance 实现(非可调用 this 返回 false、
prototype 非对象抛 TypeError、bound 链递归到最内层 target);
new boundFn() 解包 [[BoundTargetFunction]] 链后转发构造:绑定实参前置、
新对象原型取 target.prototype、new.target 替换为最内层 target。
This commit is contained in:
2026-08-15 22:40:45 +08:00
parent c3d181bd32
commit c052f5a619
7 changed files with 328 additions and 4 deletions
+14
View File
@@ -174,6 +174,8 @@ pub struct FunctionMethods {
pub apply: *const (),
pub bind: *const (),
pub to_string: *const (),
/// `@@hasInstance`(well-known symbol id 6):instanceof 运算符的默认判定。
pub has_instance: *const (),
}
/// 全部内置对象(原型、构造器、全局单例 Math/JSON、well-known symbol 与 stub 对象)的持有者。
@@ -1483,6 +1485,18 @@ impl BuiltinWorld {
("bind", methods.bind, 1),
("toString", methods.to_string, 0),
);
// @@hasInstance 走 well-known symbol 键(id 6):instanceof 运算符经
// dispatch_instanceof 读该属性调用,绑定后属性存在性测试与全局改写生效。
let _ = Self::bind_method_key_static(
proto,
shape_forge,
string_forge,
make_well_known_symbol_key(6),
"[Symbol.hasInstance]",
unsafe { NativeFnPtr::from_raw(methods.has_instance) },
1,
fp,
);
}
/// 在指定原型上安装一个 native 方法,wrapper 函数以本 world 的 Function 原型为原型。