summaryrefslogtreecommitdiff
path: root/Tests
diff options
context:
space:
mode:
authorAli Mohammad Pur <ali.mpfard@gmail.com>2023-02-25 11:15:11 +0330
committerAli Mohammad Pur <Ali.mpfard@gmail.com>2023-02-26 10:54:23 +0330
commit6b50f232426742fcf9e71420c37bf4831bca2e31 (patch)
treebb6a8545d01d0e60e7b5274d835e97d772dcf4d9 /Tests
parent1c3050245ea7660bec230c397ca1046bdf083bd2 (diff)
downloadserenity-6b50f232426742fcf9e71420c37bf4831bca2e31.zip
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.
Diffstat (limited to 'Tests')
-rw-r--r--Tests/LibWasm/CMakeLists.txt2
-rw-r--r--Tests/LibWasm/test-wasm.cpp3
2 files changed, 4 insertions, 1 deletions
diff --git a/Tests/LibWasm/CMakeLists.txt b/Tests/LibWasm/CMakeLists.txt
index f3b3f86666..8e393132f3 100644
--- a/Tests/LibWasm/CMakeLists.txt
+++ b/Tests/LibWasm/CMakeLists.txt
@@ -1,2 +1,2 @@
-serenity_testjs_test(test-wasm.cpp test-wasm LIBS LibWasm)
+serenity_testjs_test(test-wasm.cpp test-wasm LIBS LibWasm LibJS)
install(TARGETS test-wasm RUNTIME DESTINATION bin OPTIONAL)
diff --git a/Tests/LibWasm/test-wasm.cpp b/Tests/LibWasm/test-wasm.cpp
index 233f9f90f5..c882b95a3f 100644
--- a/Tests/LibWasm/test-wasm.cpp
+++ b/Tests/LibWasm/test-wasm.cpp
@@ -246,6 +246,9 @@ JS_DEFINE_NATIVE_FUNCTION(WebAssemblyModule::wasm_invoke)
if (result.is_trap())
return vm.throw_completion<JS::TypeError>(TRY_OR_THROW_OOM(vm, String::formatted("Execution trapped: {}", result.trap().reason)));
+ if (result.is_completion())
+ return result.completion();
+
if (result.values().is_empty())
return JS::js_null();