1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:38:11 +00:00

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.
This commit is contained in:
Ali Mohammad Pur 2022-02-12 19:54:08 +03:30 committed by Linus Groh
parent 3a5f7cb524
commit 75aa900b83
10 changed files with 378 additions and 233 deletions

View file

@ -767,7 +767,11 @@ Completion ECMAScriptFunctionObject::ordinary_call_evaluate_body()
// FIXME: pass something to evaluate default arguments with
TRY(function_declaration_instantiation(nullptr));
if (!m_bytecode_executable) {
m_bytecode_executable = Bytecode::Generator::generate(m_ecmascript_code, m_kind);
auto executable_result = JS::Bytecode::Generator::generate(m_ecmascript_code, m_kind);
if (executable_result.is_error())
return vm.throw_completion<InternalError>(bytecode_interpreter->global_object(), ErrorType::NotImplemented, executable_result.error().to_string());
m_bytecode_executable = executable_result.release_value();
m_bytecode_executable->name = m_name;
auto& passes = JS::Bytecode::Interpreter::optimization_pipeline();
passes.perform(*m_bytecode_executable);