mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-27 12:11:12 +08:00
fix: 移除 Promise 构造出口原型链检
This commit is contained in:
@@ -344,7 +344,7 @@ impl Vm {
|
|||||||
/// 2. executor 可读性检查(步序先于 GpFC 原型读)。
|
/// 2. executor 可读性检查(步序先于 GpFC 原型读)。
|
||||||
/// 3. GetPrototypeFromConstructor:传播式读 new.target 的 "prototype"
|
/// 3. GetPrototypeFromConstructor:传播式读 new.target 的 "prototype"
|
||||||
/// (访问器副作用与异常原值传播);非对象结果回落 %Promise.prototype%。
|
/// (访问器副作用与异常原值传播);非对象结果回落 %Promise.prototype%。
|
||||||
/// 4. 物化 receiver(原型重设 + type_tag + 状态盒)后经原型链检放行。
|
/// 4. 物化 receiver(原型重设 + type_tag + 状态盒)。
|
||||||
fn promise_constructor(vm: &mut Vm, args: &[u8]) -> NativeResult {
|
fn promise_constructor(vm: &mut Vm, args: &[u8]) -> NativeResult {
|
||||||
let this_val = vm.reg(if args.is_empty() { 0 } else { args[0] });
|
let this_val = vm.reg(if args.is_empty() { 0 } else { args[0] });
|
||||||
// NewTarget 缺失 = 非构造形态:构造入口置位、普通调用入口清零,据此拒绝。
|
// NewTarget 缺失 = 非构造形态:构造入口置位、普通调用入口清零,据此拒绝。
|
||||||
@@ -397,10 +397,6 @@ fn promise_constructor(vm: &mut Vm, args: &[u8]) -> NativeResult {
|
|||||||
promoted_clone: std::ptr::null_mut(),
|
promoted_clone: std::ptr::null_mut(),
|
||||||
});
|
});
|
||||||
obj.set_native_data(Box::into_raw(state) as *mut u8);
|
obj.set_native_data(Box::into_raw(state) as *mut u8);
|
||||||
// 物化后的 receiver 原型链须含 %Promise.prototype%(构造面放行兜底)。
|
|
||||||
if !vm.has_promise_proto(this_val) {
|
|
||||||
return NativeResult::Err(oxide_builtins::error::create_type_error(vm, "Promise must be called with new"));
|
|
||||||
}
|
|
||||||
match vm.call_function_sync(executor, JsValue::undefined(), &[resolve, reject]) {
|
match vm.call_function_sync(executor, JsValue::undefined(), &[resolve, reject]) {
|
||||||
Ok(_) => NativeResult::Ok(this_val),
|
Ok(_) => NativeResult::Ok(this_val),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|||||||
@@ -152,30 +152,6 @@ impl Vm {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 校验值的原型链含 `%Promise.prototype%`(`new Promise` 构造出的实例特征)。
|
|
||||||
pub(super) fn has_promise_proto(&self, v: JsValue) -> bool {
|
|
||||||
if !v.is_object() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
let target = self.promise_proto.as_ptr() as *mut JsObject;
|
|
||||||
let mut cursor = v;
|
|
||||||
for _ in 0..crate::vm::MAX_PROTO_CHAIN_DEPTH {
|
|
||||||
if !cursor.is_object() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
let ptr = cursor.as_js_object_ptr();
|
|
||||||
if ptr.is_null() {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if std::ptr::eq(ptr, target) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
// SAFETY: 循环内 `is_object` 与 `ptr` 非空守卫保证可解引用;只读 proto(),链深受深度上限约束。
|
|
||||||
cursor = unsafe { &*ptr }.proto();
|
|
||||||
}
|
|
||||||
false
|
|
||||||
}
|
|
||||||
|
|
||||||
/// 入队一条微任务(追加到队尾,保证 FIFO)。
|
/// 入队一条微任务(追加到队尾,保证 FIFO)。
|
||||||
pub(super) fn enqueue(&mut self, job: Microtask) {
|
pub(super) fn enqueue(&mut self, job: Microtask) {
|
||||||
self.job_queue.push_back(job);
|
self.job_queue.push_back(job);
|
||||||
|
|||||||
Reference in New Issue
Block a user