1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-28 19:02:12 +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

@ -34,7 +34,7 @@ namespace Wasm {
void BytecodeInterpreter::interpret(Configuration& configuration)
{
m_trap.clear();
m_trap = Empty {};
auto& instructions = configuration.frame().expression().instructions();
auto max_ip_value = InstructionPointer { instructions.size() };
auto& current_ip_value = configuration.ip();
@ -51,7 +51,7 @@ void BytecodeInterpreter::interpret(Configuration& configuration)
auto& instruction = instructions[current_ip_value.value()];
auto old_ip = current_ip_value;
interpret(configuration, current_ip_value, instruction);
if (m_trap.has_value())
if (did_trap())
return;
if (current_ip_value == old_ip) // If no jump occurred
++current_ip_value;
@ -140,6 +140,11 @@ void BytecodeInterpreter::call_address(Configuration& configuration, FunctionAdd
return;
}
if (result.is_completion()) {
m_trap = move(result.completion());
return;
}
configuration.stack().entries().ensure_capacity(configuration.stack().size() + result.values().size());
for (auto& entry : result.values().in_reverse())
configuration.stack().entries().unchecked_append(move(entry));