Explorar el Código

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.)
Andreas Kling hace 5 años
padre
commit
0a71533aff

+ 1 - 1
Libraries/LibJS/Runtime/ConsoleObject.cpp

@@ -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();

+ 1 - 1
Libraries/LibJS/Runtime/Function.h

@@ -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();

+ 3 - 3
Libraries/LibJS/Runtime/NativeFunction.cpp

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

+ 2 - 2
Libraries/LibJS/Runtime/NativeFunction.h

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

+ 1 - 1
Libraries/LibJS/Runtime/ObjectPrototype.cpp

@@ -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();

+ 2 - 2
Libraries/LibJS/Runtime/ScriptFunction.cpp

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

+ 1 - 1
Libraries/LibJS/Runtime/ScriptFunction.h

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

+ 2 - 2
Libraries/LibJS/Runtime/StringPrototype.cpp

@@ -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());