fix: class 类名绑定经 dedicated cell 捕获(C===Cv 恒等)+ upvalue 写入 const guard(getter 赋值抛 TypeError)

This commit is contained in:
2026-08-12 17:30:28 +08:00
parent 0a4e42334d
commit 0c22a0e968
10 changed files with 60 additions and 31 deletions
@@ -1,9 +1,6 @@
//! 类声明语句 emit:`emit_class_declaration_statement` 声明类名并初始化类对象。
use crate::{CompileCtx, Emitter};
use oxide_bytecode::opcode::OpCode;
use oxide_ir::inst::Inst;
use oxide_ir::operand::Operand;
use oxide_parser::{Statement, VariableDeclarationKind};
impl Emitter {
@@ -28,17 +25,7 @@ impl Emitter {
};
// 类名绑定在 emit_class_with_binding 内于 extends 求值后初始化:
// 先声明未初始化绑定(TDZ),extends 引用类名按规范抛 ReferenceError。
let ctor_reg = self.emit_class_with_binding(class, ctx, Some(var_reg))?;
if let Some(&cell_idx) = ctx.captured_bindings.get(&name) {
ctx.inst(Inst::new(
OpCode::MAKE_CELL,
Operand::Reg(var_reg),
Operand::Imm(cell_idx as u16),
Operand::None,
));
} else {
ctx.inst(Inst::new(OpCode::STORE_VAR, Operand::Reg(var_reg), Operand::Reg(ctor_reg), Operand::None));
}
self.emit_class_with_binding(class, ctx, Some(var_reg))?;
Ok(None)
}
}