Files
ladybird/Tests/LibJS/Bytecode/input/block-scoping.js
Andreas Kling 7f89158d20 LibJS: Replace implicit environment stack with explicit registers
Replace the saved_lexical_environments stack in ExecutionContextRareData
with explicit register-based environment tracking. Environments are now
stored in registers and restored via SetLexicalEnvironment, making the
environment flow visible in bytecode.

Key changes:
- Add GetLexicalEnvironment and SetLexicalEnvironment opcodes
- CreateLexicalEnvironment takes explicit parent and dst operands
- EnterObjectEnvironment stores new environment in a dst register
- NewClass takes an explicit class_environment operand
- Remove LeaveLexicalEnvironment opcode (instead: SetLexicalEnvironment)
- Remove saved_lexical_environments from ExecutionContextRareData
- Use a reserved register for the saved lexical environment to avoid
  dominance issues with lazily-emitted GetLexicalEnvironment
2026-02-09 16:35:39 +01:00

30 lines
573 B
JavaScript

function closureOverBlockScope() {
let fns = [];
{
let x = 1;
fns.push(() => x);
}
{
let y = 2;
fns.push(() => y);
}
return fns[0]() + fns[1]();
}
console.log(closureOverBlockScope());
function breakThroughBlockScopes() {
let result;
outer: for (let i = 0; i < 3; i++) {
{
let x = i;
let f = () => x;
if (x > 1) {
result = f;
break outer;
}
}
}
return result();
}
console.log(breakThroughBlockScopes());