fix: 构造帧 super 状态改显式标志修复多层继承与 return 语义

derived 构造器 super 状态改由 CallFrame.super_called 显式标志承载,
取代依赖 regs[254] 值判定:多层继承中间 derived 帧由 SUPER_CALL 压入
this=构造对象,值判定三重失效(未调 super 不报错 / this-before-super
失效 / 合法 super() 误判 more-than-once)。父构造器正常返回经
construct_result_reg==Some(254) 识别置位调用方帧(该 ABI 不变量仅
SUPER_CALL 压帧满足),抛错走 unwind 不置位。

do_return 检查放宽为非对象返回值(含 undefined/null/原始值)且未调
super 时抛 ReferenceError(规范 §9.2.2.2),调过 super 回退构造 this。

super 构造器改取当前帧 callee 原型而非 newTarget 原型:newTarget 跨
SUPER_CALL 压帧保持为最外层类,取其原型在中间 derived 层解析回同一
父类导致无限压帧。
This commit is contained in:
2026-08-16 01:23:52 +08:00
parent 3df08dddff
commit 8c4b766e70
7 changed files with 163 additions and 8 deletions
+10
View File
@@ -212,6 +212,14 @@ pub struct CallFrame {
pub construct_result_reg: Option<u8>,
pub constructed_this: Option<JsValue>,
pub is_derived_constructor: bool,
/// derived 构造帧是否已成功调用 super()(父构造器正常返回后置位)。
///
/// 置位识别依赖 ABI 不变量:`construct_result_reg == Some(254)` 仅 SUPER_CALL
/// 压帧产生(emit 从寄存器 ≥1 分配,254 保留给 this);父构造器抛错走 unwind
/// 弹帧不进 do_return,不置位。此标志取代依赖 regs[254] 值判定 super 状态的
/// 旧方案——多层继承时中间 derived 帧由 SUPER_CALL 以构造 this 压入,
/// regs[254] 恒非 undefined,值判定三重失效。
pub super_called: bool,
pub continuation: FrameContinuation,
}
@@ -1317,6 +1325,7 @@ impl Vm {
construct_result_reg,
constructed_this,
is_derived_constructor: obj.is_derived_constructor(),
super_called: false,
continuation,
});
@@ -2365,6 +2374,7 @@ mod tests {
construct_result_reg: None,
constructed_this: None,
is_derived_constructor: false,
super_called: false,
continuation: super::FrameContinuation::None,
});
vm.save_stack.push(JsValue::undefined());