From 38268f1c535bf5b9352e867cbe0387ca20f7b8b4 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 8 Dec 2020 18:12:39 +0100 Subject: [PATCH] LibJS: Create lexical scope for "catch" on the spot when throwing --- Libraries/LibJS/AST.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Libraries/LibJS/AST.cpp b/Libraries/LibJS/AST.cpp index 565d8f347e..89aefe544f 100644 --- a/Libraries/LibJS/AST.cpp +++ b/Libraries/LibJS/AST.cpp @@ -1901,8 +1901,12 @@ Value TryStatement::execute(Interpreter& interpreter, GlobalObject& global_objec if (auto* exception = interpreter.exception()) { if (m_handler) { interpreter.vm().clear_exception(); - ArgumentVector arguments { { m_handler->parameter(), exception->value() } }; - interpreter.execute_statement(global_object, m_handler->body(), move(arguments)); + + HashMap parameters; + parameters.set(m_handler->parameter(), Variable { exception->value(), DeclarationKind::Var }); + auto* catch_scope = interpreter.heap().allocate(global_object, move(parameters), interpreter.vm().call_frame().scope); + TemporaryChange scope_change(interpreter.vm().call_frame().scope, catch_scope); + interpreter.execute_statement(global_object, m_handler->body()); } }