Ver Fonte

LibJS: Compile the CallWithArgumentArray bytecode instruction

Idan Horowitz há 1 ano atrás
pai
commit
b2d8d0c270

+ 28 - 0
Userland/Libraries/LibJS/Bytecode/CommonImplementations.cpp

@@ -7,6 +7,7 @@
 #include <LibJS/Bytecode/CommonImplementations.h>
 #include <LibJS/Bytecode/CommonImplementations.h>
 #include <LibJS/Bytecode/Interpreter.h>
 #include <LibJS/Bytecode/Interpreter.h>
 #include <LibJS/Bytecode/Op.h>
 #include <LibJS/Bytecode/Op.h>
+#include <LibJS/Runtime/Array.h>
 #include <LibJS/Runtime/DeclarativeEnvironment.h>
 #include <LibJS/Runtime/DeclarativeEnvironment.h>
 #include <LibJS/Runtime/ECMAScriptFunctionObject.h>
 #include <LibJS/Runtime/ECMAScriptFunctionObject.h>
 #include <LibJS/Runtime/GlobalEnvironment.h>
 #include <LibJS/Runtime/GlobalEnvironment.h>
@@ -395,4 +396,31 @@ Value new_regexp(VM& vm, ParsedRegex const& parsed_regex, DeprecatedString const
     return regexp_object;
     return regexp_object;
 }
 }
 
 
+// 13.3.8.1 https://tc39.es/ecma262/#sec-runtime-semantics-argumentlistevaluation
+MarkedVector<Value> argument_list_evaluation(Bytecode::Interpreter& interpreter)
+{
+    // Note: Any spreading and actual evaluation is handled in preceding opcodes
+    // Note: The spec uses the concept of a list, while we create a temporary array
+    //       in the preceding opcodes, so we have to convert in a manner that is not
+    //       visible to the user
+    auto& vm = interpreter.vm();
+
+    MarkedVector<Value> argument_values { vm.heap() };
+    auto arguments = interpreter.accumulator();
+
+    auto& argument_array = arguments.as_array();
+    auto array_length = argument_array.indexed_properties().array_like_size();
+
+    argument_values.ensure_capacity(array_length);
+
+    for (size_t i = 0; i < array_length; ++i) {
+        if (auto maybe_value = argument_array.indexed_properties().get(i); maybe_value.has_value())
+            argument_values.append(maybe_value.release_value().value);
+        else
+            argument_values.append(js_undefined());
+    }
+
+    return argument_values;
+}
+
 }
 }

+ 1 - 0
Userland/Libraries/LibJS/Bytecode/CommonImplementations.h

@@ -31,5 +31,6 @@ struct CalleeAndThis {
 };
 };
 ThrowCompletionOr<CalleeAndThis> get_callee_and_this_from_environment(Bytecode::Interpreter&, DeprecatedFlyString const& name, u32 cache_index);
 ThrowCompletionOr<CalleeAndThis> get_callee_and_this_from_environment(Bytecode::Interpreter&, DeprecatedFlyString const& name, u32 cache_index);
 Value new_regexp(VM&, ParsedRegex const&, DeprecatedString const& pattern, DeprecatedString const& flags);
 Value new_regexp(VM&, ParsedRegex const&, DeprecatedString const& pattern, DeprecatedString const& flags);
+MarkedVector<Value> argument_list_evaluation(Bytecode::Interpreter&);
 
 
 }
 }

+ 0 - 27
Userland/Libraries/LibJS/Bytecode/Interpreter.cpp

@@ -1027,33 +1027,6 @@ ThrowCompletionOr<void> JumpUndefined::execute_impl(Bytecode::Interpreter&) cons
     __builtin_unreachable();
     __builtin_unreachable();
 }
 }
 
 
-// 13.3.8.1 https://tc39.es/ecma262/#sec-runtime-semantics-argumentlistevaluation
-static MarkedVector<Value> argument_list_evaluation(Bytecode::Interpreter& interpreter)
-{
-    // Note: Any spreading and actual evaluation is handled in preceding opcodes
-    // Note: The spec uses the concept of a list, while we create a temporary array
-    //       in the preceding opcodes, so we have to convert in a manner that is not
-    //       visible to the user
-    auto& vm = interpreter.vm();
-
-    MarkedVector<Value> argument_values { vm.heap() };
-    auto arguments = interpreter.accumulator();
-
-    auto& argument_array = arguments.as_array();
-    auto array_length = argument_array.indexed_properties().array_like_size();
-
-    argument_values.ensure_capacity(array_length);
-
-    for (size_t i = 0; i < array_length; ++i) {
-        if (auto maybe_value = argument_array.indexed_properties().get(i); maybe_value.has_value())
-            argument_values.append(maybe_value.release_value().value);
-        else
-            argument_values.append(js_undefined());
-    }
-
-    return argument_values;
-}
-
 ThrowCompletionOr<void> Call::execute_impl(Bytecode::Interpreter& interpreter) const
 ThrowCompletionOr<void> Call::execute_impl(Bytecode::Interpreter& interpreter) const
 {
 {
     auto& vm = interpreter.vm();
     auto& vm = interpreter.vm();

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

@@ -923,6 +923,25 @@ void Compiler::compile_call(Bytecode::Op::Call const& op)
     check_exception();
     check_exception();
 }
 }
 
 
+static Value cxx_call_with_argument_array(VM& vm, Value callee, Value this_value, Bytecode::Op::CallType call_type, Optional<Bytecode::StringTableIndex> const& expression_string)
+{
+    TRY_OR_SET_EXCEPTION(throw_if_needed_for_call(vm.bytecode_interpreter(), callee, call_type, expression_string));
+    auto argument_values = argument_list_evaluation(vm.bytecode_interpreter());
+    return TRY_OR_SET_EXCEPTION(perform_call(vm.bytecode_interpreter(), this_value, call_type, callee, move(argument_values)));
+}
+
+void Compiler::compile_call_with_argument_array(Bytecode::Op::CallWithArgumentArray const& op)
+{
+    load_vm_register(ARG1, op.callee());
+    load_vm_register(ARG2, op.this_value());
+    m_assembler.mov(
+        Assembler::Operand::Register(ARG3),
+        Assembler::Operand::Imm(to_underlying(op.call_type())));
+    native_call((void*)cxx_call_with_argument_array);
+    store_vm_register(Bytecode::Register::accumulator(), RET);
+    check_exception();
+}
+
 static Value cxx_typeof_variable(VM& vm, DeprecatedFlyString const& identifier)
 static Value cxx_typeof_variable(VM& vm, DeprecatedFlyString const& identifier)
 {
 {
     return TRY_OR_SET_EXCEPTION(Bytecode::typeof_variable(vm, identifier));
     return TRY_OR_SET_EXCEPTION(Bytecode::typeof_variable(vm, identifier));
@@ -1153,6 +1172,9 @@ OwnPtr<NativeExecutable> Compiler::compile(Bytecode::Executable& bytecode_execut
             case Bytecode::Instruction::Type::Call:
             case Bytecode::Instruction::Type::Call:
                 compiler.compile_call(static_cast<Bytecode::Op::Call const&>(op));
                 compiler.compile_call(static_cast<Bytecode::Op::Call const&>(op));
                 break;
                 break;
+            case Bytecode::Instruction::Type::CallWithArgumentArray:
+                compiler.compile_call_with_argument_array(static_cast<Bytecode::Op::CallWithArgumentArray const&>(op));
+                break;
             case Bytecode::Instruction::Type::TypeofVariable:
             case Bytecode::Instruction::Type::TypeofVariable:
                 compiler.compile_typeof_variable(static_cast<Bytecode::Op::TypeofVariable const&>(op));
                 compiler.compile_typeof_variable(static_cast<Bytecode::Op::TypeofVariable const&>(op));
                 break;
                 break;

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

@@ -111,6 +111,7 @@ private:
     void compile_put_by_value(Bytecode::Op::PutByValue const&);
     void compile_put_by_value(Bytecode::Op::PutByValue const&);
 
 
     void compile_call(Bytecode::Op::Call const&);
     void compile_call(Bytecode::Op::Call const&);
+    void compile_call_with_argument_array(Bytecode::Op::CallWithArgumentArray const&);
     void compile_typeof_variable(Bytecode::Op::TypeofVariable const&);
     void compile_typeof_variable(Bytecode::Op::TypeofVariable const&);
     void compile_set_variable(Bytecode::Op::SetVariable const&);
     void compile_set_variable(Bytecode::Op::SetVariable const&);
     void compile_continue_pending_unwind(Bytecode::Op::ContinuePendingUnwind const&);
     void compile_continue_pending_unwind(Bytecode::Op::ContinuePendingUnwind const&);