mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:28:12 +00:00
LibJS: Compile the CallWithArgumentArray bytecode instruction
This commit is contained in:
parent
2b65a80ecb
commit
b2d8d0c270
5 changed files with 52 additions and 27 deletions
|
@ -7,6 +7,7 @@
|
|||
#include <LibJS/Bytecode/CommonImplementations.h>
|
||||
#include <LibJS/Bytecode/Interpreter.h>
|
||||
#include <LibJS/Bytecode/Op.h>
|
||||
#include <LibJS/Runtime/Array.h>
|
||||
#include <LibJS/Runtime/DeclarativeEnvironment.h>
|
||||
#include <LibJS/Runtime/ECMAScriptFunctionObject.h>
|
||||
#include <LibJS/Runtime/GlobalEnvironment.h>
|
||||
|
@ -395,4 +396,31 @@ Value new_regexp(VM& vm, ParsedRegex const& parsed_regex, DeprecatedString const
|
|||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -31,5 +31,6 @@ struct CalleeAndThis {
|
|||
};
|
||||
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);
|
||||
MarkedVector<Value> argument_list_evaluation(Bytecode::Interpreter&);
|
||||
|
||||
}
|
||||
|
|
|
@ -1027,33 +1027,6 @@ ThrowCompletionOr<void> JumpUndefined::execute_impl(Bytecode::Interpreter&) cons
|
|||
__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
|
||||
{
|
||||
auto& vm = interpreter.vm();
|
||||
|
|
|
@ -923,6 +923,25 @@ void Compiler::compile_call(Bytecode::Op::Call const& op)
|
|||
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)
|
||||
{
|
||||
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:
|
||||
compiler.compile_call(static_cast<Bytecode::Op::Call const&>(op));
|
||||
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:
|
||||
compiler.compile_typeof_variable(static_cast<Bytecode::Op::TypeofVariable const&>(op));
|
||||
break;
|
||||
|
|
|
@ -111,6 +111,7 @@ private:
|
|||
void compile_put_by_value(Bytecode::Op::PutByValue 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_set_variable(Bytecode::Op::SetVariable const&);
|
||||
void compile_continue_pending_unwind(Bytecode::Op::ContinuePendingUnwind const&);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue