diff --git a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp index 3996506c181dd4..d69f683e76ee97 100644 --- a/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp +++ b/Userland/Libraries/LibJS/Bytecode/Interpreter.cpp @@ -1329,7 +1329,7 @@ ThrowCompletionOr CreateVariable::execute_impl(Bytecode::Interpreter& inte ThrowCompletionOr CreateRestParams::execute_impl(Bytecode::Interpreter& interpreter) const { - auto const& arguments = interpreter.running_execution_context().arguments(); + auto const& arguments = interpreter.running_execution_context().arguments; auto arguments_count = interpreter.running_execution_context().passed_argument_count; auto array = MUST(Array::create(interpreter.realm(), 0)); for (size_t rest_index = m_rest_index; rest_index < arguments_count; ++rest_index) @@ -1341,7 +1341,7 @@ ThrowCompletionOr CreateRestParams::execute_impl(Bytecode::Interpreter& in ThrowCompletionOr CreateArguments::execute_impl(Bytecode::Interpreter& interpreter) const { auto const& function = interpreter.running_execution_context().function; - auto const& arguments = interpreter.running_execution_context().arguments(); + auto const& arguments = interpreter.running_execution_context().arguments; auto const& environment = interpreter.running_execution_context().lexical_environment; auto passed_arguments = ReadonlySpan { arguments.data(), interpreter.running_execution_context().passed_argument_count }; diff --git a/Userland/Libraries/LibJS/Runtime/AsyncFunctionConstructor.cpp b/Userland/Libraries/LibJS/Runtime/AsyncFunctionConstructor.cpp index 08bd44dc8527d1..7766fbae1b17da 100644 --- a/Userland/Libraries/LibJS/Runtime/AsyncFunctionConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/AsyncFunctionConstructor.cpp @@ -46,7 +46,7 @@ ThrowCompletionOr> AsyncFunctionConstructor::construct(Func // 2. Let args be the argumentsList that was passed to this function by [[Call]] or [[Construct]]. MarkedVector args(heap()); - for (auto argument : vm.running_execution_context().arguments()) + for (auto argument : vm.running_execution_context().arguments) args.append(argument); // 3. Return CreateDynamicFunction(C, NewTarget, async, args). diff --git a/Userland/Libraries/LibJS/Runtime/AsyncGeneratorFunctionConstructor.cpp b/Userland/Libraries/LibJS/Runtime/AsyncGeneratorFunctionConstructor.cpp index 6dfab3cc1c712b..e52b12820fec71 100644 --- a/Userland/Libraries/LibJS/Runtime/AsyncGeneratorFunctionConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/AsyncGeneratorFunctionConstructor.cpp @@ -47,7 +47,7 @@ ThrowCompletionOr> AsyncGeneratorFunctionConstructor::const // 2. Let args be the argumentsList that was passed to this function by [[Call]] or [[Construct]]. MarkedVector args(heap()); - for (auto argument : vm.running_execution_context().arguments()) + for (auto argument : vm.running_execution_context().arguments) args.append(argument); // 3. Return ? CreateDynamicFunction(C, NewTarget, asyncGenerator, args). diff --git a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp index f40832f526d41b..89483a78392369 100644 --- a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.cpp @@ -827,7 +827,7 @@ Completion ECMAScriptFunctionObject::ordinary_call_evaluate_body(ReadonlySpannumber_of_registers + m_bytecode_executable->constants.size(); - vm.running_execution_context().registers_and_constants_and_locals_count = registers_and_constants_and_locals_count; + // vm.running_execution_context().registers_and_constants_and_locals_count = registers_and_constants_and_locals_count; auto& registers_constants_locals_and_arguments = vm.running_execution_context().registers_constants_locals_and_arguments; registers_constants_locals_and_arguments.resize(registers_and_constants_and_locals_count + arguments_size); @@ -839,6 +839,8 @@ Completion ECMAScriptFunctionObject::ordinary_call_evaluate_body(ReadonlySpan ExecutionContext::copy() const copy->is_strict_mode = is_strict_mode; copy->executable = executable; copy->passed_argument_count = passed_argument_count; - copy->registers_and_constants_and_locals_count = registers_and_constants_and_locals_count; copy->registers_constants_locals_and_arguments = registers_constants_locals_and_arguments; + copy->arguments = { copy->registers_constants_locals_and_arguments.data(), arguments.size() }; copy->unwind_contexts = unwind_contexts; copy->saved_lexical_environments = saved_lexical_environments; copy->previously_scheduled_jumps = previously_scheduled_jumps; diff --git a/Userland/Libraries/LibJS/Runtime/ExecutionContext.h b/Userland/Libraries/LibJS/Runtime/ExecutionContext.h index 2bd4c4f767c3df..c5cec1ed8c6b73 100644 --- a/Userland/Libraries/LibJS/Runtime/ExecutionContext.h +++ b/Userland/Libraries/LibJS/Runtime/ExecutionContext.h @@ -63,9 +63,9 @@ struct ExecutionContext { Value argument(size_t index) const { - if (index >= registers_constants_locals_and_arguments.size()) [[unlikely]] + if (index >= arguments.size()) [[unlikely]] return js_undefined(); - return registers_constants_locals_and_arguments[registers_and_constants_and_locals_count + index]; + return arguments[index]; } Value& local(size_t index) @@ -73,11 +73,10 @@ struct ExecutionContext { return registers_constants_locals_and_arguments[index]; } - u32 registers_and_constants_and_locals_count { 0 }; + // u32 registers_and_constants_and_locals_count { 0 }; u32 passed_argument_count { 0 }; - Span arguments() { return registers_constants_locals_and_arguments.span().slice(registers_and_constants_and_locals_count); } - ReadonlySpan arguments() const { return registers_constants_locals_and_arguments.span().slice(registers_and_constants_and_locals_count); } + Span arguments; Vector registers_constants_locals_and_arguments; Vector unwind_contexts; diff --git a/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp b/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp index 46414363d88e42..bf53edc1a03d00 100644 --- a/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/FunctionConstructor.cpp @@ -270,7 +270,7 @@ ThrowCompletionOr> FunctionConstructor::construct(FunctionO // 2. Let args be the argumentsList that was passed to this function by [[Call]] or [[Construct]]. MarkedVector args(heap()); - for (auto argument : vm.running_execution_context().arguments()) + for (auto argument : vm.running_execution_context().arguments) args.append(argument); // 3. Return ? CreateDynamicFunction(C, NewTarget, normal, args). diff --git a/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp b/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp index 8efe151acd016c..954d41796e996e 100644 --- a/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/FunctionPrototype.cpp @@ -98,7 +98,7 @@ JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::bind) Vector arguments; if (vm.argument_count() > 1) { - arguments.append(vm.running_execution_context().arguments().slice(1).data(), vm.argument_count() - 1); + arguments.append(vm.running_execution_context().arguments.slice(1).data(), vm.argument_count() - 1); } // 3. Let F be ? BoundFunctionCreate(Target, thisArg, args). @@ -129,7 +129,7 @@ JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::call) // FIXME: 3. Perform PrepareForTailCall(). auto this_arg = vm.argument(0); - auto args = vm.argument_count() > 1 ? vm.running_execution_context().arguments().slice(1) : ReadonlySpan {}; + auto args = vm.argument_count() > 1 ? vm.running_execution_context().arguments.slice(1) : ReadonlySpan {}; // 4. Return ? Call(func, thisArg, args). return TRY(JS::call(vm, function, this_arg, args)); diff --git a/Userland/Libraries/LibJS/Runtime/GeneratorFunctionConstructor.cpp b/Userland/Libraries/LibJS/Runtime/GeneratorFunctionConstructor.cpp index 6d9dae6fe2a7c2..1bea1bd0e1dbbe 100644 --- a/Userland/Libraries/LibJS/Runtime/GeneratorFunctionConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/GeneratorFunctionConstructor.cpp @@ -45,7 +45,7 @@ ThrowCompletionOr> GeneratorFunctionConstructor::construct( // 2. Let args be the argumentsList that was passed to this function by [[Call]] or [[Construct]]. MarkedVector args(heap()); - for (auto argument : vm.running_execution_context().arguments()) + for (auto argument : vm.running_execution_context().arguments) args.append(argument); // 3. Return ? CreateDynamicFunction(C, NewTarget, generator, args). diff --git a/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp b/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp index 032d4b82809ac3..c4ee09405248d7 100644 --- a/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp +++ b/Userland/Libraries/LibJS/Runtime/NativeFunction.cpp @@ -146,8 +146,9 @@ ThrowCompletionOr NativeFunction::internal_call(Value this_argument, Read // 8. Perform any necessary implementation-defined initialization of calleeContext. callee_context->this_value = this_argument; - callee_context->registers_and_constants_and_locals_count = 0; + // callee_context->registers_and_constants_and_locals_count = 0; callee_context->registers_constants_locals_and_arguments.append(arguments_list.data(), arguments_list.size()); + callee_context->arguments = callee_context->registers_constants_locals_and_arguments.span(); callee_context->program_counter = vm.bytecode_interpreter().program_counter(); callee_context->lexical_environment = caller_context.lexical_environment; @@ -210,8 +211,9 @@ ThrowCompletionOr> NativeFunction::internal_construct(Reado // Note: This is already the default value. // 8. Perform any necessary implementation-defined initialization of calleeContext. - callee_context->registers_and_constants_and_locals_count = 0; + // callee_context->registers_and_constants_and_locals_count = 0; callee_context->registers_constants_locals_and_arguments.append(arguments_list.data(), arguments_list.size()); + callee_context->arguments = callee_context->registers_constants_locals_and_arguments.span(); callee_context->program_counter = vm.bytecode_interpreter().program_counter(); callee_context->lexical_environment = caller_context.lexical_environment; diff --git a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp index 1ee26725280aa1..460d3abf9a0354 100644 --- a/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp +++ b/Userland/Libraries/LibJS/Runtime/PromiseConstructor.cpp @@ -465,7 +465,7 @@ JS_DEFINE_NATIVE_FUNCTION(PromiseConstructor::try_) auto callbackfn = vm.argument(0); Span args; if (vm.argument_count() > 1) { - args = vm.running_execution_context().arguments().slice(1, vm.argument_count() - 1); + args = vm.running_execution_context().arguments.slice(1, vm.argument_count() - 1); } // 1. Let C be the this value. diff --git a/Userland/Libraries/LibJS/Runtime/VM.h b/Userland/Libraries/LibJS/Runtime/VM.h index 85050239882c1e..a9aa1b08ae9ee8 100644 --- a/Userland/Libraries/LibJS/Runtime/VM.h +++ b/Userland/Libraries/LibJS/Runtime/VM.h @@ -160,7 +160,7 @@ class VM : public RefCounted { { if (m_execution_context_stack.is_empty()) return 0; - return running_execution_context().arguments().size(); + return running_execution_context().arguments.size(); } Value argument(size_t index) const