mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:47:44 +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:
parent
1c3050245e
commit
6b50f23242
11 changed files with 95 additions and 35 deletions
|
@ -15,9 +15,15 @@ namespace Wasm {
|
|||
struct BytecodeInterpreter : public Interpreter {
|
||||
virtual void interpret(Configuration&) override;
|
||||
virtual ~BytecodeInterpreter() override = default;
|
||||
virtual bool did_trap() const override { return m_trap.has_value(); }
|
||||
virtual DeprecatedString trap_reason() const override { return m_trap.value().reason; }
|
||||
virtual void clear_trap() override { m_trap.clear(); }
|
||||
virtual bool did_trap() const override { return !m_trap.has<Empty>(); }
|
||||
virtual DeprecatedString trap_reason() const override
|
||||
{
|
||||
return m_trap.visit(
|
||||
[](Empty) -> DeprecatedString { VERIFY_NOT_REACHED(); },
|
||||
[](Trap const& trap) { return trap.reason; },
|
||||
[](JS::Completion const& completion) { return completion.value()->to_string_without_side_effects().release_value().to_deprecated_string(); });
|
||||
}
|
||||
virtual void clear_trap() override { m_trap = Empty {}; }
|
||||
|
||||
struct CallFrameHandle {
|
||||
explicit CallFrameHandle(BytecodeInterpreter& interpreter, Configuration& configuration)
|
||||
|
@ -62,10 +68,10 @@ protected:
|
|||
{
|
||||
if (!value)
|
||||
m_trap = Trap { reason };
|
||||
return m_trap.has_value();
|
||||
return !m_trap.has<Empty>();
|
||||
}
|
||||
|
||||
Optional<Trap> m_trap;
|
||||
Variant<Trap, JS::Completion, Empty> m_trap;
|
||||
StackInfo m_stack_info;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue