LibJS/Bytecode: Grab at ThrowCompletionOr errors directly

The interpreter can now grab at the error value directly instead of
instantiating a temporary Completion to hold it.
This commit is contained in:
Andreas Kling 2024-05-10 11:22:27 +02:00 committed by Alexander Kalenik
commit 353e635535
Notes: sideshowbarker 2024-07-17 05:06:13 +09:00
2 changed files with 29 additions and 28 deletions

View file

@ -447,7 +447,7 @@ FLATTEN_ON_CLANG void Interpreter::run_bytecode(size_t entry_point)
auto& instruction = *reinterpret_cast<Op::Jump##op_TitleCase const*>(&bytecode[program_counter]); \
auto result = op_snake_case(vm(), get(instruction.lhs()), get(instruction.rhs())); \
if (result.is_error()) { \
if (handle_exception(program_counter, *result.throw_completion().value()) == HandleExceptionResponse::ExitFromExecutable) \
if (handle_exception(program_counter, result.error_value()) == HandleExceptionResponse::ExitFromExecutable) \
return; \
goto start; \
} \
@ -517,7 +517,7 @@ FLATTEN_ON_CLANG void Interpreter::run_bytecode(size_t entry_point)
{ \
auto result = instruction.execute_impl(*this); \
if (result.is_error()) { \
if (handle_exception(program_counter, *result.throw_completion().value()) == HandleExceptionResponse::ExitFromExecutable) \
if (handle_exception(program_counter, result.error_value()) == HandleExceptionResponse::ExitFromExecutable) \
return; \
goto start; \
} \

View file

@ -315,6 +315,7 @@ public:
[[nodiscard]] bool is_throw_completion() const { return m_value_or_error.template has<ErrorValue>(); }
[[nodiscard]] Completion throw_completion() const { return error(); }
[[nodiscard]] Value error_value() const { return m_value_or_error.template get<ErrorValue>().error; }
[[nodiscard]] bool has_value() const
requires(!IsSame<ValueType, Empty>)