1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-25 22:05:07 +00:00

LibWasm+LibWeb: Sneak a JS::Completion into Wasm::Result

Imported functions in Wasm may throw JS exceptions, and we need to
preserve these exceptions so we can pass them to the calling JS code.

This also adds a `assert_wasm_result()` API to Result for cases where
only Wasm traps or values are expected (e.g. internal uses) to avoid
making LibWasm (pointlessly) handle JS exceptions that will never show
up in reality.
This commit is contained in:
Ali Mohammad Pur 2023-02-25 11:15:11 +03:30 committed by Ali Mohammad Pur
parent 1c3050245e
commit 6b50f23242
11 changed files with 95 additions and 35 deletions

View file

@ -200,20 +200,12 @@ JS::ThrowCompletionOr<size_t> WebAssemblyObject::instantiate_module(JS::VM& vm,
for (auto& entry : arguments)
argument_values.append(to_js_value(vm, entry));
auto result_or_error = JS::call(vm, function, JS::js_undefined(), move(argument_values));
if (result_or_error.is_error()) {
return Wasm::Trap();
}
auto result = TRY(JS::call(vm, function, JS::js_undefined(), move(argument_values)));
if (type.results().is_empty())
return Wasm::Result { Vector<Wasm::Value> {} };
if (type.results().size() == 1) {
auto value_or_error = to_webassembly_value(vm, result_or_error.release_value(), type.results().first());
if (value_or_error.is_error())
return Wasm::Trap {};
return Wasm::Result { Vector<Wasm::Value> { value_or_error.release_value() } };
}
if (type.results().size() == 1)
return Wasm::Result { Vector<Wasm::Value> { TRY(to_webassembly_value(vm, result, type.results().first())) } };
// FIXME: Multiple returns
TODO();