diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2022-02-12 19:54:08 +0330 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-02-13 14:41:33 +0000 |
commit | 75aa900b830a3e72dbc59229c44a6c0b88d99230 (patch) | |
tree | 6572353b81b80f31bd58266d7d22bdf46a6cb5f4 /Userland/Utilities/js.cpp | |
parent | 3a5f7cb524bb061bae07ba0554ef1edcd34c502b (diff) | |
download | serenity-75aa900b830a3e72dbc59229c44a6c0b88d99230.zip |
LibJS: Make ASTNode::generate_bytecode() fallible
Instead of crashing on the spot, return a descriptive error that will
eventually continue its days as a javascript "InternalError" exception.
This should make random crashes with BC less likely.
Diffstat (limited to 'Userland/Utilities/js.cpp')
-rw-r--r-- | Userland/Utilities/js.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/Userland/Utilities/js.cpp b/Userland/Utilities/js.cpp index b91ff09f82..17f788f191 100644 --- a/Userland/Utilities/js.cpp +++ b/Userland/Utilities/js.cpp @@ -1024,7 +1024,13 @@ static bool parse_and_run(JS::Interpreter& interpreter, StringView source, Strin script_or_module->parse_node().dump(0); if (JS::Bytecode::g_dump_bytecode || s_run_bytecode) { - auto executable = JS::Bytecode::Generator::generate(script_or_module->parse_node()); + auto executable_result = JS::Bytecode::Generator::generate(script_or_module->parse_node()); + if (executable_result.is_error()) { + result = vm->throw_completion<JS::InternalError>(interpreter.global_object(), executable_result.error().to_string()); + return ReturnEarly::No; + } + + auto executable = executable_result.release_value(); executable->name = source_name; if (s_opt_bytecode) { auto& passes = JS::Bytecode::Interpreter::optimization_pipeline(); |