From 52fcaae71cb278c00f18247cf77a6a3c39ebf5df Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 6 Jun 2020 13:35:58 +0200 Subject: [PATCH] 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. --- Libraries/LibWeb/Bindings/LocationObject.cpp | 2 +- Libraries/LibWeb/DOM/Document.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Libraries/LibWeb/Bindings/LocationObject.cpp b/Libraries/LibWeb/Bindings/LocationObject.cpp index 7864f54efc..27dddc64d7 100644 --- a/Libraries/LibWeb/Bindings/LocationObject.cpp +++ b/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(interpreter.global_object()); - auto& url = window.impl().document().url(); + auto url = window.impl().document().url(); StringBuilder builder; builder.append(url.host()); builder.append(':'); diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h index 5ae6e1fb17..1b4172100f 100644 --- a/Libraries/LibWeb/DOM/Document.h +++ b/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;