mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:28:11 +00: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:
parent
0881f8160f
commit
5832de62fe
99 changed files with 597 additions and 669 deletions
|
@ -23,27 +23,23 @@ WebAssemblyInstanceConstructor::~WebAssemblyInstanceConstructor()
|
|||
{
|
||||
}
|
||||
|
||||
JS::Value WebAssemblyInstanceConstructor::call()
|
||||
JS::ThrowCompletionOr<JS::Value> WebAssemblyInstanceConstructor::call()
|
||||
{
|
||||
vm().throw_exception<JS::TypeError>(global_object(), JS::ErrorType::ConstructorWithoutNew, "WebAssembly.Instance");
|
||||
return {};
|
||||
return vm().throw_completion<JS::TypeError>(global_object(), JS::ErrorType::ConstructorWithoutNew, "WebAssembly.Instance");
|
||||
}
|
||||
|
||||
JS::Value WebAssemblyInstanceConstructor::construct(FunctionObject&)
|
||||
JS::ThrowCompletionOr<JS::Object*> WebAssemblyInstanceConstructor::construct(FunctionObject&)
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
auto& global_object = this->global_object();
|
||||
auto* module_argument = TRY_OR_DISCARD(vm.argument(0).to_object(global_object));
|
||||
if (!is<WebAssemblyModuleObject>(module_argument)) {
|
||||
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Module");
|
||||
return {};
|
||||
}
|
||||
|
||||
auto* module_argument = TRY(vm.argument(0).to_object(global_object));
|
||||
if (!is<WebAssemblyModuleObject>(module_argument))
|
||||
return vm.throw_completion<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Module");
|
||||
auto& module_object = static_cast<WebAssemblyModuleObject&>(*module_argument);
|
||||
auto result = WebAssemblyObject::instantiate_module(module_object.module(), vm, global_object);
|
||||
if (result.is_error()) {
|
||||
vm.throw_exception(global_object, result.release_error());
|
||||
return {};
|
||||
vm.throw_exception(global_object, result.error());
|
||||
return JS::throw_completion(result.error());
|
||||
}
|
||||
return heap().allocate<WebAssemblyInstanceObject>(global_object, global_object, result.value());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue