LibJS: Make bytecode generation infallible

Remove CodeGenerationError and make all bytecode generation functions
return their results directly instead of wrapping them in
CodeGenerationErrorOr.

For the few remaining sites where codegen encounters an unimplemented
or unexpected AST node, we now use a new emit_todo() helper that emits
a NewTypeError + Throw sequence at compile time (preserving the runtime
behavior) and then switches to a dead basic block so subsequent codegen
for the same function can continue without issue.

This allows us to remove error handling from all callers of the
bytecode compiler, simplifying the code significantly.
This commit is contained in:
Andreas Kling 2026-02-11 22:42:53 +01:00 committed by Andreas Kling
parent 20f50d1f71
commit 7281091fdb
Notes: github-actions[bot] 2026-02-12 10:39:25 +00:00
23 changed files with 469 additions and 556 deletions

View file

@ -707,10 +707,7 @@ ThrowCompletionOr<void> SourceTextModule::execute_module(VM& vm, GC::Ptr<Promise
dbgln_if(JS_MODULE_DEBUG, "[JS MODULE] SourceTextModule::execute_module({}, PromiseCapability @ {})", filename(), capability.ptr());
if (!m_has_top_level_await && !m_executable) {
auto maybe_executable = Bytecode::compile(vm, *m_ecmascript_code, FunctionKind::Normal, "ShadowRealmEval"_utf16_fly_string);
if (maybe_executable.is_error())
return maybe_executable.release_error();
m_executable = maybe_executable.release_value();
m_executable = Bytecode::compile(vm, *m_ecmascript_code, FunctionKind::Normal, "ShadowRealmEval"_utf16_fly_string);
m_ecmascript_code = nullptr;
}