Skip to content

Commit 04774f9

Browse files
Lubrsialimpfard
authored andcommitted
LibJS/Bytecode: Setup lexical environment boundary for with statements
This allows us to properly unwind the object environment for `with` on a block terminating instruction, e.g. an unconditional throw.
1 parent 9f4cc64 commit 04774f9

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1625,8 +1625,15 @@ Bytecode::CodeGenerationErrorOr<void> WithStatement::generate_bytecode(Bytecode:
16251625
{
16261626
TRY(m_object->generate_bytecode(generator));
16271627
generator.emit<Bytecode::Op::EnterObjectEnvironment>();
1628+
1629+
// EnterObjectEnvironment sets the running execution context's lexical_environment to a new Object Environment.
1630+
generator.start_boundary(Bytecode::Generator::BlockBoundaryType::LeaveLexicalEnvironment);
16281631
TRY(m_body->generate_bytecode(generator));
1629-
generator.emit<Bytecode::Op::LeaveEnvironment>(Bytecode::Op::EnvironmentMode::Lexical);
1632+
generator.end_boundary(Bytecode::Generator::BlockBoundaryType::LeaveLexicalEnvironment);
1633+
1634+
if (!generator.is_current_block_terminated())
1635+
generator.emit<Bytecode::Op::LeaveEnvironment>(Bytecode::Op::EnvironmentMode::Lexical);
1636+
16301637
return {};
16311638
}
16321639

0 commit comments

Comments
 (0)