mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-25 11:11:11 +08:00
fix: DataView 原型访问器与 ToNumber 强转序位收口
This commit is contained in:
@@ -74,9 +74,28 @@ impl Vm {
|
||||
let nt_obj = unsafe { &*new_target.as_js_object_ptr() };
|
||||
// native 构造器:receiver 为新对象(this 取 newTarget.prototype),值传递调用。
|
||||
if ctor_obj.native_fn().is_some() {
|
||||
let this_ptr = self.alloc_ctor_this(nt_obj)?;
|
||||
let this_val = JsValue::from_js_object(this_ptr);
|
||||
return match self.call_function_sync(ctor, this_val, args) {
|
||||
// DataView 构造器不预分配 this:其体内先做全部校验、后读 newTarget.prototype
|
||||
// (抛错的 prototype getter 不得先于越界 RangeError 触发),占位 receiver
|
||||
// 不可观测(构造器恒返回自建对象);原型取 %DataView.prototype% 使构造器
|
||||
// 的 receiver 原型链判定通过。
|
||||
let is_data_view = std::ptr::eq(
|
||||
ctor.as_js_object_ptr(),
|
||||
self.session.builtin_world().data_view_constructor.as_ptr() as *mut JsObject,
|
||||
);
|
||||
let this_val = if is_data_view {
|
||||
let data_view_proto_val =
|
||||
JsValue::from_js_object(self.session.builtin_world().data_view_proto.as_ptr() as *mut JsObject);
|
||||
JsValue::from_js_object(self.alloc_object(JsObject::new_empty(EMPTY_SHAPE_ID, data_view_proto_val)))
|
||||
} else {
|
||||
let this_ptr = self.alloc_ctor_this(nt_obj)?;
|
||||
JsValue::from_js_object(this_ptr)
|
||||
};
|
||||
// newTarget 经 reg(255) 暴露给 native 构造器(快照/恢复:call 窗口不触及 255)。
|
||||
let saved_nt = self.regs[255];
|
||||
self.regs[255] = new_target;
|
||||
let result = self.call_function_sync(ctor, this_val, args);
|
||||
self.regs[255] = saved_nt;
|
||||
return match result {
|
||||
Ok(ret) if ret.is_object() => Ok(ret),
|
||||
Ok(_) => Ok(this_val),
|
||||
Err(e) => Err(self
|
||||
|
||||
@@ -121,7 +121,8 @@ enum AggregateKind {
|
||||
}
|
||||
|
||||
/// IsConstructor 近似判定:可调用、非 arrow,且 native 函数须带构造器 tag
|
||||
/// (与 `construct_ctor` 的校验一致)。
|
||||
/// (与 `construct_ctor` 的校验一致);bound 包装恒接受(target 可构造性在
|
||||
/// `dispatch_new_bound` 入口复核)。
|
||||
fn is_constructor_value(c: JsValue) -> bool {
|
||||
if !c.is_object() {
|
||||
return false;
|
||||
@@ -130,7 +131,9 @@ fn is_constructor_value(c: JsValue) -> bool {
|
||||
let c_obj = unsafe { &*c.as_js_object_ptr() };
|
||||
c_obj.is_function()
|
||||
&& !c_obj.is_arrow()
|
||||
&& !(c_obj.native_fn().is_some() && c_obj.type_tag != JsObject::OBJ_TYPE_CONSTRUCTOR)
|
||||
&& !(c_obj.native_fn().is_some()
|
||||
&& c_obj.type_tag != JsObject::OBJ_TYPE_CONSTRUCTOR
|
||||
&& c_obj.type_tag != JsObject::OBJ_TYPE_BOUND)
|
||||
}
|
||||
|
||||
// ── session GC 支撑:状态盒中的 JsValues 作为 Promise 对象边追踪 ──
|
||||
|
||||
Reference in New Issue
Block a user