mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 17:55:07 +02:00
LibJS: Convert NativeFunction::{call,construct}() to ThrowCompletionOr
Both at the same time because many of them call construct() in call() and I'm not keen on adding a bunch of temporary plumbing to turn exceptions into throw completions. Also changes the return value of construct() to Object* instead of Value as it always needs to return an object; allowing an arbitrary Value is a massive foot gun.
This commit is contained in:
Notes:
sideshowbarker
2024-07-18 02:06:32 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/5832de62fe5 Pull-request: https://github.com/SerenityOS/serenity/pull/10548 Reviewed-by: https://github.com/IdanHo ✅
@@ -23,22 +23,21 @@ WebAssemblyModuleConstructor::~WebAssemblyModuleConstructor()
|
||||
{
|
||||
}
|
||||
|
||||
JS::Value WebAssemblyModuleConstructor::call()
|
||||
JS::ThrowCompletionOr<JS::Value> WebAssemblyModuleConstructor::call()
|
||||
{
|
||||
vm().throw_exception<JS::TypeError>(global_object(), JS::ErrorType::ConstructorWithoutNew, "WebAssembly.Module");
|
||||
return {};
|
||||
return vm().throw_completion<JS::TypeError>(global_object(), JS::ErrorType::ConstructorWithoutNew, "WebAssembly.Module");
|
||||
}
|
||||
|
||||
JS::Value WebAssemblyModuleConstructor::construct(FunctionObject&)
|
||||
JS::ThrowCompletionOr<JS::Object*> WebAssemblyModuleConstructor::construct(FunctionObject&)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& global_object = this->global_object();
|
||||
|
||||
auto* buffer_object = TRY_OR_DISCARD(vm.argument(0).to_object(global_object));
|
||||
auto* buffer_object = TRY(vm.argument(0).to_object(global_object));
|
||||
auto result = parse_module(global_object, buffer_object);
|
||||
if (result.is_error()) {
|
||||
vm.throw_exception(global_object, result.error());
|
||||
return {};
|
||||
return JS::throw_completion(result.error());
|
||||
}
|
||||
|
||||
return heap().allocate<WebAssemblyModuleObject>(global_object, global_object, result.release_value());
|
||||
|
||||
Reference in New Issue
Block a user