From 04774f923fa0f80fc4e8f6a718f83f8f776890fc Mon Sep 17 00:00:00 2001 From: Luke Wilde Date: Mon, 14 Mar 2022 02:35:45 +0000 Subject: [PATCH] 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. --- Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp index 2ccd183519..3bd8ee32d7 100644 --- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -1625,8 +1625,15 @@ Bytecode::CodeGenerationErrorOr WithStatement::generate_bytecode(Bytecode: { TRY(m_object->generate_bytecode(generator)); generator.emit(); + + // EnterObjectEnvironment sets the running execution context's lexical_environment to a new Object Environment. + generator.start_boundary(Bytecode::Generator::BlockBoundaryType::LeaveLexicalEnvironment); TRY(m_body->generate_bytecode(generator)); - generator.emit(Bytecode::Op::EnvironmentMode::Lexical); + generator.end_boundary(Bytecode::Generator::BlockBoundaryType::LeaveLexicalEnvironment); + + if (!generator.is_current_block_terminated()) + generator.emit(Bytecode::Op::EnvironmentMode::Lexical); + return {}; }