1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 08:34:57 +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

@ -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();