LibJS: Pass argument value vectors as const Vector<Value>&

Now that Interpreter keeps all arguments in the CallFrame stack, we can
just pass a const-reference to the CallFrame's argument vector to each
function handler (instead of copying it.)
This commit is contained in:
Andreas Kling 2020-03-17 16:24:53 +01:00
parent bf9912cc59
commit 0a71533aff
Notes: sideshowbarker 2024-07-19 08:16:19 +09:00
8 changed files with 13 additions and 13 deletions

View file

@ -32,7 +32,7 @@ namespace JS {
ConsoleObject::ConsoleObject()
{
put_native_function("log", [](Object*, Vector<Value> arguments) -> Value {
put_native_function("log", [](Object*, const Vector<Value>& arguments) -> Value {
for (auto& argument : arguments)
printf("%s ", argument.to_string().characters());
return js_undefined();

View file

@ -35,7 +35,7 @@ class Function : public Object {
public:
virtual ~Function();
virtual Value call(Interpreter&, Vector<Value>) = 0;
virtual Value call(Interpreter&, const Vector<Value>&) = 0;
protected:
Function();

View file

@ -30,7 +30,7 @@
namespace JS {
NativeFunction::NativeFunction(AK::Function<Value(Object*, Vector<Value>)> native_function)
NativeFunction::NativeFunction(AK::Function<Value(Object*, const Vector<Value>&)> native_function)
: m_native_function(move(native_function))
{
}
@ -39,11 +39,11 @@ NativeFunction::~NativeFunction()
{
}
Value NativeFunction::call(Interpreter& interpreter, Vector<Value> arguments)
Value NativeFunction::call(Interpreter& interpreter, const Vector<Value>& arguments)
{
auto this_value = interpreter.this_value();
ASSERT(this_value.is_object());
return m_native_function(this_value.as_object(), move(arguments));
return m_native_function(this_value.as_object(), arguments);
}
}

View file

@ -33,10 +33,10 @@ namespace JS {
class NativeFunction final : public Function {
public:
explicit NativeFunction(AK::Function<Value(Object*, Vector<Value>)>);
explicit NativeFunction(AK::Function<Value(Object*, const Vector<Value>&)>);
virtual ~NativeFunction() override;
virtual Value call(Interpreter&, Vector<Value>) override;
virtual Value call(Interpreter&, const Vector<Value>&) override;
private:
virtual bool is_native_function() const override { return true; }

View file

@ -37,7 +37,7 @@ ObjectPrototype::ObjectPrototype()
{
set_prototype(nullptr);
put_native_function("hasOwnProperty", [](Object* this_object, Vector<Value> arguments) -> Value {
put_native_function("hasOwnProperty", [](Object* this_object, const Vector<Value>& arguments) -> Value {
ASSERT(this_object);
if (arguments.is_empty())
return js_undefined();

View file

@ -40,7 +40,7 @@ ScriptFunction::~ScriptFunction()
{
}
Value ScriptFunction::call(Interpreter& interpreter, Vector<Value> argument_values)
Value ScriptFunction::call(Interpreter& interpreter, const Vector<Value>& argument_values)
{
Vector<Argument> arguments;
for (size_t i = 0; i < m_parameters.size(); ++i) {
@ -50,7 +50,7 @@ Value ScriptFunction::call(Interpreter& interpreter, Vector<Value> argument_valu
value = argument_values[i];
arguments.append({ move(name), move(value) });
}
return interpreter.run(m_body, move(arguments), ScopeType::Function);
return interpreter.run(m_body, arguments, ScopeType::Function);
}
}

View file

@ -38,7 +38,7 @@ public:
const ScopeNode& body() const { return m_body; }
const Vector<String>& parameters() const { return m_parameters; };
virtual Value call(Interpreter&, Vector<Value>) override;
virtual Value call(Interpreter&, const Vector<Value>&) override;
private:
virtual bool is_script_function() const final { return true; }

View file

@ -44,7 +44,7 @@ StringPrototype::StringPrototype()
return Value((i32) static_cast<const StringObject*>(this_object)->primitive_string()->string().length());
},
nullptr);
put_native_function("charAt", [](Object* this_object, Vector<Value> arguments) -> Value {
put_native_function("charAt", [](Object* this_object, const Vector<Value>& arguments) -> Value {
ASSERT(this_object);
i32 index = 0;
if (!arguments.is_empty())
@ -55,7 +55,7 @@ StringPrototype::StringPrototype()
return js_string(this_object->heap(), String::empty());
return js_string(this_object->heap(), underlying_string.substring(index, 1));
});
put_native_function("repeat", [](Object* this_object, Vector<Value> arguments) -> Value {
put_native_function("repeat", [](Object* this_object, const Vector<Value>& arguments) -> Value {
ASSERT(this_object->is_string_object());
if (arguments.is_empty())
return js_string(this_object->heap(), String::empty());