1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 03:07:43 +00:00

LibWeb: Rename DOM::Window::document() => associated_document()

Match the spec nomenclature.
This commit is contained in:
Andreas Kling 2021-09-09 13:55:31 +02:00
parent 8f72729f0e
commit 90cdeebfb3
16 changed files with 44 additions and 42 deletions

View file

@ -43,7 +43,7 @@ JS::Value ImageConstructor::call()
JS::Value ImageConstructor::construct(FunctionObject&) JS::Value ImageConstructor::construct(FunctionObject&)
{ {
auto& window = static_cast<WindowObject&>(global_object()); auto& window = static_cast<WindowObject&>(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); auto image_element = DOM::create_element(document, HTML::TagNames::img, Namespace::HTML);
if (vm().argument_count() > 0) { if (vm().argument_count() > 0) {

View file

@ -41,7 +41,7 @@ LocationObject::~LocationObject()
JS_DEFINE_NATIVE_FUNCTION(LocationObject::href_getter) JS_DEFINE_NATIVE_FUNCTION(LocationObject::href_getter)
{ {
auto& window = static_cast<WindowObject&>(global_object); auto& window = static_cast<WindowObject&>(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) 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); auto new_href = vm.argument(0).to_string(global_object);
if (vm.exception()) if (vm.exception())
return {}; 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()) { if (!href_url.is_valid()) {
vm.throw_exception<JS::URIError>(global_object, String::formatted("Invalid URL '{}'", new_href)); vm.throw_exception<JS::URIError>(global_object, String::formatted("Invalid URL '{}'", new_href));
return {}; return {};
@ -62,26 +62,26 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::href_setter)
JS_DEFINE_NATIVE_FUNCTION(LocationObject::pathname_getter) JS_DEFINE_NATIVE_FUNCTION(LocationObject::pathname_getter)
{ {
auto& window = static_cast<WindowObject&>(global_object); auto& window = static_cast<WindowObject&>(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) JS_DEFINE_NATIVE_FUNCTION(LocationObject::hostname_getter)
{ {
auto& window = static_cast<WindowObject&>(global_object); auto& window = static_cast<WindowObject&>(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) JS_DEFINE_NATIVE_FUNCTION(LocationObject::host_getter)
{ {
auto& window = static_cast<WindowObject&>(global_object); auto& window = static_cast<WindowObject&>(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())); return JS::js_string(vm, String::formatted("{}:{}", url.host(), url.port()));
} }
JS_DEFINE_NATIVE_FUNCTION(LocationObject::hash_getter) JS_DEFINE_NATIVE_FUNCTION(LocationObject::hash_getter)
{ {
auto& window = static_cast<WindowObject&>(global_object); auto& window = static_cast<WindowObject&>(global_object);
auto fragment = window.impl().document().url().fragment(); auto fragment = window.impl().associated_document().url().fragment();
if (!fragment.length()) if (!fragment.length())
return JS::js_string(vm, ""); return JS::js_string(vm, "");
StringBuilder builder; StringBuilder builder;
@ -93,7 +93,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::hash_getter)
JS_DEFINE_NATIVE_FUNCTION(LocationObject::search_getter) JS_DEFINE_NATIVE_FUNCTION(LocationObject::search_getter)
{ {
auto& window = static_cast<WindowObject&>(global_object); auto& window = static_cast<WindowObject&>(global_object);
auto query = window.impl().document().url().query(); auto query = window.impl().associated_document().url().query();
if (!query.length()) if (!query.length())
return JS::js_string(vm, ""); return JS::js_string(vm, "");
StringBuilder builder; StringBuilder builder;
@ -106,7 +106,7 @@ JS_DEFINE_NATIVE_FUNCTION(LocationObject::protocol_getter)
{ {
auto& window = static_cast<WindowObject&>(global_object); auto& window = static_cast<WindowObject&>(global_object);
StringBuilder builder; StringBuilder builder;
builder.append(window.impl().document().url().protocol()); builder.append(window.impl().associated_document().url().protocol());
builder.append(':'); builder.append(':');
return JS::js_string(vm, builder.to_string()); return JS::js_string(vm, builder.to_string());
} }

View file

@ -97,7 +97,7 @@ void WindowObject::visit_edges(Visitor& visitor)
Origin WindowObject::origin() const 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) 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) if (!impl)
return {}; return {};
auto* this_browsing_context = impl->document().browsing_context(); auto* this_browsing_context = impl->associated_document().browsing_context();
if (!this_browsing_context) if (!this_browsing_context)
return JS::js_null(); return JS::js_null();
@ -374,7 +374,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::parent_getter)
if (!impl) if (!impl)
return {}; return {};
auto* this_browsing_context = impl->document().browsing_context(); auto* this_browsing_context = impl->associated_document().browsing_context();
if (!this_browsing_context) if (!this_browsing_context)
return JS::js_null(); return JS::js_null();
@ -392,7 +392,7 @@ JS_DEFINE_NATIVE_FUNCTION(WindowObject::document_getter)
auto* impl = impl_from(vm, global_object); auto* impl = impl_from(vm, global_object);
if (!impl) if (!impl)
return {}; return {};
return wrap(global_object, impl->document()); return wrap(global_object, impl->associated_document());
} }
JS_DEFINE_NATIVE_FUNCTION(WindowObject::performance_getter) JS_DEFINE_NATIVE_FUNCTION(WindowObject::performance_getter)

View file

@ -31,7 +31,7 @@ public:
static NonnullRefPtr<AbortController> create_with_global_object(Bindings::WindowObject& window_object) static NonnullRefPtr<AbortController> 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; virtual ~AbortController() override;

View file

@ -34,7 +34,7 @@ public:
static NonnullRefPtr<AbortSignal> create_with_global_object(Bindings::WindowObject& window_object) static NonnullRefPtr<AbortSignal> 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; virtual ~AbortSignal() override;

View file

@ -22,7 +22,7 @@ Comment::~Comment()
// https://dom.spec.whatwg.org/#dom-comment-comment // https://dom.spec.whatwg.org/#dom-comment-comment
NonnullRefPtr<Comment> Comment::create_with_global_object(Bindings::WindowObject& window, String const& data) NonnullRefPtr<Comment> Comment::create_with_global_object(Bindings::WindowObject& window, String const& data)
{ {
return make_ref_counted<Comment>(window.impl().document(), data); return make_ref_counted<Comment>(window.impl().associated_document(), data);
} }
} }

View file

@ -21,7 +21,7 @@ DocumentFragment::~DocumentFragment()
// https://dom.spec.whatwg.org/#dom-documentfragment-documentfragment // https://dom.spec.whatwg.org/#dom-documentfragment-documentfragment
NonnullRefPtr<DocumentFragment> DocumentFragment::create_with_global_object(Bindings::WindowObject& window) NonnullRefPtr<DocumentFragment> DocumentFragment::create_with_global_object(Bindings::WindowObject& window)
{ {
return make_ref_counted<DocumentFragment>(window.impl().document()); return make_ref_counted<DocumentFragment>(window.impl().associated_document());
} }
} }

View file

@ -162,7 +162,7 @@ bool EventDispatcher::dispatch(NonnullRefPtr<EventTarget> target, NonnullRefPtr<
target_override = target; target_override = target;
} else { } else {
// NOTE: This can be done because legacy_target_override is only set for events targeted at Window. // NOTE: This can be done because legacy_target_override is only set for events targeted at Window.
target_override = verify_cast<Window>(*target).document(); target_override = verify_cast<Window>(*target).associated_document();
} }
RefPtr<EventTarget> activation_target; RefPtr<EventTarget> activation_target;

View file

@ -13,7 +13,7 @@ namespace Web::DOM {
NonnullRefPtr<Range> Range::create(Window& window) NonnullRefPtr<Range> Range::create(Window& window)
{ {
return Range::create(window.document()); return Range::create(window.associated_document());
} }
NonnullRefPtr<Range> Range::create(Document& document) NonnullRefPtr<Range> Range::create(Document& document)

View file

@ -27,7 +27,7 @@ RefPtr<Layout::Node> Text::create_layout_node()
// https://dom.spec.whatwg.org/#dom-text-text // https://dom.spec.whatwg.org/#dom-text-text
NonnullRefPtr<Text> Text::create_with_global_object(Bindings::WindowObject& window, String const& data) NonnullRefPtr<Text> Text::create_with_global_object(Bindings::WindowObject& window, String const& data)
{ {
return make_ref_counted<Text>(window.impl().document(), data); return make_ref_counted<Text>(window.impl().associated_document(), data);
} }
} }

View file

@ -25,7 +25,7 @@ NonnullRefPtr<Window> Window::create_with_document(Document& document)
Window::Window(Document& document) Window::Window(Document& document)
: EventTarget(static_cast<Bindings::ScriptExecutionContext&>(document)) : EventTarget(static_cast<Bindings::ScriptExecutionContext&>(document))
, m_document(document) , m_associated_document(document)
, m_performance(make<HighResolutionTime::Performance>(*this)) , m_performance(make<HighResolutionTime::Performance>(*this))
, m_screen(CSS::Screen::create(*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<Bindings::LocationObject>, URL const& new_href) void Window::did_set_location_href(Badge<Bindings::LocationObject>, URL const& new_href)
{ {
auto* frame = document().browsing_context(); auto* frame = associated_document().browsing_context();
if (!frame) if (!frame)
return; return;
frame->loader().load(new_href, FrameLoader::Type::Navigation); frame->loader().load(new_href, FrameLoader::Type::Navigation);
@ -147,10 +147,10 @@ void Window::did_set_location_href(Badge<Bindings::LocationObject>, URL const& n
void Window::did_call_location_reload(Badge<Bindings::LocationObject>) void Window::did_call_location_reload(Badge<Bindings::LocationObject>)
{ {
auto* frame = document().browsing_context(); auto* frame = associated_document().browsing_context();
if (!frame) if (!frame)
return; return;
frame->loader().load(document().url(), FrameLoader::Type::Reload); frame->loader().load(associated_document().url(), FrameLoader::Type::Reload);
} }
bool Window::dispatch_event(NonnullRefPtr<Event> event) bool Window::dispatch_event(NonnullRefPtr<Event> event)
@ -165,26 +165,26 @@ JS::Object* Window::create_wrapper(JS::GlobalObject& global_object)
int Window::inner_width() const int Window::inner_width() const
{ {
if (!document().layout_node()) if (!associated_document().layout_node())
return 0; return 0;
return document().layout_node()->width(); return associated_document().layout_node()->width();
} }
int Window::inner_height() const int Window::inner_height() const
{ {
if (!document().layout_node()) if (!associated_document().layout_node())
return 0; return 0;
return document().layout_node()->height(); return associated_document().layout_node()->height();
} }
Page* Window::page() Page* Window::page()
{ {
return document().page(); return associated_document().page();
} }
Page const* Window::page() const Page const* Window::page() const
{ {
return document().page(); return associated_document().page();
} }
} }

View file

@ -36,8 +36,8 @@ public:
Page* page(); Page* page();
Page const* page() const; Page const* page() const;
Document const& document() const { return m_document; } Document const& associated_document() const { return m_associated_document; }
Document& document() { return m_document; } Document& associated_document() { return m_associated_document; }
void alert(String const&); void alert(String const&);
bool confirm(String const&); bool confirm(String const&);
@ -75,7 +75,9 @@ public:
private: private:
explicit Window(Document&); explicit Window(Document&);
Document& m_document; // https://html.spec.whatwg.org/multipage/window-object.html#concept-document-window
Document& m_associated_document;
WeakPtr<Bindings::WindowObject> m_wrapper; WeakPtr<Bindings::WindowObject> m_wrapper;
IDAllocator m_timer_id_allocator; IDAllocator m_timer_id_allocator;

View file

@ -62,7 +62,7 @@ DOM::ExceptionOr<NonnullRefPtr<WebSocket>> WebSocket::create_with_global_object(
} }
WebSocket::WebSocket(DOM::Window& window, URL& url) WebSocket::WebSocket(DOM::Window& window, URL& url)
: EventTarget(static_cast<Bindings::ScriptExecutionContext&>(window.document())) : EventTarget(static_cast<Bindings::ScriptExecutionContext&>(window.associated_document()))
, m_window(window) , m_window(window)
{ {
// FIXME: Integrate properly with FETCH as per https://fetch.spec.whatwg.org/#websocket-opening-handshake // FIXME: Integrate properly with FETCH as per https://fetch.spec.whatwg.org/#websocket-opening-handshake

View file

@ -14,7 +14,7 @@
namespace Web::HighResolutionTime { namespace Web::HighResolutionTime {
Performance::Performance(DOM::Window& window) Performance::Performance(DOM::Window& window)
: DOM::EventTarget(static_cast<Bindings::ScriptExecutionContext&>(window.document())) : DOM::EventTarget(static_cast<Bindings::ScriptExecutionContext&>(window.associated_document()))
, m_window(window) , m_window(window)
, m_timing(make<NavigationTiming::PerformanceTiming>(window)) , m_timing(make<NavigationTiming::PerformanceTiming>(window))
{ {

View file

@ -25,7 +25,7 @@
namespace Web::XHR { namespace Web::XHR {
XMLHttpRequest::XMLHttpRequest(DOM::Window& window) XMLHttpRequest::XMLHttpRequest(DOM::Window& window)
: XMLHttpRequestEventTarget(static_cast<Bindings::ScriptExecutionContext&>(window.document())) : XMLHttpRequestEventTarget(static_cast<Bindings::ScriptExecutionContext&>(window.associated_document()))
, m_window(window) , m_window(window)
{ {
} }
@ -119,7 +119,7 @@ DOM::ExceptionOr<void> XMLHttpRequest::open(const String& method, const String&
auto normalized_method = normalize_method(method); 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()) if (!parsed_url.is_valid())
return DOM::SyntaxError::create("Invalid URL"); return DOM::SyntaxError::create("Invalid URL");
@ -166,14 +166,14 @@ DOM::ExceptionOr<void> XMLHttpRequest::send()
// FIXME: If body is not null, then: // FIXME: If body is not null, then:
URL request_url = m_window->document().complete_url(m_url.to_string()); URL request_url = m_window->associated_document().complete_url(m_url.to_string());
dbgln("XHR send from {} to {}", m_window->document().url(), request_url); dbgln("XHR send from {} to {}", m_window->associated_document().url(), request_url);
// TODO: Add support for preflight requests to support CORS requests // TODO: Add support for preflight requests to support CORS requests
Origin request_url_origin = Origin(request_url.protocol(), request_url.host(), request_url.port()); Origin request_url_origin = Origin(request_url.protocol(), request_url.host(), request_url.port());
if (!m_window->document().origin().is_same(request_url_origin)) { 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->document().url(), request_url); 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(); auto weak_this = make_weak_ptr();
if (!weak_this) if (!weak_this)
return {}; return {};

View file

@ -110,7 +110,7 @@ JS_DEFINE_NATIVE_GETTER(ConsoleGlobalObject::inspected_node_getter)
auto console_global_object = static_cast<ConsoleGlobalObject*>(this_object); auto console_global_object = static_cast<ConsoleGlobalObject*>(this_object);
auto& window = console_global_object->m_window_object->impl(); 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) if (!inspected_node)
return JS::js_undefined(); return JS::js_undefined();