summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb
diff options
context:
space:
mode:
authorIdan Horowitz <idan.horowitz@gmail.com>2021-10-19 22:53:27 +0300
committerLinus Groh <mail@linusgroh.de>2021-10-20 12:27:19 +0100
commitca27e5eff56ebdaf7f990296c6429f1b3afaa057 (patch)
treec8a33d4d2c3419d5844dac57cf78534c4b13d011 /Userland/Libraries/LibWeb
parent20163c058485dc524402c46f21bbe65a860bf9c5 (diff)
downloadserenity-ca27e5eff56ebdaf7f990296c6429f1b3afaa057.zip
LibJS: Convert NativeFunction callback to ThrowCompletionOr
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r--Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp12
1 files changed, 5 insertions, 7 deletions
diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp
index 1c4b72c4c2..de5ed754e7 100644
--- a/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp
+++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssemblyObject.cpp
@@ -442,7 +442,7 @@ JS::NativeFunction* create_native_function(Wasm::FunctionAddress address, String
auto function = JS::NativeFunction::create(
global_object,
name,
- [address, type = type.release_value()](JS::VM& vm, JS::GlobalObject& global_object) -> JS::Value {
+ [address, type = type.release_value()](JS::VM& vm, JS::GlobalObject& global_object) -> JS::ThrowCompletionOr<JS::Value> {
Vector<Wasm::Value> values;
values.ensure_capacity(type.parameters().size());
@@ -453,15 +453,13 @@ JS::NativeFunction* create_native_function(Wasm::FunctionAddress address, String
if (result.has_value())
values.append(result.release_value());
else
- return {};
+ return JS::throw_completion(vm.exception()->value());
}
auto result = WebAssemblyObject::s_abstract_machine.invoke(address, move(values));
// FIXME: Use the convoluted mapping of errors defined in the spec.
- if (result.is_trap()) {
- vm.throw_exception<JS::TypeError>(global_object, String::formatted("Wasm execution trapped (WIP): {}", result.trap().reason));
- return {};
- }
+ if (result.is_trap())
+ return vm.throw_completion<JS::TypeError>(global_object, String::formatted("Wasm execution trapped (WIP): {}", result.trap().reason));
if (result.values().is_empty())
return JS::js_undefined();
@@ -473,7 +471,7 @@ JS::NativeFunction* create_native_function(Wasm::FunctionAddress address, String
for (auto& entry : result.values())
result_values.append(to_js_value(entry, global_object));
- return JS::Array::create_from(global_object, result_values);
+ return JS::Value(JS::Array::create_from(global_object, result_values));
});
WebAssemblyObject::s_global_cache.function_instances.set(address, function);