fix: 对齐 counter/emitter 指令条数,修解构参数、数组赋值元素、解构catch、for-init 无初始化的跳转漂移

This commit is contained in:
爱特每羊队
2026-06-27 20:32:33 +08:00
parent 3c92f8368c
commit 242e94af09
7 changed files with 104 additions and 14 deletions
@@ -120,12 +120,14 @@ fn regression_for_var_init() {
#[test]
fn regression_var_decl_counter_no_init() {
let result = std::panic::catch_unwind(|| {
compile_source("for (var i; i < 3; i = i + 1) {}");
});
// `for (var i; ...)` initializes `i` to undefined (var semantics, not TDZ), and the
// counter/emitter agree on the no-init declarator's instruction count, so it compiles
// to a well-formed loop header instead of panicking.
let module = compile_source("for (var i; i < 3; i = i + 1) {}");
assert!(!module.bytecode.is_empty(), "for(var) no-init should compile");
assert!(
result.is_err(),
"for(var) without initializer should fail - accessing TDZ variable in test expression"
module.bytecode.iter().any(|&i| opcode::opcode(i) == OpCode::JMP_IF_FALSE),
"for(var) no-init should contain JMP_IF_FALSE"
);
}