Pārlūkot izejas kodu

LibJS/JIT: Compile the ThrowIfNullish instruction

Simon Wanner 1 gadu atpakaļ
vecāks
revīzija
e7fdf9c7e5

+ 14 - 0
Userland/Libraries/LibJS/JIT/Compiler.cpp

@@ -1255,6 +1255,20 @@ void Compiler::compile_throw_if_not_object(Bytecode::Op::ThrowIfNotObject const&
     check_exception();
     check_exception();
 }
 }
 
 
+static Value cxx_throw_if_nullish(VM& vm, Value value)
+{
+    if (value.is_nullish())
+        TRY_OR_SET_EXCEPTION(vm.throw_completion<TypeError>(ErrorType::NotObjectCoercible, value.to_string_without_side_effects()));
+    return {};
+}
+
+void Compiler::compile_throw_if_nullish(Bytecode::Op::ThrowIfNullish const&)
+{
+    load_vm_register(ARG1, Bytecode::Register::accumulator());
+    native_call((void*)cxx_throw_if_nullish);
+    check_exception();
+}
+
 void Compiler::jump_to_exit()
 void Compiler::jump_to_exit()
 {
 {
     m_assembler.jump(m_exit_label);
     m_assembler.jump(m_exit_label);

+ 2 - 1
Userland/Libraries/LibJS/JIT/Compiler.h

@@ -109,7 +109,8 @@ private:
         O(GetIterator, get_iterator)                                             \
         O(GetIterator, get_iterator)                                             \
         O(IteratorNext, iterator_next)                                           \
         O(IteratorNext, iterator_next)                                           \
         O(IteratorResultDone, iterator_result_done)                              \
         O(IteratorResultDone, iterator_result_done)                              \
-        O(ThrowIfNotObject, throw_if_not_object)
+        O(ThrowIfNotObject, throw_if_not_object)                                 \
+        O(ThrowIfNullish, throw_if_nullish)
 
 
 #    define DECLARE_COMPILE_OP(OpTitleCase, op_snake_case) \
 #    define DECLARE_COMPILE_OP(OpTitleCase, op_snake_case) \
         void compile_##op_snake_case(Bytecode::Op::OpTitleCase const&);
         void compile_##op_snake_case(Bytecode::Op::OpTitleCase const&);