From 3a8f913eee397f0844c082125bb9aea5b1d665a1 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 10 Jun 2021 21:04:12 +0200 Subject: [PATCH] LibJS: Don't generate bytecode after we've encountered a parser error --- Userland/Utilities/js.cpp | 40 +++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Userland/Utilities/js.cpp b/Userland/Utilities/js.cpp index b99d2c53879..1566e06287e 100644 --- a/Userland/Utilities/js.cpp +++ b/Userland/Utilities/js.cpp @@ -512,25 +512,6 @@ static bool parse_and_run(JS::Interpreter& interpreter, const StringView& source if (s_dump_ast) program->dump(0); - if (s_dump_bytecode || s_run_bytecode) { - auto unit = JS::Bytecode::Generator::generate(*program); - if (s_dump_bytecode) { - for (auto& block : unit.basic_blocks) - block.dump(unit); - if (!unit.string_table->is_empty()) { - outln(); - unit.string_table->dump(); - } - } - - if (s_run_bytecode) { - JS::Bytecode::Interpreter bytecode_interpreter(interpreter.global_object()); - bytecode_interpreter.run(unit); - } - - return true; - } - if (parser.has_errors()) { auto error = parser.errors()[0]; auto hint = error.source_location_hint(source); @@ -538,7 +519,26 @@ static bool parse_and_run(JS::Interpreter& interpreter, const StringView& source outln("{}", hint); vm->throw_exception(interpreter.global_object(), error.to_string()); } else { - interpreter.run(interpreter.global_object(), *program); + if (s_dump_bytecode || s_run_bytecode) { + auto unit = JS::Bytecode::Generator::generate(*program); + if (s_dump_bytecode) { + for (auto& block : unit.basic_blocks) + block.dump(unit); + if (!unit.string_table->is_empty()) { + outln(); + unit.string_table->dump(); + } + } + + if (s_run_bytecode) { + JS::Bytecode::Interpreter bytecode_interpreter(interpreter.global_object()); + bytecode_interpreter.run(unit); + } + + return true; + } else { + interpreter.run(interpreter.global_object(), *program); + } } auto handle_exception = [&] {