mirror of
https://github.com/pjh456/OxideJS.git
synced 2026-10-25 11:11:11 +08:00
fix: 脚本顶层 var/function 声明落 globalThis(DEFINE_GLOBAL_PROP 非可配置数据属性)
This commit is contained in:
@@ -60,6 +60,10 @@ impl Emitter {
|
||||
} else {
|
||||
ctx.inst(Inst::new(OpCode::STORE_VAR, Operand::Reg(var_reg), Operand::Reg(var_reg), Operand::None));
|
||||
}
|
||||
// 脚本顶层函数声明:同步写全局对象,使 globalThis 可反射函数名。
|
||||
if ctx.is_global_scope {
|
||||
self.emit_global_prop_write(&name, var_reg, ctx);
|
||||
}
|
||||
Ok(None)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +61,10 @@ impl Emitter {
|
||||
ctx.inst(Inst::new(OpCode::STORE_VAR, Operand::Reg(target_reg), Operand::Reg(tmp), Operand::None));
|
||||
}
|
||||
ctx.init_var(bi.name.as_str());
|
||||
// 脚本顶层 var 无初始化:仍须写全局对象属性(值为 undefined)。
|
||||
if ctx.is_global_scope && matches!(decl.kind, VariableDeclarationKind::Var) {
|
||||
self.emit_global_prop_write(bi.name.as_str(), tmp, ctx);
|
||||
}
|
||||
r = Some(var_reg);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user