feat: 共享 ThrowTypeError 对象并拆分 arguments callee 四象限

This commit is contained in:
2026-09-26 15:01:50 +00:00
parent d773cc7282
commit de236fb5d1
11 changed files with 138 additions and 67 deletions
+5
View File
@@ -120,6 +120,9 @@ pub struct CompileCtx {
/// 函数 `length` 属性值:首个带默认值形参之前的形参数(rest 不计)。
/// emit_params_prologue 前由编译入口从 param_specs 计算。
pub(crate) function_length: u32,
/// 形参列表是否 simple(全部无初始值标识符且无 rest):arguments 对象
/// callee 形态(数据属性 vs 受限访问器)按 strict ‖ !simple 分流。
pub(crate) has_simple_params: bool,
pub(crate) const_overflow: bool,
/// with 语句作用域栈:元素为 (with 对象寄存器, 打开时的作用域深度)。
/// 非空时 with 体内的自由标识符需动态解析(先查对象属性,回退外层)。
@@ -250,6 +253,7 @@ impl CompileCtx {
implicit_global_reads: HashSet::new(),
implicit_global_writes: HashSet::new(),
function_length: 0,
has_simple_params: false,
const_overflow: false,
with_stack: Vec::new(),
open_try_handlers: Vec::new(),
@@ -819,6 +823,7 @@ impl CompileCtx {
captured_this_const_idx: 0,
function_name: None,
function_length: self.function_length,
has_simple_params: self.has_simple_params,
is_top_level: parent_ctx.is_none(),
const_overflow: self.const_overflow,
nested: std::mem::take(&mut self.nested),
+8
View File
@@ -319,6 +319,14 @@ impl Emitter {
})
.count() as u32;
// simple 参数列表:全部形参为无初始值标识符且无 rest(规范
// simpleParameterList)。arguments 对象 callee 形态(数据属性 vs
// 受限访问器)按 strict ‖ !simple 分流,length 口径不可代用
// (f({x}) 的 length 与 n_args 相等但非 simple)。
ctx.has_simple_params = param_specs
.iter()
.all(|spec| matches!(spec, ParamSpec::Identifier { initializer: None, .. }));
// 继承父内置寄存器映射:子模块寄存器文件中,内置标识符(Math、Object 等)
// 解析到父预先分配的槽位。
ctx.scopes.builtin_reg_map = parent_ctx.scopes.builtin_reg_map.clone();