From 6d88bb7b97ff4938084c2823257878ef623551ee Mon Sep 17 00:00:00 2001 From: pjh456 <147148383@qq.com> Date: Thu, 24 Sep 2026 03:23:47 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=A7=BB=E9=99=A4=20Promise=20=E6=9E=84?= =?UTF-8?q?=E9=80=A0=E5=87=BA=E5=8F=A3=E5=8E=9F=E5=9E=8B=E9=93=BE=E6=A3=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/oxide_vm/src/promise/constructor.rs | 6 +----- crates/oxide_vm/src/promise/settlement.rs | 24 ---------------------- 2 files changed, 1 insertion(+), 29 deletions(-) diff --git a/crates/oxide_vm/src/promise/constructor.rs b/crates/oxide_vm/src/promise/constructor.rs index 6e95e42f..60c0457b 100644 --- a/crates/oxide_vm/src/promise/constructor.rs +++ b/crates/oxide_vm/src/promise/constructor.rs @@ -344,7 +344,7 @@ impl Vm { /// 2. executor 可读性检查(步序先于 GpFC 原型读)。 /// 3. GetPrototypeFromConstructor:传播式读 new.target 的 "prototype" /// (访问器副作用与异常原值传播);非对象结果回落 %Promise.prototype%。 -/// 4. 物化 receiver(原型重设 + type_tag + 状态盒)后经原型链检放行。 +/// 4. 物化 receiver(原型重设 + type_tag + 状态盒)。 fn promise_constructor(vm: &mut Vm, args: &[u8]) -> NativeResult { let this_val = vm.reg(if args.is_empty() { 0 } else { args[0] }); // NewTarget 缺失 = 非构造形态:构造入口置位、普通调用入口清零,据此拒绝。 @@ -397,10 +397,6 @@ fn promise_constructor(vm: &mut Vm, args: &[u8]) -> NativeResult { promoted_clone: std::ptr::null_mut(), }); 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]) { Ok(_) => NativeResult::Ok(this_val), Err(e) => { diff --git a/crates/oxide_vm/src/promise/settlement.rs b/crates/oxide_vm/src/promise/settlement.rs index 4b7aa1ac..e6e17e72 100644 --- a/crates/oxide_vm/src/promise/settlement.rs +++ b/crates/oxide_vm/src/promise/settlement.rs @@ -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)。 pub(super) fn enqueue(&mut self, job: Microtask) { self.job_queue.push_back(job);