mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
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:
committed by
Andreas Kling
parent
20f50d1f71
commit
7281091fdb
Notes:
github-actions[bot]
2026-02-12 10:39:25 +00:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/7281091fdb7 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7903
@@ -213,21 +213,20 @@ void ECMAScriptFunctionObject::initialize(Realm& realm)
|
||||
}
|
||||
}
|
||||
|
||||
ThrowCompletionOr<void> ECMAScriptFunctionObject::get_stack_frame_size(size_t& registers_and_locals_count, size_t& constants_count, size_t& argument_count)
|
||||
void ECMAScriptFunctionObject::get_stack_frame_size(size_t& registers_and_locals_count, size_t& constants_count, size_t& argument_count)
|
||||
{
|
||||
auto& executable = shared_data().m_executable;
|
||||
if (!executable) {
|
||||
if (is_module_wrapper()) {
|
||||
executable = TRY(Bytecode::compile(vm(), ecmascript_code(), kind(), name()));
|
||||
executable = Bytecode::compile(vm(), ecmascript_code(), kind(), name());
|
||||
} else {
|
||||
executable = TRY(Bytecode::compile(vm(), shared_data(), Bytecode::BuiltinAbstractOperationsEnabled::No));
|
||||
executable = Bytecode::compile(vm(), shared_data(), Bytecode::BuiltinAbstractOperationsEnabled::No);
|
||||
}
|
||||
m_shared_data->clear_compile_inputs();
|
||||
}
|
||||
registers_and_locals_count = executable->registers_and_locals_count;
|
||||
constants_count = executable->constants.size();
|
||||
argument_count = max(argument_count, static_cast<size_t>(formal_parameter_count()));
|
||||
return {};
|
||||
}
|
||||
|
||||
// 10.2.1 [[Call]] ( thisArgument, argumentsList ), https://tc39.es/ecma262/#sec-ecmascript-function-objects-call-thisargument-argumentslist
|
||||
@@ -537,11 +536,8 @@ void async_block_start(VM& vm, T const& async_body, PromiseCapability const& pro
|
||||
// b. If asyncBody is a Parse Node, then
|
||||
if constexpr (!IsSame<T, GC::Function<Completion()>>) {
|
||||
// i. Let result be Completion(Evaluation of asyncBody).
|
||||
auto maybe_executable = Bytecode::compile(vm, async_body, FunctionKind::Async, "AsyncBlockStart"_utf16_fly_string);
|
||||
if (maybe_executable.is_error())
|
||||
result = maybe_executable.release_error();
|
||||
else
|
||||
result = vm.bytecode_interpreter().run_executable(vm.running_execution_context(), *maybe_executable.value(), {});
|
||||
auto executable = Bytecode::compile(vm, async_body, FunctionKind::Async, "AsyncBlockStart"_utf16_fly_string);
|
||||
result = vm.bytecode_interpreter().run_executable(vm.running_execution_context(), *executable, {});
|
||||
}
|
||||
// c. Else,
|
||||
else {
|
||||
|
||||
Reference in New Issue
Block a user