summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/WebAssembly
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-10-12 19:24:57 +0100
committerLinus Groh <mail@linusgroh.de>2021-10-13 09:55:10 +0100
commit52976bfac675f9166fd1a9bf0bf6082e4615a086 (patch)
tree7cb7b7971db2f4df59472b7887b1304c38b94e30 /Userland/Libraries/LibWeb/WebAssembly
parent9eb065a1f62f34f62f2484139cf3063ef42565dd (diff)
downloadserenity-52976bfac675f9166fd1a9bf0bf6082e4615a086.zip
LibJS: Convert to_object() to ThrowCompletionOr
Diffstat (limited to 'Userland/Libraries/LibWeb/WebAssembly')
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceConstructor.cpp6
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObjectPrototype.cpp4
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp5
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp8
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/WebAssemblyModuleConstructor.cpp5
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp43
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp5
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.cpp16
8 files changed, 38 insertions, 54 deletions
diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceConstructor.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceConstructor.cpp
index 770249be7f..aa33ca5916 100644
--- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceConstructor.cpp
+++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceConstructor.cpp
@@ -33,11 +33,7 @@ JS::Value WebAssemblyInstanceConstructor::construct(FunctionObject&)
{
auto& vm = this->vm();
auto& global_object = this->global_object();
-
- auto module_argument = vm.argument(0).to_object(global_object);
- if (vm.exception())
- return {};
-
+ 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 {};
diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObjectPrototype.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObjectPrototype.cpp
index 924a6c1102..1db0997d0f 100644
--- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObjectPrototype.cpp
+++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyInstanceObjectPrototype.cpp
@@ -19,9 +19,7 @@ void WebAssemblyInstancePrototype::initialize(JS::GlobalObject& global_object)
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyInstancePrototype::exports_getter)
{
auto this_value = vm.this_value(global_object);
- auto this_object = this_value.to_object(global_object);
- if (vm.exception())
- return {};
+ auto* this_object = TRY_OR_DISCARD(this_value.to_object(global_object));
if (!is<WebAssemblyInstanceObject>(this_object)) {
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Instance");
return {};
diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp
index 703bbd47b4..6546d01860 100644
--- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp
+++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryConstructor.cpp
@@ -32,10 +32,7 @@ JS::Value WebAssemblyMemoryConstructor::construct(FunctionObject&)
auto& vm = this->vm();
auto& global_object = this->global_object();
- auto descriptor = vm.argument(0).to_object(global_object);
- if (vm.exception())
- return {};
-
+ auto descriptor = TRY_OR_DISCARD(vm.argument(0).to_object(global_object));
auto initial_value = TRY_OR_DISCARD(descriptor->get("initial"));
auto maximum_value = TRY_OR_DISCARD(descriptor->get("maximum"));
diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp
index 2a9151f656..e16abbf0b0 100644
--- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp
+++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyMemoryPrototype.cpp
@@ -22,8 +22,8 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyMemoryPrototype::grow)
auto page_count = vm.argument(0).to_u32(global_object);
if (vm.exception())
return {};
- auto* this_object = vm.this_value(global_object).to_object(global_object);
- if (!this_object || !is<WebAssemblyMemoryObject>(this_object)) {
+ auto* this_object = TRY_OR_DISCARD(vm.this_value(global_object).to_object(global_object));
+ if (!is<WebAssemblyMemoryObject>(this_object)) {
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Memory");
return {};
}
@@ -44,8 +44,8 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyMemoryPrototype::grow)
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyMemoryPrototype::buffer_getter)
{
- auto* this_object = vm.this_value(global_object).to_object(global_object);
- if (!this_object || !is<WebAssemblyMemoryObject>(this_object)) {
+ auto* this_object = TRY_OR_DISCARD(vm.this_value(global_object).to_object(global_object));
+ if (!is<WebAssemblyMemoryObject>(this_object)) {
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Memory");
return {};
}
diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyModuleConstructor.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyModuleConstructor.cpp
index ba1ac2ee17..2d8e188f54 100644
--- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyModuleConstructor.cpp
+++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyModuleConstructor.cpp
@@ -34,10 +34,7 @@ JS::Value WebAssemblyModuleConstructor::construct(FunctionObject&)
auto& vm = this->vm();
auto& global_object = this->global_object();
- auto buffer_object = vm.argument(0).to_object(global_object);
- if (vm.exception())
- return {};
-
+ auto* buffer_object = TRY_OR_DISCARD(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());
diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp
index bc12fc8277..699dc19690 100644
--- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp
+++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp
@@ -130,17 +130,19 @@ Result<size_t, JS::Value> parse_module(JS::GlobalObject& global_object, JS::Obje
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::compile)
{
// FIXME: This shouldn't block!
- auto buffer = vm.argument(0).to_object(global_object);
+ auto buffer_or_error = vm.argument(0).to_object(global_object);
JS::Value rejection_value;
- if (vm.exception()) {
- rejection_value = vm.exception()->value();
+ if (buffer_or_error.is_error()) {
+ rejection_value = buffer_or_error.throw_completion().value();
vm.clear_exception();
+ vm.stop_unwind();
}
auto promise = JS::Promise::create(global_object);
if (!rejection_value.is_empty()) {
promise->reject(rejection_value);
return promise;
}
+ auto* buffer = buffer_or_error.release_value();
auto result = parse_module(global_object, buffer);
if (result.is_error())
promise->reject(result.error());
@@ -155,11 +157,13 @@ Result<size_t, JS::Value> WebAssemblyObject::instantiate_module(Wasm::Module con
HashMap<Wasm::Linker::Name, Wasm::ExternValue> resolved_imports;
auto import_argument = vm.argument(1);
if (!import_argument.is_undefined()) {
- [[maybe_unused]] auto import_object = import_argument.to_object(global_object);
- if (auto exception = vm.exception()) {
+ auto import_object_or_error = import_argument.to_object(global_object);
+ if (import_object_or_error.is_error()) {
vm.clear_exception();
- return exception->value();
+ vm.stop_unwind();
+ return import_object_or_error.throw_completion().value();
}
+ [[maybe_unused]] auto* import_object = import_object_or_error.release_value();
dbgln("Trying to resolve stuff because import object was specified");
for (const Wasm::Linker::Name& import_name : linker.unresolved_imports()) {
@@ -168,10 +172,10 @@ Result<size_t, JS::Value> WebAssemblyObject::instantiate_module(Wasm::Module con
if (value_or_error.is_error())
break;
auto value = value_or_error.release_value();
- auto object = value.to_object(global_object);
- if (vm.exception())
+ auto object_or_error = value.to_object(global_object);
+ if (object_or_error.is_error())
break;
-
+ auto* object = object_or_error.release_value();
auto import_or_error = object->get(import_name.name);
if (import_or_error.is_error())
break;
@@ -307,22 +311,17 @@ Result<size_t, JS::Value> WebAssemblyObject::instantiate_module(Wasm::Module con
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyObject::instantiate)
{
// FIXME: This shouldn't block!
- auto buffer = vm.argument(0).to_object(global_object);
+ auto buffer_or_error = vm.argument(0).to_object(global_object);
auto promise = JS::Promise::create(global_object);
bool should_return_module = false;
- auto take_exception_and_reject_if_needed = [&] {
- if (vm.exception()) {
- auto rejection_value = vm.exception()->value();
- vm.clear_exception();
- promise->reject(rejection_value);
- return true;
- }
-
- return false;
- };
-
- if (take_exception_and_reject_if_needed())
+ if (buffer_or_error.is_error()) {
+ auto rejection_value = buffer_or_error.throw_completion().value();
+ vm.clear_exception();
+ vm.stop_unwind();
+ promise->reject(rejection_value);
return promise;
+ }
+ auto* buffer = buffer_or_error.release_value();
const Wasm::Module* module { nullptr };
if (is<JS::ArrayBuffer>(buffer) || is<JS::TypedArrayBase>(buffer)) {
diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp
index cfe8b67d05..dc58bf4b42 100644
--- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp
+++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTableConstructor.cpp
@@ -34,10 +34,7 @@ JS::Value WebAssemblyTableConstructor::construct(FunctionObject&)
auto& vm = this->vm();
auto& global_object = this->global_object();
- auto descriptor = vm.argument(0).to_object(global_object);
- if (vm.exception())
- return {};
-
+ auto descriptor = TRY_OR_DISCARD(vm.argument(0).to_object(global_object));
auto element_value = TRY_OR_DISCARD(descriptor->get("element"));
if (!element_value.is_string()) {
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::InvalidHint, element_value.to_string_without_side_effects());
diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.cpp
index a88d800a35..f8d2381007 100644
--- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.cpp
+++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyTablePrototype.cpp
@@ -24,8 +24,8 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::grow)
auto delta = vm.argument(0).to_u32(global_object);
if (vm.exception())
return {};
- auto* this_object = vm.this_value(global_object).to_object(global_object);
- if (!this_object || !is<WebAssemblyTableObject>(this_object)) {
+ auto* this_object = TRY_OR_DISCARD(vm.this_value(global_object).to_object(global_object));
+ if (!is<WebAssemblyTableObject>(this_object)) {
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table");
return {};
}
@@ -63,8 +63,8 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::get)
if (vm.exception())
return {};
- auto* this_object = vm.this_value(global_object).to_object(global_object);
- if (!this_object || !is<WebAssemblyTableObject>(this_object)) {
+ auto* this_object = TRY_OR_DISCARD(vm.this_value(global_object).to_object(global_object));
+ if (!is<WebAssemblyTableObject>(this_object)) {
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table");
return {};
}
@@ -93,8 +93,8 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::set)
if (vm.exception())
return {};
- auto* this_object = vm.this_value(global_object).to_object(global_object);
- if (!this_object || !is<WebAssemblyTableObject>(this_object)) {
+ auto* this_object = TRY_OR_DISCARD(vm.this_value(global_object).to_object(global_object));
+ if (!is<WebAssemblyTableObject>(this_object)) {
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table");
return {};
}
@@ -128,8 +128,8 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::set)
JS_DEFINE_NATIVE_FUNCTION(WebAssemblyTablePrototype::length_getter)
{
- auto* this_object = vm.this_value(global_object).to_object(global_object);
- if (!this_object || !is<WebAssemblyTableObject>(this_object)) {
+ auto* this_object = TRY_OR_DISCARD(vm.this_value(global_object).to_object(global_object));
+ if (!is<WebAssemblyTableObject>(this_object)) {
vm.throw_exception<JS::TypeError>(global_object, JS::ErrorType::NotAnObjectOfType, "WebAssembly.Table");
return {};
}