diff options
author | Ali Mohammad Pur <ali.mpfard@gmail.com> | 2023-02-25 11:15:11 +0330 |
---|---|---|
committer | Ali Mohammad Pur <Ali.mpfard@gmail.com> | 2023-02-26 10:54:23 +0330 |
commit | 6b50f232426742fcf9e71420c37bf4831bca2e31 (patch) | |
tree | bb6a8545d01d0e60e7b5274d835e97d772dcf4d9 /Userland/Utilities/wasm.cpp | |
parent | 1c3050245ea7660bec230c397ca1046bdf083bd2 (diff) | |
download | serenity-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 'Userland/Utilities/wasm.cpp')
-rw-r--r-- | Userland/Utilities/wasm.cpp | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/Userland/Utilities/wasm.cpp b/Userland/Utilities/wasm.cpp index 00652bbd57..38c061095a 100644 --- a/Userland/Utilities/wasm.cpp +++ b/Userland/Utilities/wasm.cpp @@ -206,15 +206,17 @@ static bool pre_interpret_hook(Wasm::Configuration& config, Wasm::InstructionPoi Wasm::Result result { Wasm::Trap {} }; { Wasm::BytecodeInterpreter::CallFrameHandle handle { g_interpreter, config }; - result = config.call(g_interpreter, *address, move(values)); + result = config.call(g_interpreter, *address, move(values)).assert_wasm_result(); } - if (result.is_trap()) + if (result.is_trap()) { warnln("Execution trapped: {}", result.trap().reason); - if (!result.values().is_empty()) - warnln("Returned:"); - for (auto& value : result.values()) { - g_stdout->write(" -> "sv.bytes()).release_value_but_fixme_should_propagate_errors(); - g_printer->print(value); + } else { + if (!result.values().is_empty()) + warnln("Returned:"); + for (auto& value : result.values()) { + g_stdout->write(" -> "sv.bytes()).release_value_but_fixme_should_propagate_errors(); + g_printer->print(value); + } } continue; } @@ -513,7 +515,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) outln(); } - auto result = machine.invoke(g_interpreter, run_address.value(), move(values)); + auto result = machine.invoke(g_interpreter, run_address.value(), move(values)).assert_wasm_result(); if (debug) launch_repl(); |