mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-24 18:51:13 +08:00
fix: 未声明标识符读写混合解析——读侧登记的全局槽写不穿透全局对象
未声明名由首次引用侧登记全局槽:读侧(LOAD_GLOBAL 槽)登记后, 后的写点只查写侧集合,补全局对象属性写被跳过——条件读走全局 属性、写落脚本内寄存器,脱节成死循环;更新式/复合式/逻辑赋值的 旧值又取自入口快照槽(读从不刷新槽),先读后写算出陈旧值。 写点隐式全局判定改读写登记集合取并(7 处),RMW 旧值读前经 LOAD_GLOBAL_TYPEOF 从全局对象取当前值(缺失按 undefined,sloppy 未解析引用 GetBaseValue 语义),读侧登记集合随继承绑定传入子 函数 ctx。
This commit is contained in:
@@ -95,11 +95,23 @@ impl Emitter {
|
||||
ctx.inst(Inst::new(op, Operand::Reg(val_reg), Operand::Reg(rhs), Operand::None));
|
||||
return Ok(val_reg);
|
||||
}
|
||||
let is_implicit = ctx.implicit_global_writes.contains(&var_reg);
|
||||
let is_implicit = ctx.is_implicit_global_reg(var_reg);
|
||||
if is_implicit && ctx.is_strict {
|
||||
// 严格模式未声明复合写:未解析引用不可 put,值无关抛 ReferenceError。
|
||||
return self.emit_strict_undeclared_write(name, ctx);
|
||||
}
|
||||
// 未声明名槽是入口快照(读侧登记的槽从不被读刷新,同脚本后续写
|
||||
// 可使其脱节):RMW 前从全局对象属性取旧值,属性缺失按 undefined
|
||||
// (sloppy 未解析引用 GetBaseValue 语义,不抛)。
|
||||
if is_implicit {
|
||||
let key_idx = ctx.add_constant(Constant::String(name.to_string()));
|
||||
ctx.inst(Inst::new(
|
||||
OpCode::LOAD_GLOBAL_TYPEOF,
|
||||
Operand::Reg(var_reg),
|
||||
Operand::Const(key_idx),
|
||||
Operand::None,
|
||||
));
|
||||
}
|
||||
ctx.inst(Inst::new(op, Operand::Reg(var_reg), Operand::Reg(rhs), Operand::None));
|
||||
if is_implicit {
|
||||
self.emit_implicit_global_write(name, var_reg, ctx);
|
||||
@@ -368,6 +380,17 @@ impl Emitter {
|
||||
));
|
||||
} else {
|
||||
let var_reg = ctx.lookup_or_global(name);
|
||||
// 未声明名槽是入口快照(读侧登记的槽从不被读刷新):
|
||||
// 旧值读前从全局对象属性取当前值,缺失按 undefined(不抛)。
|
||||
if ctx.is_implicit_global_reg(var_reg) {
|
||||
let key_idx = ctx.add_constant(Constant::String(name.to_string()));
|
||||
ctx.inst(Inst::new(
|
||||
OpCode::LOAD_GLOBAL_TYPEOF,
|
||||
Operand::Reg(var_reg),
|
||||
Operand::Const(key_idx),
|
||||
Operand::None,
|
||||
));
|
||||
}
|
||||
ctx.inst(Inst::new(
|
||||
OpCode::LOAD_VAR,
|
||||
Operand::Reg(result_reg),
|
||||
@@ -408,7 +431,7 @@ impl Emitter {
|
||||
} else if !readonly_builtin {
|
||||
// 隐式全局判定以寄存器集合为准:读侧(旧值解析)已登记绑定,
|
||||
// 写侧二次解析命中集合而非"新登记"。
|
||||
let is_implicit = ctx.implicit_global_writes.contains(&var_reg);
|
||||
let is_implicit = ctx.is_implicit_global_reg(var_reg);
|
||||
if is_implicit && ctx.is_strict {
|
||||
// 严格模式未声明写:抛 ReferenceError,后续 LOAD_VAR 不可达。
|
||||
let _ = self.emit_strict_undeclared_write(name, ctx)?;
|
||||
|
||||
Reference in New Issue
Block a user