fix: 顶层 var 声明带初始化撞不可写全局用户属性 strict 抛 TypeError——用户名声明处写点改 session 解析 PutValue 语义,builtin 名保 GDI 写点;序言缺失分支全局不可扩展两模式对齐抛 TypeError

This commit is contained in:
2026-09-12 21:36:10 +00:00
parent 60274baca8
commit bf08803071
5 changed files with 201 additions and 5 deletions
+7 -1
View File
@@ -108,7 +108,13 @@ impl Emitter {
ctx.init_var(name);
// 脚本顶层 var:同步写全局对象,使 globalThis.x 反射声明值。
if ctx.is_global_scope && matches!(kind, VariableDeclarationKind::Var) {
self.emit_global_prop_write(name, src_reg, ctx);
if CompileCtx::is_known_builtin(name) {
// builtin 名保持 GDI 零动作写点(序言镜像值语义),不扩 strict 面。
self.emit_global_prop_write(name, src_reg, ctx);
} else {
// 用户名既有属性面:声明带初始化是 PutValue,0x98 带 strict 分派。
self.emit_global_put_write(name, src_reg, ctx);
}
}
// REPL 持久模式:let/const 也写全局对象属性,使跨轮次读取可见。
if ctx.repl_persist && ctx.is_global_scope && !matches!(kind, VariableDeclarationKind::Var) {