1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 19:45:07 +00:00

LibJS: Compile the CallWithArgumentArray bytecode instruction

This commit is contained in:
Idan Horowitz 2023-10-28 21:04:09 +03:00 committed by Andreas Kling
parent 2b65a80ecb
commit b2d8d0c270
5 changed files with 52 additions and 27 deletions

View file

@ -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;
}
}