From 90cdeebfb3589bceb2a269a1725199e384fb4f74 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 9 Sep 2021 13:55:31 +0200 Subject: [PATCH] LibWeb: Rename DOM::Window::document() => associated_document() Match the spec nomenclature. --- .../LibWeb/Bindings/ImageConstructor.cpp | 2 +- .../LibWeb/Bindings/LocationObject.cpp | 16 +++++++-------- .../LibWeb/Bindings/WindowObject.cpp | 8 ++++---- .../Libraries/LibWeb/DOM/AbortController.h | 2 +- Userland/Libraries/LibWeb/DOM/AbortSignal.h | 2 +- Userland/Libraries/LibWeb/DOM/Comment.cpp | 2 +- .../Libraries/LibWeb/DOM/DocumentFragment.cpp | 2 +- .../Libraries/LibWeb/DOM/EventDispatcher.cpp | 2 +- Userland/Libraries/LibWeb/DOM/Range.cpp | 2 +- Userland/Libraries/LibWeb/DOM/Text.cpp | 2 +- Userland/Libraries/LibWeb/DOM/Window.cpp | 20 +++++++++---------- Userland/Libraries/LibWeb/DOM/Window.h | 8 +++++--- Userland/Libraries/LibWeb/HTML/WebSocket.cpp | 2 +- .../LibWeb/HighResolutionTime/Performance.cpp | 2 +- .../Libraries/LibWeb/XHR/XMLHttpRequest.cpp | 12 +++++------ .../WebContent/ConsoleGlobalObject.cpp | 2 +- 16 files changed, 44 insertions(+), 42 deletions(-) diff --git a/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp b/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp index adf4deba975..46ec3ffaebb 100644 --- a/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp +++ b/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp @@ -43,7 +43,7 @@ JS::Value ImageConstructor::call() JS::Value ImageConstructor::construct(FunctionObject&) { auto& window = static_cast(global_object()); - auto& document = window.impl().document(); + auto& document = window.impl().associated_document(); auto image_element = DOM::create_element(document, HTML::TagNames::img, Namespace::HTML); if (vm().argument_count() > 0) { diff --git a/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp b/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp index 227a6aebee8..1d819baa44f 100644 --- a/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp +++ b/Userland/Libraries/LibWeb/Bindings/LocationObject.cpp @@ -41,7 +41,7 @@ LocationObject::~LocationObject() JS_DEFINE_NATIVE_FUNCTION(LocationObject::href_getter) { auto& window = static_cast(global_object); - return JS::js_string(vm, window.impl().document().url().to_string()); + return JS::js_string(vm, window.impl().associated_document().url().to_string()); } JS_DEFINE_NATIVE_FUNCTION(LocationObject::href_setter) @@ -50,7 +50,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::href_setter) auto new_href = vm.argument(0).to_string(global_object); if (vm.exception()) return {}; - auto href_url = window.impl().document().complete_url(new_href); + auto href_url = window.impl().associated_document().complete_url(new_href); if (!href_url.is_valid()) { vm.throw_exception(global_object, String::formatted("Invalid URL '{}'", new_href)); return {}; @@ -62,26 +62,26 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::href_setter) JS_DEFINE_NATIVE_FUNCTION(LocationObject::pathname_getter) { auto& window = static_cast(global_object); - return JS::js_string(vm, window.impl().document().url().path()); + return JS::js_string(vm, window.impl().associated_document().url().path()); } JS_DEFINE_NATIVE_FUNCTION(LocationObject::hostname_getter) { auto& window = static_cast(global_object); - return JS::js_string(vm, window.impl().document().url().host()); + return JS::js_string(vm, window.impl().associated_document().url().host()); } JS_DEFINE_NATIVE_FUNCTION(LocationObject::host_getter) { auto& window = static_cast(global_object); - auto url = window.impl().document().url(); + auto url = window.impl().associated_document().url(); return JS::js_string(vm, String::formatted("{}:{}", url.host(), url.port())); } JS_DEFINE_NATIVE_FUNCTION(LocationObject::hash_getter) { auto& window = static_cast(global_object); - auto fragment = window.impl().document().url().fragment(); + auto fragment = window.impl().associated_document().url().fragment(); if (!fragment.length()) return JS::js_string(vm, ""); StringBuilder builder; @@ -93,7 +93,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::hash_getter) JS_DEFINE_NATIVE_FUNCTION(LocationObject::search_getter) { auto& window = static_cast(global_object); - auto query = window.impl().document().url().query(); + auto query = window.impl().associated_document().url().query(); if (!query.length()) return JS::js_string(vm, ""); StringBuilder builder; @@ -106,7 +106,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::protocol_getter) { auto& window = static_cast(global_object); StringBuilder builder; - builder.append(window.impl().document().url().protocol()); + builder.append(window.impl().associated_document().url().protocol()); builder.append(':'); return JS::js_string(vm, builder.to_string()); } diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp b/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp index 1cf8b287f40..c0cdd3234bd 100644 --- a/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp +++ b/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp @@ -97,7 +97,7 @@ void WindowObject::visit_edges(Visitor& visitor) Origin WindowObject::origin() const { - return impl().document().origin(); + return impl().associated_document().origin(); } static DOM::Window* impl_from(JS::VM& vm, JS::GlobalObject& global_object) @@ -358,7 +358,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::top_getter) if (!impl) return {}; - auto* this_browsing_context = impl->document().browsing_context(); + auto* this_browsing_context = impl->associated_document().browsing_context(); if (!this_browsing_context) return JS::js_null(); @@ -374,7 +374,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::parent_getter) if (!impl) return {}; - auto* this_browsing_context = impl->document().browsing_context(); + auto* this_browsing_context = impl->associated_document().browsing_context(); if (!this_browsing_context) return JS::js_null(); @@ -392,7 +392,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::document_getter) auto* impl = impl_from(vm, global_object); if (!impl) return {}; - return wrap(global_object, impl->document()); + return wrap(global_object, impl->associated_document()); } JS_DEFINE_NATIVE_FUNCTION(WindowObject::performance_getter) diff --git a/Userland/Libraries/LibWeb/DOM/AbortController.h b/Userland/Libraries/LibWeb/DOM/AbortController.h index 3e9d919978c..c8b4a158663 100644 --- a/Userland/Libraries/LibWeb/DOM/AbortController.h +++ b/Userland/Libraries/LibWeb/DOM/AbortController.h @@ -31,7 +31,7 @@ public: static NonnullRefPtr create_with_global_object(Bindings::WindowObject& window_object) { - return AbortController::create(window_object.impl().document()); + return AbortController::create(window_object.impl().associated_document()); } virtual ~AbortController() override; diff --git a/Userland/Libraries/LibWeb/DOM/AbortSignal.h b/Userland/Libraries/LibWeb/DOM/AbortSignal.h index 273d28981ab..f468eb079ee 100644 --- a/Userland/Libraries/LibWeb/DOM/AbortSignal.h +++ b/Userland/Libraries/LibWeb/DOM/AbortSignal.h @@ -34,7 +34,7 @@ public: static NonnullRefPtr create_with_global_object(Bindings::WindowObject& window_object) { - return AbortSignal::create(window_object.impl().document()); + return AbortSignal::create(window_object.impl().associated_document()); } virtual ~AbortSignal() override; diff --git a/Userland/Libraries/LibWeb/DOM/Comment.cpp b/Userland/Libraries/LibWeb/DOM/Comment.cpp index 2d7bcb8fea7..77abdb9b162 100644 --- a/Userland/Libraries/LibWeb/DOM/Comment.cpp +++ b/Userland/Libraries/LibWeb/DOM/Comment.cpp @@ -22,7 +22,7 @@ Comment::~Comment() // https://dom.spec.whatwg.org/#dom-comment-comment NonnullRefPtr Comment::create_with_global_object(Bindings::WindowObject& window, String const& data) { - return make_ref_counted(window.impl().document(), data); + return make_ref_counted(window.impl().associated_document(), data); } } diff --git a/Userland/Libraries/LibWeb/DOM/DocumentFragment.cpp b/Userland/Libraries/LibWeb/DOM/DocumentFragment.cpp index 50a5aabd864..a9ac6833f26 100644 --- a/Userland/Libraries/LibWeb/DOM/DocumentFragment.cpp +++ b/Userland/Libraries/LibWeb/DOM/DocumentFragment.cpp @@ -21,7 +21,7 @@ DocumentFragment::~DocumentFragment() // https://dom.spec.whatwg.org/#dom-documentfragment-documentfragment NonnullRefPtr DocumentFragment::create_with_global_object(Bindings::WindowObject& window) { - return make_ref_counted(window.impl().document()); + return make_ref_counted(window.impl().associated_document()); } } diff --git a/Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp b/Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp index 9b62ebcd1e9..b7dba26c5de 100644 --- a/Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp +++ b/Userland/Libraries/LibWeb/DOM/EventDispatcher.cpp @@ -162,7 +162,7 @@ bool EventDispatcher::dispatch(NonnullRefPtr target, NonnullRefPtr< target_override = target; } else { // NOTE: This can be done because legacy_target_override is only set for events targeted at Window. - target_override = verify_cast(*target).document(); + target_override = verify_cast(*target).associated_document(); } RefPtr activation_target; diff --git a/Userland/Libraries/LibWeb/DOM/Range.cpp b/Userland/Libraries/LibWeb/DOM/Range.cpp index 3125a41b984..40af4a14442 100644 --- a/Userland/Libraries/LibWeb/DOM/Range.cpp +++ b/Userland/Libraries/LibWeb/DOM/Range.cpp @@ -13,7 +13,7 @@ namespace Web::DOM { NonnullRefPtr Range::create(Window& window) { - return Range::create(window.document()); + return Range::create(window.associated_document()); } NonnullRefPtr Range::create(Document& document) diff --git a/Userland/Libraries/LibWeb/DOM/Text.cpp b/Userland/Libraries/LibWeb/DOM/Text.cpp index 6fa80992d29..b724891b848 100644 --- a/Userland/Libraries/LibWeb/DOM/Text.cpp +++ b/Userland/Libraries/LibWeb/DOM/Text.cpp @@ -27,7 +27,7 @@ RefPtr Text::create_layout_node() // https://dom.spec.whatwg.org/#dom-text-text NonnullRefPtr Text::create_with_global_object(Bindings::WindowObject& window, String const& data) { - return make_ref_counted(window.impl().document(), data); + return make_ref_counted(window.impl().associated_document(), data); } } diff --git a/Userland/Libraries/LibWeb/DOM/Window.cpp b/Userland/Libraries/LibWeb/DOM/Window.cpp index 52a7f7f8754..a787da2e1cf 100644 --- a/Userland/Libraries/LibWeb/DOM/Window.cpp +++ b/Userland/Libraries/LibWeb/DOM/Window.cpp @@ -25,7 +25,7 @@ NonnullRefPtr Window::create_with_document(Document& document) Window::Window(Document& document) : EventTarget(static_cast(document)) - , m_document(document) + , m_associated_document(document) , m_performance(make(*this)) , m_screen(CSS::Screen::create(*this)) { @@ -139,7 +139,7 @@ void Window::cancel_animation_frame(i32 id) void Window::did_set_location_href(Badge, URL const& new_href) { - auto* frame = document().browsing_context(); + auto* frame = associated_document().browsing_context(); if (!frame) return; frame->loader().load(new_href, FrameLoader::Type::Navigation); @@ -147,10 +147,10 @@ void Window::did_set_location_href(Badge, URL const& n void Window::did_call_location_reload(Badge) { - auto* frame = document().browsing_context(); + auto* frame = associated_document().browsing_context(); if (!frame) return; - frame->loader().load(document().url(), FrameLoader::Type::Reload); + frame->loader().load(associated_document().url(), FrameLoader::Type::Reload); } bool Window::dispatch_event(NonnullRefPtr event) @@ -165,26 +165,26 @@ JS::Object* Window::create_wrapper(JS::GlobalObject& global_object) int Window::inner_width() const { - if (!document().layout_node()) + if (!associated_document().layout_node()) return 0; - return document().layout_node()->width(); + return associated_document().layout_node()->width(); } int Window::inner_height() const { - if (!document().layout_node()) + if (!associated_document().layout_node()) return 0; - return document().layout_node()->height(); + return associated_document().layout_node()->height(); } Page* Window::page() { - return document().page(); + return associated_document().page(); } Page const* Window::page() const { - return document().page(); + return associated_document().page(); } } diff --git a/Userland/Libraries/LibWeb/DOM/Window.h b/Userland/Libraries/LibWeb/DOM/Window.h index 054ed289b2e..67e742f2a17 100644 --- a/Userland/Libraries/LibWeb/DOM/Window.h +++ b/Userland/Libraries/LibWeb/DOM/Window.h @@ -36,8 +36,8 @@ public: Page* page(); Page const* page() const; - Document const& document() const { return m_document; } - Document& document() { return m_document; } + Document const& associated_document() const { return m_associated_document; } + Document& associated_document() { return m_associated_document; } void alert(String const&); bool confirm(String const&); @@ -75,7 +75,9 @@ public: private: explicit Window(Document&); - Document& m_document; + // https://html.spec.whatwg.org/multipage/window-object.html#concept-document-window + Document& m_associated_document; + WeakPtr m_wrapper; IDAllocator m_timer_id_allocator; diff --git a/Userland/Libraries/LibWeb/HTML/WebSocket.cpp b/Userland/Libraries/LibWeb/HTML/WebSocket.cpp index f1c7164ea22..59067e865ac 100644 --- a/Userland/Libraries/LibWeb/HTML/WebSocket.cpp +++ b/Userland/Libraries/LibWeb/HTML/WebSocket.cpp @@ -62,7 +62,7 @@ DOM::ExceptionOr> WebSocket::create_with_global_object( } WebSocket::WebSocket(DOM::Window& window, URL& url) - : EventTarget(static_cast(window.document())) + : EventTarget(static_cast(window.associated_document())) , m_window(window) { // FIXME: Integrate properly with FETCH as per https://fetch.spec.whatwg.org/#websocket-opening-handshake diff --git a/Userland/Libraries/LibWeb/HighResolutionTime/Performance.cpp b/Userland/Libraries/LibWeb/HighResolutionTime/Performance.cpp index 86a7036a131..436e647a0e3 100644 --- a/Userland/Libraries/LibWeb/HighResolutionTime/Performance.cpp +++ b/Userland/Libraries/LibWeb/HighResolutionTime/Performance.cpp @@ -14,7 +14,7 @@ namespace Web::HighResolutionTime { Performance::Performance(DOM::Window& window) - : DOM::EventTarget(static_cast(window.document())) + : DOM::EventTarget(static_cast(window.associated_document())) , m_window(window) , m_timing(make(window)) { diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp index 021e988002f..2261f58a099 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp @@ -25,7 +25,7 @@ namespace Web::XHR { XMLHttpRequest::XMLHttpRequest(DOM::Window& window) - : XMLHttpRequestEventTarget(static_cast(window.document())) + : XMLHttpRequestEventTarget(static_cast(window.associated_document())) , m_window(window) { } @@ -119,7 +119,7 @@ DOM::ExceptionOr XMLHttpRequest::open(const String& method, const String& auto normalized_method = normalize_method(method); - auto parsed_url = m_window->document().complete_url(url); + auto parsed_url = m_window->associated_document().complete_url(url); if (!parsed_url.is_valid()) return DOM::SyntaxError::create("Invalid URL"); @@ -166,14 +166,14 @@ DOM::ExceptionOr XMLHttpRequest::send() // FIXME: If body is not null, then: - URL request_url = m_window->document().complete_url(m_url.to_string()); - dbgln("XHR send from {} to {}", m_window->document().url(), request_url); + URL request_url = m_window->associated_document().complete_url(m_url.to_string()); + dbgln("XHR send from {} to {}", m_window->associated_document().url(), request_url); // TODO: Add support for preflight requests to support CORS requests Origin request_url_origin = Origin(request_url.protocol(), request_url.host(), request_url.port()); - if (!m_window->document().origin().is_same(request_url_origin)) { - dbgln("XHR failed to load: Same-Origin Policy violation: {} may not load {}", m_window->document().url(), request_url); + if (!m_window->associated_document().origin().is_same(request_url_origin)) { + dbgln("XHR failed to load: Same-Origin Policy violation: {} may not load {}", m_window->associated_document().url(), request_url); auto weak_this = make_weak_ptr(); if (!weak_this) return {}; diff --git a/Userland/Services/WebContent/ConsoleGlobalObject.cpp b/Userland/Services/WebContent/ConsoleGlobalObject.cpp index 16510052829..f1c0af4a349 100644 --- a/Userland/Services/WebContent/ConsoleGlobalObject.cpp +++ b/Userland/Services/WebContent/ConsoleGlobalObject.cpp @@ -110,7 +110,7 @@ JS_DEFINE_NATIVE_GETTER(ConsoleGlobalObject::inspected_node_getter) auto console_global_object = static_cast(this_object); auto& window = console_global_object->m_window_object->impl(); - auto* inspected_node = window.document().inspected_node(); + auto* inspected_node = window.associated_document().inspected_node(); if (!inspected_node) return JS::js_undefined();