diff options
author | Luke Wilde <lukew@serenityos.org> | 2022-03-14 02:35:45 +0000 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2022-03-14 21:15:27 +0330 |
commit | 04774f923fa0f80fc4e8f6a718f83f8f776890fc (patch) | |
tree | 05f143b6942011656de69f7915cdf5ae7ca13187 /Userland | |
parent | 9f4cc6435d8f7533641aac3951d4b4dd87649035 (diff) | |
download | serenity-04774f923fa0f80fc4e8f6a718f83f8f776890fc.zip |
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.
Diffstat (limited to 'Userland')
-rw-r--r-- | Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp | 9 |
1 files changed, 8 insertions, 1 deletions
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<void> WithStatement::generate_bytecode(Bytecode: { TRY(m_object->generate_bytecode(generator)); generator.emit<Bytecode::Op::EnterObjectEnvironment>(); + + // 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::LeaveEnvironment>(Bytecode::Op::EnvironmentMode::Lexical); + generator.end_boundary(Bytecode::Generator::BlockBoundaryType::LeaveLexicalEnvironment); + + if (!generator.is_current_block_terminated()) + generator.emit<Bytecode::Op::LeaveEnvironment>(Bytecode::Op::EnvironmentMode::Lexical); + return {}; } |