From 84dc83e0e0a6cc0d304affed546b844c492fffb0 Mon Sep 17 00:00:00 2001 From: Shannon Booth Date: Mon, 21 Oct 2024 13:48:44 +1300 Subject: [PATCH] LibWeb: Rename current_global_object to current_principal_global_object Again, following a rename as part of the introduction of shadow realms inducing a bunch of mechanical changes. --- .../LibWeb/BindingsGenerator/IDLGenerators.cpp | 2 +- Userland/Libraries/LibWeb/Animations/Animation.cpp | 2 +- Userland/Libraries/LibWeb/Bindings/AudioConstructor.cpp | 2 +- Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp | 5 +++-- Userland/Libraries/LibWeb/Bindings/OptionConstructor.cpp | 5 +++-- Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp | 4 ++-- Userland/Libraries/LibWeb/DOM/Text.cpp | 2 +- Userland/Libraries/LibWeb/HTML/Location.cpp | 2 +- Userland/Libraries/LibWeb/HTML/Navigator.cpp | 4 ++-- Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp | 2 +- Userland/Libraries/LibWeb/HTML/Scripting/Environments.h | 2 +- Userland/Libraries/LibWeb/HTML/WindowProxy.cpp | 8 ++++---- Userland/Libraries/LibWeb/UserTiming/PerformanceMark.cpp | 4 ++-- Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp | 8 ++++---- 14 files changed, 27 insertions(+), 25 deletions(-) diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp index e26b99b85f..527cccec6a 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/BindingsGenerator/IDLGenerators.cpp @@ -2440,7 +2440,7 @@ static void generate_html_constructor(SourceGenerator& generator, IDL::Construct } constructor_generator.append(R"~~~( - auto& window = verify_cast(HTML::current_global_object()); + auto& window = verify_cast(HTML::current_principal_global_object()); // 1. Let registry be the current global object's CustomElementRegistry object. auto registry = TRY(throw_dom_exception_if_needed(vm, [&] { return window.custom_elements(); })); diff --git a/Userland/Libraries/LibWeb/Animations/Animation.cpp b/Userland/Libraries/LibWeb/Animations/Animation.cpp index 9ef693c7b1..a5e54790b3 100644 --- a/Userland/Libraries/LibWeb/Animations/Animation.cpp +++ b/Userland/Libraries/LibWeb/Animations/Animation.cpp @@ -34,7 +34,7 @@ JS::NonnullGCPtr Animation::create(JS::Realm& realm, JS::GCPtr(HTML::current_global_object()); + auto& window = verify_cast(HTML::current_principal_global_object()); timeline = window.associated_document().timeline(); } animation->set_timeline(timeline.release_value()); diff --git a/Userland/Libraries/LibWeb/Bindings/AudioConstructor.cpp b/Userland/Libraries/LibWeb/Bindings/AudioConstructor.cpp index b16a46ec41..a5fda03f23 100644 --- a/Userland/Libraries/LibWeb/Bindings/AudioConstructor.cpp +++ b/Userland/Libraries/LibWeb/Bindings/AudioConstructor.cpp @@ -41,7 +41,7 @@ JS::ThrowCompletionOr> AudioConstructor::construct( auto& vm = this->vm(); // 1. Let document be the current global object's associated Document. - auto& window = verify_cast(HTML::current_global_object()); + auto& window = verify_cast(HTML::current_principal_global_object()); auto& document = window.associated_document(); // 2. Let audio be the result of creating an element given document, audio, and the HTML namespace. diff --git a/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp b/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp index 7bb9ae757a..594fc880fc 100644 --- a/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp +++ b/Userland/Libraries/LibWeb/Bindings/ImageConstructor.cpp @@ -36,12 +36,13 @@ JS::ThrowCompletionOr ImageConstructor::call() } // https://html.spec.whatwg.org/multipage/embedded-content.html#dom-image +// https://whatpr.org/html/9893/embedded-content.html#dom-image JS::ThrowCompletionOr> ImageConstructor::construct(FunctionObject&) { auto& vm = this->vm(); - // 1. Let document be the current global object's associated Document. - auto& window = verify_cast(HTML::current_global_object()); + // 1. Let document be the current principal global object's associated Document. + auto& window = verify_cast(HTML::current_principal_global_object()); auto& document = window.associated_document(); // 2. Let img be the result of creating an element given document, img, and the HTML namespace. diff --git a/Userland/Libraries/LibWeb/Bindings/OptionConstructor.cpp b/Userland/Libraries/LibWeb/Bindings/OptionConstructor.cpp index 4e19d3f8a3..3777674811 100644 --- a/Userland/Libraries/LibWeb/Bindings/OptionConstructor.cpp +++ b/Userland/Libraries/LibWeb/Bindings/OptionConstructor.cpp @@ -39,13 +39,14 @@ JS::ThrowCompletionOr OptionConstructor::call() } // https://html.spec.whatwg.org/multipage/form-elements.html#dom-option +// https://whatpr.org/html/9893/form-elements.html#dom-option JS::ThrowCompletionOr> OptionConstructor::construct(FunctionObject&) { auto& vm = this->vm(); auto& realm = *vm.current_realm(); - // 1. Let document be the current global object's associated Document. - auto& window = verify_cast(HTML::current_global_object()); + // 1. Let document be the current principal global object's associated Document. + auto& window = verify_cast(HTML::current_principal_global_object()); auto& document = window.associated_document(); // 2. Let option be the result of creating an element given document, option, and the HTML namespace. diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp index 278ef39a84..334962c383 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp @@ -34,8 +34,8 @@ WebIDL::ExceptionOr> CSSStyleSheet::construct_im // 1. Construct a new CSSStyleSheet object sheet. auto sheet = create(realm, CSSRuleList::create_empty(realm), CSS::MediaList::create(realm, {}), {}); - // 2. Set sheet’s location to the base URL of the associated Document for the current global object. - auto associated_document = verify_cast(HTML::current_global_object()).document(); + // 2. Set sheet’s location to the base URL of the associated Document for the current principal global object. + auto associated_document = verify_cast(HTML::current_principal_global_object()).document(); sheet->set_location(MUST(associated_document->base_url().to_string())); // 3. Set sheet’s stylesheet base URL to the baseURL attribute value from options. diff --git a/Userland/Libraries/LibWeb/DOM/Text.cpp b/Userland/Libraries/LibWeb/DOM/Text.cpp index 0eea95fee5..1f3895c086 100644 --- a/Userland/Libraries/LibWeb/DOM/Text.cpp +++ b/Userland/Libraries/LibWeb/DOM/Text.cpp @@ -44,7 +44,7 @@ void Text::visit_edges(Cell::Visitor& visitor) WebIDL::ExceptionOr> Text::construct_impl(JS::Realm& realm, String const& data) { // The new Text(data) constructor steps are to set this’s data to data and this’s node document to current global object’s associated Document. - auto& window = verify_cast(HTML::current_global_object()); + auto& window = verify_cast(HTML::current_principal_global_object()); return realm.heap().allocate(realm, window.associated_document(), data); } diff --git a/Userland/Libraries/LibWeb/HTML/Location.cpp b/Userland/Libraries/LibWeb/HTML/Location.cpp index 86350eabcd..d0998b3236 100644 --- a/Userland/Libraries/LibWeb/HTML/Location.cpp +++ b/Userland/Libraries/LibWeb/HTML/Location.cpp @@ -110,7 +110,7 @@ WebIDL::ExceptionOr Location::href() const WebIDL::ExceptionOr Location::set_href(String const& new_href) { auto& realm = this->realm(); - auto& window = verify_cast(HTML::current_global_object()); + auto& window = verify_cast(HTML::current_principal_global_object()); // 1. If this's relevant Document is null, then return. auto const relevant_document = this->relevant_document(); diff --git a/Userland/Libraries/LibWeb/HTML/Navigator.cpp b/Userland/Libraries/LibWeb/HTML/Navigator.cpp index dba3531ef4..83953ab59f 100644 --- a/Userland/Libraries/LibWeb/HTML/Navigator.cpp +++ b/Userland/Libraries/LibWeb/HTML/Navigator.cpp @@ -45,7 +45,7 @@ bool Navigator::pdf_viewer_enabled() const { // The NavigatorPlugins mixin's pdfViewerEnabled getter steps are to return the user agent's PDF viewer supported. // NOTE: The NavigatorPlugins mixin should only be exposed on the Window object. - auto const& window = verify_cast(HTML::current_global_object()); + auto const& window = verify_cast(HTML::current_principal_global_object()); return window.page().pdf_viewer_supported(); } @@ -55,7 +55,7 @@ bool Navigator::webdriver() const // Returns true if webdriver-active flag is set, false otherwise. // NOTE: The NavigatorAutomationInformation interface should not be exposed on WorkerNavigator. - auto const& window = verify_cast(HTML::current_global_object()); + auto const& window = verify_cast(HTML::current_principal_global_object()); return window.page().is_webdriver_active(); } diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp index 811b49b43b..bab9131cf5 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp +++ b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.cpp @@ -319,7 +319,7 @@ EnvironmentSettingsObject& current_principal_settings_object() } // https://html.spec.whatwg.org/multipage/webappapis.html#current-global-object -JS::Object& current_global_object() +JS::Object& current_principal_global_object() { auto& event_loop = HTML::main_thread_event_loop(); auto& vm = event_loop.vm(); diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h index 390fea6b02..21a185df67 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h +++ b/Userland/Libraries/LibWeb/HTML/Scripting/Environments.h @@ -146,7 +146,7 @@ JS::Object& incumbent_global_object(); JS::Realm& current_principal_realm(); EnvironmentSettingsObject& current_principal_settings_object(); -JS::Object& current_global_object(); +JS::Object& current_principal_global_object(); JS::Realm& relevant_realm(JS::Object const&); EnvironmentSettingsObject& relevant_settings_object(JS::Object const&); EnvironmentSettingsObject& relevant_settings_object(DOM::Node const&); diff --git a/Userland/Libraries/LibWeb/HTML/WindowProxy.cpp b/Userland/Libraries/LibWeb/HTML/WindowProxy.cpp index 059f322270..a6c60d9eda 100644 --- a/Userland/Libraries/LibWeb/HTML/WindowProxy.cpp +++ b/Userland/Libraries/LibWeb/HTML/WindowProxy.cpp @@ -160,8 +160,8 @@ JS::ThrowCompletionOr WindowProxy::internal_get(JS::PropertyKey const // 1. Let W be the value of the [[Window]] internal slot of this. - // 2. Check if an access between two browsing contexts should be reported, given the current global object's browsing context, W's browsing context, P, and the current principal settings object. - check_if_access_between_two_browsing_contexts_should_be_reported(*verify_cast(current_global_object()).browsing_context(), m_window->browsing_context(), property_key, current_principal_settings_object()); + // 2. Check if an access between two browsing contexts should be reported, given the current principal global object's browsing context, W's browsing context, P, and the current principal settings object. + check_if_access_between_two_browsing_contexts_should_be_reported(*verify_cast(current_principal_global_object()).browsing_context(), m_window->browsing_context(), property_key, current_principal_settings_object()); // 3. If IsPlatformObjectSameOrigin(W) is true, then return ? OrdinaryGet(this, P, Receiver). // NOTE: this is passed rather than W as OrdinaryGet and CrossOriginGet will invoke the [[GetOwnProperty]] internal method. @@ -181,8 +181,8 @@ JS::ThrowCompletionOr WindowProxy::internal_set(JS::PropertyKey const& pro // 1. Let W be the value of the [[Window]] internal slot of this. - // 2. Check if an access between two browsing contexts should be reported, given the current global object's browsing context, W's browsing context, P, and the current principal settings object. - check_if_access_between_two_browsing_contexts_should_be_reported(*verify_cast(current_global_object()).browsing_context(), m_window->browsing_context(), property_key, current_principal_settings_object()); + // 2. Check if an access between two browsing contexts should be reported, given the current principal global object's browsing context, W's browsing context, P, and the current principal settings object. + check_if_access_between_two_browsing_contexts_should_be_reported(*verify_cast(current_principal_global_object()).browsing_context(), m_window->browsing_context(), property_key, current_principal_settings_object()); // 3. If IsPlatformObjectSameOrigin(W) is true, then: if (is_platform_object_same_origin(*m_window)) { diff --git a/Userland/Libraries/LibWeb/UserTiming/PerformanceMark.cpp b/Userland/Libraries/LibWeb/UserTiming/PerformanceMark.cpp index 6ec1f15a52..c2f374e3da 100644 --- a/Userland/Libraries/LibWeb/UserTiming/PerformanceMark.cpp +++ b/Userland/Libraries/LibWeb/UserTiming/PerformanceMark.cpp @@ -29,11 +29,11 @@ PerformanceMark::~PerformanceMark() = default; // https://w3c.github.io/user-timing/#dfn-performancemark-constructor WebIDL::ExceptionOr> PerformanceMark::construct_impl(JS::Realm& realm, String const& mark_name, Web::UserTiming::PerformanceMarkOptions const& mark_options) { - auto& current_global_object = realm.global_object(); + auto& current_principal_global_object = HTML::current_principal_global_object(); auto& vm = realm.vm(); // 1. If the current global object is a Window object and markName uses the same name as a read only attribute in the PerformanceTiming interface, throw a SyntaxError. - if (is(current_global_object)) { + if (is(current_principal_global_object)) { bool matched = false; #define __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME(name, _) \ diff --git a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp index 97d8c452e3..9f4d734489 100644 --- a/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp +++ b/Userland/Libraries/LibWeb/XHR/XMLHttpRequest.cpp @@ -159,7 +159,7 @@ WebIDL::ExceptionOr> XMLHttpRequest::response_xml() WebIDL::ExceptionOr XMLHttpRequest::set_response_type(Bindings::XMLHttpRequestResponseType response_type) { // 1. If the current global object is not a Window object and the given value is "document", then return. - if (!is(HTML::current_global_object()) && response_type == Bindings::XMLHttpRequestResponseType::Document) + if (!is(HTML::current_principal_global_object()) && response_type == Bindings::XMLHttpRequestResponseType::Document) return {}; // 2. If this’s state is loading or done, then throw an "InvalidStateError" DOMException. @@ -167,7 +167,7 @@ WebIDL::ExceptionOr XMLHttpRequest::set_response_type(Bindings::XMLHttpReq return WebIDL::InvalidStateError::create(realm(), "Can't readyState when XHR is loading or done"_string); // 3. If the current global object is a Window object and this’s synchronous flag is set, then throw an "InvalidAccessError" DOMException. - if (is(HTML::current_global_object()) && m_synchronous) + if (is(HTML::current_principal_global_object()) && m_synchronous) return WebIDL::InvalidAccessError::create(realm(), "Can't set readyState on synchronous XHR in Window environment"_string); // 4. Set this’s response type to the given value. @@ -506,7 +506,7 @@ WebIDL::ExceptionOr XMLHttpRequest::open(String const& method_string, Stri // 9. If async is false, the current global object is a Window object, and either this’s timeout is // not 0 or this’s response type is not the empty string, then throw an "InvalidAccessError" DOMException. if (!async - && is(HTML::current_global_object()) + && is(HTML::current_principal_global_object()) && (m_timeout != 0 || m_response_type != Bindings::XMLHttpRequestResponseType::Empty)) { return WebIDL::InvalidAccessError::create(realm(), "Synchronous XMLHttpRequests in a Window context do not support timeout or a non-empty responseType"_string); } @@ -1051,7 +1051,7 @@ WebIDL::ExceptionOr XMLHttpRequest::set_timeout(u32 timeout) { // 1. If the current global object is a Window object and this’s synchronous flag is set, // then throw an "InvalidAccessError" DOMException. - if (is(HTML::current_global_object()) && m_synchronous) + if (is(HTML::current_principal_global_object()) && m_synchronous) return WebIDL::InvalidAccessError::create(realm(), "Use of XMLHttpRequest's timeout attribute is not supported in the synchronous mode in window context."_string); // 2. Set this’s timeout to the given value.