Ver Fonte

LibWeb: Make Document::url() return URL by value

Returning it by reference can lead to unpleasant situations if we use
this getter when the document may go away. Better to make the getter
return a copy than have to think about this everywhere.
Andreas Kling há 5 anos atrás
pai
commit
52fcaae71c

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

@@ -84,7 +84,7 @@ JS::Value LocationObject::hostname_getter(JS::Interpreter& interpreter)
 JS::Value LocationObject::host_getter(JS::Interpreter& interpreter)
 {
     auto& window = static_cast<WindowObject&>(interpreter.global_object());
-    auto& url = window.impl().document().url();
+    auto url = window.impl().document().url();
     StringBuilder builder;
     builder.append(url.host());
     builder.append(':');

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

@@ -53,7 +53,7 @@ public:
     virtual ~Document() override;
 
     void set_url(const URL& url) { m_url = url; }
-    const URL& url() const { return m_url; }
+    URL url() const { return m_url; }
 
     Origin origin() const;