From 9e2edc3085af321cdc7240db43bb5fa001d510d8 Mon Sep 17 00:00:00 2001 From: Simon Wanner Date: Sun, 29 Oct 2023 16:09:44 +0100 Subject: [PATCH] LibJS/JIT: Compile the ThrowIfNotObject instruction --- Userland/Libraries/LibJS/JIT/Compiler.cpp | 14 ++++++++++++++ Userland/Libraries/LibJS/JIT/Compiler.h | 3 ++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJS/JIT/Compiler.cpp b/Userland/Libraries/LibJS/JIT/Compiler.cpp index 10ca6bcd23..ed1ee3293f 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.cpp +++ b/Userland/Libraries/LibJS/JIT/Compiler.cpp @@ -1241,6 +1241,20 @@ void Compiler::compile_iterator_result_done(Bytecode::Op::IteratorResultDone con check_exception(); } +static Value cxx_throw_if_not_object(VM& vm, Value value) +{ + if (!value.is_object()) + TRY_OR_SET_EXCEPTION(vm.throw_completion(ErrorType::NotAnObject, value.to_string_without_side_effects())); + return {}; +} + +void Compiler::compile_throw_if_not_object(Bytecode::Op::ThrowIfNotObject const&) +{ + load_vm_register(ARG1, Bytecode::Register::accumulator()); + native_call((void*)cxx_throw_if_not_object); + check_exception(); +} + void Compiler::jump_to_exit() { m_assembler.jump(m_exit_label); diff --git a/Userland/Libraries/LibJS/JIT/Compiler.h b/Userland/Libraries/LibJS/JIT/Compiler.h index 4551d94189..d9124196e0 100644 --- a/Userland/Libraries/LibJS/JIT/Compiler.h +++ b/Userland/Libraries/LibJS/JIT/Compiler.h @@ -108,7 +108,8 @@ private: O(SuperCallWithArgumentArray, super_call_with_argument_array) \ O(GetIterator, get_iterator) \ O(IteratorNext, iterator_next) \ - O(IteratorResultDone, iterator_result_done) + O(IteratorResultDone, iterator_result_done) \ + O(ThrowIfNotObject, throw_if_not_object) # define DECLARE_COMPILE_OP(OpTitleCase, op_snake_case) \ void compile_##op_snake_case(Bytecode::Op::OpTitleCase const&);