Sfoglia il codice sorgente

LibJS+LibWeb: Fix some inconsistencies in NativeFunction callbacks

These should always pass the arguments in a const Vector<JS::Value>&.
Andreas Kling 5 anni fa
parent
commit
08b17d70af

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

@@ -42,7 +42,7 @@ private:
     virtual bool is_native_function() const override { return true; }
     virtual bool is_native_function() const override { return true; }
     virtual const char* class_name() const override { return "NativeFunction"; }
     virtual const char* class_name() const override { return "NativeFunction"; }
 
 
-    AK::Function<Value(Object*, Vector<Value>)> m_native_function;
+    AK::Function<Value(Object*, const Vector<Value>&)> m_native_function;
 };
 };
 
 
 }
 }

+ 1 - 1
Libraries/LibWeb/Bindings/DocumentWrapper.cpp

@@ -36,7 +36,7 @@ namespace Bindings {
 DocumentWrapper::DocumentWrapper(Document& document)
 DocumentWrapper::DocumentWrapper(Document& document)
     : NodeWrapper(document)
     : NodeWrapper(document)
 {
 {
-    put_native_function("getElementById", [this](JS::Object*, Vector<JS::Value> arguments) -> JS::Value {
+    put_native_function("getElementById", [this](JS::Object*, const Vector<JS::Value>& arguments) -> JS::Value {
         if (arguments.is_empty())
         if (arguments.is_empty())
             return JS::js_null();
             return JS::js_null();
         auto id = arguments[0].to_string();
         auto id = arguments[0].to_string();

+ 1 - 1
Libraries/LibWeb/DOM/Document.cpp

@@ -341,7 +341,7 @@ JS::Interpreter& Document::interpreter()
     if (!m_interpreter) {
     if (!m_interpreter) {
         m_interpreter = make<JS::Interpreter>();
         m_interpreter = make<JS::Interpreter>();
 
 
-        m_interpreter->global_object().put_native_function("alert", [](JS::Object*, Vector<JS::Value> arguments) -> JS::Value {
+        m_interpreter->global_object().put_native_function("alert", [](JS::Object*, const Vector<JS::Value>& arguments) -> JS::Value {
             if (arguments.size() < 1)
             if (arguments.size() < 1)
                 return JS::js_undefined();
                 return JS::js_undefined();
             GUI::MessageBox::show(arguments[0].to_string(), "Alert", GUI::MessageBox::Type::Information);
             GUI::MessageBox::show(arguments[0].to_string(), "Alert", GUI::MessageBox::Type::Information);