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.
This commit is contained in:
Shannon Booth 2024-10-21 13:48:44 +13:00 committed by Andrew Kaster
commit 84dc83e0e0
Notes: github-actions[bot] 2024-11-01 19:16:55 +00:00
14 changed files with 27 additions and 25 deletions

View file

@ -2440,7 +2440,7 @@ static void generate_html_constructor(SourceGenerator& generator, IDL::Construct
} }
constructor_generator.append(R"~~~( constructor_generator.append(R"~~~(
auto& window = verify_cast<HTML::Window>(HTML::current_global_object()); auto& window = verify_cast<HTML::Window>(HTML::current_principal_global_object());
// 1. Let registry be the current global object's CustomElementRegistry 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(); })); auto registry = TRY(throw_dom_exception_if_needed(vm, [&] { return window.custom_elements(); }));

View file

@ -34,7 +34,7 @@ JS::NonnullGCPtr<Animation> Animation::create(JS::Realm& realm, JS::GCPtr<Animat
// a timeline argument is missing, passing the default document timeline of the Document associated with the // a timeline argument is missing, passing the default document timeline of the Document associated with the
// Window that is the current global object. // Window that is the current global object.
if (!timeline.has_value()) { if (!timeline.has_value()) {
auto& window = verify_cast<HTML::Window>(HTML::current_global_object()); auto& window = verify_cast<HTML::Window>(HTML::current_principal_global_object());
timeline = window.associated_document().timeline(); timeline = window.associated_document().timeline();
} }
animation->set_timeline(timeline.release_value()); animation->set_timeline(timeline.release_value());

View file

@ -41,7 +41,7 @@ JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> AudioConstructor::construct(
auto& vm = this->vm(); auto& vm = this->vm();
// 1. Let document be the current global object's associated Document. // 1. Let document be the current global object's associated Document.
auto& window = verify_cast<HTML::Window>(HTML::current_global_object()); auto& window = verify_cast<HTML::Window>(HTML::current_principal_global_object());
auto& document = window.associated_document(); auto& document = window.associated_document();
// 2. Let audio be the result of creating an element given document, audio, and the HTML namespace. // 2. Let audio be the result of creating an element given document, audio, and the HTML namespace.

View file

@ -36,12 +36,13 @@ JS::ThrowCompletionOr<JS::Value> ImageConstructor::call()
} }
// https://html.spec.whatwg.org/multipage/embedded-content.html#dom-image // https://html.spec.whatwg.org/multipage/embedded-content.html#dom-image
// https://whatpr.org/html/9893/embedded-content.html#dom-image
JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> ImageConstructor::construct(FunctionObject&) JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> ImageConstructor::construct(FunctionObject&)
{ {
auto& vm = this->vm(); auto& vm = this->vm();
// 1. Let document be the current global object's associated Document. // 1. Let document be the current principal global object's associated Document.
auto& window = verify_cast<HTML::Window>(HTML::current_global_object()); auto& window = verify_cast<HTML::Window>(HTML::current_principal_global_object());
auto& document = window.associated_document(); auto& document = window.associated_document();
// 2. Let img be the result of creating an element given document, img, and the HTML namespace. // 2. Let img be the result of creating an element given document, img, and the HTML namespace.

View file

@ -39,13 +39,14 @@ JS::ThrowCompletionOr<JS::Value> OptionConstructor::call()
} }
// https://html.spec.whatwg.org/multipage/form-elements.html#dom-option // https://html.spec.whatwg.org/multipage/form-elements.html#dom-option
// https://whatpr.org/html/9893/form-elements.html#dom-option
JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> OptionConstructor::construct(FunctionObject&) JS::ThrowCompletionOr<JS::NonnullGCPtr<JS::Object>> OptionConstructor::construct(FunctionObject&)
{ {
auto& vm = this->vm(); auto& vm = this->vm();
auto& realm = *vm.current_realm(); auto& realm = *vm.current_realm();
// 1. Let document be the current global object's associated Document. // 1. Let document be the current principal global object's associated Document.
auto& window = verify_cast<HTML::Window>(HTML::current_global_object()); auto& window = verify_cast<HTML::Window>(HTML::current_principal_global_object());
auto& document = window.associated_document(); auto& document = window.associated_document();
// 2. Let option be the result of creating an element given document, option, and the HTML namespace. // 2. Let option be the result of creating an element given document, option, and the HTML namespace.

View file

@ -34,8 +34,8 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<CSSStyleSheet>> CSSStyleSheet::construct_im
// 1. Construct a new CSSStyleSheet object sheet. // 1. Construct a new CSSStyleSheet object sheet.
auto sheet = create(realm, CSSRuleList::create_empty(realm), CSS::MediaList::create(realm, {}), {}); auto sheet = create(realm, CSSRuleList::create_empty(realm), CSS::MediaList::create(realm, {}), {});
// 2. Set sheets location to the base URL of the associated Document for the current global object. // 2. Set sheets location to the base URL of the associated Document for the current principal global object.
auto associated_document = verify_cast<HTML::Window>(HTML::current_global_object()).document(); auto associated_document = verify_cast<HTML::Window>(HTML::current_principal_global_object()).document();
sheet->set_location(MUST(associated_document->base_url().to_string())); sheet->set_location(MUST(associated_document->base_url().to_string()));
// 3. Set sheets stylesheet base URL to the baseURL attribute value from options. // 3. Set sheets stylesheet base URL to the baseURL attribute value from options.

View file

@ -44,7 +44,7 @@ void Text::visit_edges(Cell::Visitor& visitor)
WebIDL::ExceptionOr<JS::NonnullGCPtr<Text>> Text::construct_impl(JS::Realm& realm, String const& data) WebIDL::ExceptionOr<JS::NonnullGCPtr<Text>> Text::construct_impl(JS::Realm& realm, String const& data)
{ {
// The new Text(data) constructor steps are to set thiss data to data and thiss node document to current global objects associated Document. // The new Text(data) constructor steps are to set thiss data to data and thiss node document to current global objects associated Document.
auto& window = verify_cast<HTML::Window>(HTML::current_global_object()); auto& window = verify_cast<HTML::Window>(HTML::current_principal_global_object());
return realm.heap().allocate<Text>(realm, window.associated_document(), data); return realm.heap().allocate<Text>(realm, window.associated_document(), data);
} }

View file

@ -110,7 +110,7 @@ WebIDL::ExceptionOr<String> Location::href() const
WebIDL::ExceptionOr<void> Location::set_href(String const& new_href) WebIDL::ExceptionOr<void> Location::set_href(String const& new_href)
{ {
auto& realm = this->realm(); auto& realm = this->realm();
auto& window = verify_cast<HTML::Window>(HTML::current_global_object()); auto& window = verify_cast<HTML::Window>(HTML::current_principal_global_object());
// 1. If this's relevant Document is null, then return. // 1. If this's relevant Document is null, then return.
auto const relevant_document = this->relevant_document(); auto const relevant_document = this->relevant_document();

View file

@ -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. // 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. // NOTE: The NavigatorPlugins mixin should only be exposed on the Window object.
auto const& window = verify_cast<HTML::Window>(HTML::current_global_object()); auto const& window = verify_cast<HTML::Window>(HTML::current_principal_global_object());
return window.page().pdf_viewer_supported(); return window.page().pdf_viewer_supported();
} }
@ -55,7 +55,7 @@ bool Navigator::webdriver() const
// Returns true if webdriver-active flag is set, false otherwise. // Returns true if webdriver-active flag is set, false otherwise.
// NOTE: The NavigatorAutomationInformation interface should not be exposed on WorkerNavigator. // NOTE: The NavigatorAutomationInformation interface should not be exposed on WorkerNavigator.
auto const& window = verify_cast<HTML::Window>(HTML::current_global_object()); auto const& window = verify_cast<HTML::Window>(HTML::current_principal_global_object());
return window.page().is_webdriver_active(); return window.page().is_webdriver_active();
} }

View file

@ -319,7 +319,7 @@ EnvironmentSettingsObject& current_principal_settings_object()
} }
// https://html.spec.whatwg.org/multipage/webappapis.html#current-global-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& event_loop = HTML::main_thread_event_loop();
auto& vm = event_loop.vm(); auto& vm = event_loop.vm();

View file

@ -146,7 +146,7 @@ JS::Object& incumbent_global_object();
JS::Realm& current_principal_realm(); JS::Realm& current_principal_realm();
EnvironmentSettingsObject& current_principal_settings_object(); EnvironmentSettingsObject& current_principal_settings_object();
JS::Object& current_global_object(); JS::Object& current_principal_global_object();
JS::Realm& relevant_realm(JS::Object const&); JS::Realm& relevant_realm(JS::Object const&);
EnvironmentSettingsObject& relevant_settings_object(JS::Object const&); EnvironmentSettingsObject& relevant_settings_object(JS::Object const&);
EnvironmentSettingsObject& relevant_settings_object(DOM::Node const&); EnvironmentSettingsObject& relevant_settings_object(DOM::Node const&);

View file

@ -160,8 +160,8 @@ JS::ThrowCompletionOr<JS::Value> WindowProxy::internal_get(JS::PropertyKey const
// 1. Let W be the value of the [[Window]] internal slot of this. // 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. // 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<Window>(current_global_object()).browsing_context(), m_window->browsing_context(), property_key, current_principal_settings_object()); check_if_access_between_two_browsing_contexts_should_be_reported(*verify_cast<Window>(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). // 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. // NOTE: this is passed rather than W as OrdinaryGet and CrossOriginGet will invoke the [[GetOwnProperty]] internal method.
@ -181,8 +181,8 @@ JS::ThrowCompletionOr<bool> WindowProxy::internal_set(JS::PropertyKey const& pro
// 1. Let W be the value of the [[Window]] internal slot of this. // 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. // 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<Window>(current_global_object()).browsing_context(), m_window->browsing_context(), property_key, current_principal_settings_object()); check_if_access_between_two_browsing_contexts_should_be_reported(*verify_cast<Window>(current_principal_global_object()).browsing_context(), m_window->browsing_context(), property_key, current_principal_settings_object());
// 3. If IsPlatformObjectSameOrigin(W) is true, then: // 3. If IsPlatformObjectSameOrigin(W) is true, then:
if (is_platform_object_same_origin(*m_window)) { if (is_platform_object_same_origin(*m_window)) {

View file

@ -29,11 +29,11 @@ PerformanceMark::~PerformanceMark() = default;
// https://w3c.github.io/user-timing/#dfn-performancemark-constructor // https://w3c.github.io/user-timing/#dfn-performancemark-constructor
WebIDL::ExceptionOr<JS::NonnullGCPtr<PerformanceMark>> PerformanceMark::construct_impl(JS::Realm& realm, String const& mark_name, Web::UserTiming::PerformanceMarkOptions const& mark_options) WebIDL::ExceptionOr<JS::NonnullGCPtr<PerformanceMark>> 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(); 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. // 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<HTML::Window>(current_global_object)) { if (is<HTML::Window>(current_principal_global_object)) {
bool matched = false; bool matched = false;
#define __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME(name, _) \ #define __ENUMERATE_NAVIGATION_TIMING_ENTRY_NAME(name, _) \

View file

@ -159,7 +159,7 @@ WebIDL::ExceptionOr<JS::GCPtr<DOM::Document>> XMLHttpRequest::response_xml()
WebIDL::ExceptionOr<void> XMLHttpRequest::set_response_type(Bindings::XMLHttpRequestResponseType response_type) WebIDL::ExceptionOr<void> 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. // 1. If the current global object is not a Window object and the given value is "document", then return.
if (!is<HTML::Window>(HTML::current_global_object()) && response_type == Bindings::XMLHttpRequestResponseType::Document) if (!is<HTML::Window>(HTML::current_principal_global_object()) && response_type == Bindings::XMLHttpRequestResponseType::Document)
return {}; return {};
// 2. If thiss state is loading or done, then throw an "InvalidStateError" DOMException. // 2. If thiss state is loading or done, then throw an "InvalidStateError" DOMException.
@ -167,7 +167,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::set_response_type(Bindings::XMLHttpReq
return WebIDL::InvalidStateError::create(realm(), "Can't readyState when XHR is loading or done"_string); 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 thiss synchronous flag is set, then throw an "InvalidAccessError" DOMException. // 3. If the current global object is a Window object and thiss synchronous flag is set, then throw an "InvalidAccessError" DOMException.
if (is<HTML::Window>(HTML::current_global_object()) && m_synchronous) if (is<HTML::Window>(HTML::current_principal_global_object()) && m_synchronous)
return WebIDL::InvalidAccessError::create(realm(), "Can't set readyState on synchronous XHR in Window environment"_string); return WebIDL::InvalidAccessError::create(realm(), "Can't set readyState on synchronous XHR in Window environment"_string);
// 4. Set thiss response type to the given value. // 4. Set thiss response type to the given value.
@ -506,7 +506,7 @@ WebIDL::ExceptionOr<void> XMLHttpRequest::open(String const& method_string, Stri
// 9. If async is false, the current global object is a Window object, and either thiss timeout is // 9. If async is false, the current global object is a Window object, and either thiss timeout is
// not 0 or thiss response type is not the empty string, then throw an "InvalidAccessError" DOMException. // not 0 or thiss response type is not the empty string, then throw an "InvalidAccessError" DOMException.
if (!async if (!async
&& is<HTML::Window>(HTML::current_global_object()) && is<HTML::Window>(HTML::current_principal_global_object())
&& (m_timeout != 0 || m_response_type != Bindings::XMLHttpRequestResponseType::Empty)) { && (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); 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<void> XMLHttpRequest::set_timeout(u32 timeout)
{ {
// 1. If the current global object is a Window object and thiss synchronous flag is set, // 1. If the current global object is a Window object and thiss synchronous flag is set,
// then throw an "InvalidAccessError" DOMException. // then throw an "InvalidAccessError" DOMException.
if (is<HTML::Window>(HTML::current_global_object()) && m_synchronous) if (is<HTML::Window>(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); return WebIDL::InvalidAccessError::create(realm(), "Use of XMLHttpRequest's timeout attribute is not supported in the synchronous mode in window context."_string);
// 2. Set thiss timeout to the given value. // 2. Set thiss timeout to the given value.