Parcourir la source

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.
Luke Wilde il y a 3 ans
Parent
commit
04774f923f
1 fichiers modifiés avec 8 ajouts et 1 suppressions
  1. 8 1
      Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp

+ 8 - 1
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 {};
 }