From bee16bb83ac935fe80a8aa9bf4a381b091952045 Mon Sep 17 00:00:00 2001 From: FalseHonesty Date: Mon, 12 Apr 2021 20:57:30 -0400 Subject: [PATCH] LibJS: Don't suppress GlobalObject variable lookup exceptions In HackStudio's Debugger a custom GlobalObject is used to reflect debugger variables into the JS scope by overriding GlobalObject's get method. However, when throwing a custom error during that lookup it was replaced with the generic "not found" js exception. This patch makes it instead pass along the custom error. --- Userland/Libraries/LibJS/AST.cpp | 3 ++- Userland/Libraries/LibJS/Runtime/VM.cpp | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index 2756de4796..c3a1b7b5ae 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -1251,7 +1251,8 @@ Value Identifier::execute(Interpreter& interpreter, GlobalObject& global_object) auto value = interpreter.vm().get_variable(string(), global_object); if (value.is_empty()) { - interpreter.vm().throw_exception(global_object, ErrorType::UnknownIdentifier, string()); + if (!interpreter.exception()) + interpreter.vm().throw_exception(global_object, ErrorType::UnknownIdentifier, string()); return {}; } return value; diff --git a/Userland/Libraries/LibJS/Runtime/VM.cpp b/Userland/Libraries/LibJS/Runtime/VM.cpp index 84330f8e6e..b6044df7b0 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.cpp +++ b/Userland/Libraries/LibJS/Runtime/VM.cpp @@ -173,6 +173,8 @@ Value VM::get_variable(const FlyString& name, GlobalObject& global_object) for (auto* scope = current_scope(); scope; scope = scope->parent()) { auto possible_match = scope->get_from_scope(name); + if (exception()) + return {}; if (possible_match.has_value()) return possible_match.value().value; }