From 9f4cc6435d8f7533641aac3951d4b4dd87649035 Mon Sep 17 00:00:00 2001 From: Luke Wilde Date: Mon, 14 Mar 2022 02:26:39 +0000 Subject: [PATCH] LibJS/Bytecode: Unwind to closest unwind boundary on Throw This will leave any lexical/variable environments on the way to the closest unwind context boundary. This will not leave the closest unwind context, as we still need the unwind context to perform the Throw instruction correctly. --- Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp | 1 + Userland/Libraries/LibJS/Bytecode/Generator.h | 2 ++ 2 files changed, 3 insertions(+) diff --git a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp index cce2818b6b..2ccd183519 100644 --- a/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp +++ b/Userland/Libraries/LibJS/Bytecode/ASTCodegen.cpp @@ -1441,6 +1441,7 @@ Bytecode::CodeGenerationErrorOr UpdateExpression::generate_bytecode(Byteco Bytecode::CodeGenerationErrorOr ThrowStatement::generate_bytecode(Bytecode::Generator& generator) const { TRY(m_argument->generate_bytecode(generator)); + generator.perform_needed_unwinds(); generator.emit(); return {}; } diff --git a/Userland/Libraries/LibJS/Bytecode/Generator.h b/Userland/Libraries/LibJS/Bytecode/Generator.h index 91662a9aea..6ebb9ad4a0 100644 --- a/Userland/Libraries/LibJS/Bytecode/Generator.h +++ b/Userland/Libraries/LibJS/Bytecode/Generator.h @@ -167,6 +167,8 @@ public: Optional boundary_to_stop_at; if constexpr (IsSame || IsSame) VERIFY(!is_break_node); + else if constexpr (IsSame) + boundary_to_stop_at = BlockBoundaryType::Unwind; else boundary_to_stop_at = is_break_node ? BlockBoundaryType::Break : BlockBoundaryType::Continue;