script: Expose NodeTraits::owner_global / Window::as_global_scope (#34843)

Expose two new helpers and start using them as much as possible.

- `NodeTraits::owner_global`: which gets the `GlobalScope` that currenty
 owns a `Node`. This may be different than `.global()` in the case that
 the `Node` was adopted by a different `Document`.
- `Window::as_global_scope`: A helper to avoid having to cast so much
  when treating a `Window` like a `GlobalScope`.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2025-01-07 10:56:02 +01:00 committed by GitHub
parent 17e2ca3f01
commit e42b4b793d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
33 changed files with 262 additions and 258 deletions

View file

@ -55,7 +55,6 @@ use crate::dom::comment::Comment;
use crate::dom::document::{Document, DocumentSource, HasBrowsingContext, IsHTMLDocument};
use crate::dom::documenttype::DocumentType;
use crate::dom::element::{CustomElementCreationMode, Element, ElementCreator};
use crate::dom::globalscope::GlobalScope;
use crate::dom::htmlformelement::{FormControlElementHelpers, HTMLFormElement};
use crate::dom::htmlimageelement::HTMLImageElement;
use crate::dom::htmlinputelement::HTMLInputElement;
@ -366,7 +365,7 @@ impl ServoParser {
let profiler_chan = self
.document
.window()
.upcast::<GlobalScope>()
.as_global_scope()
.time_profiler_chan()
.clone();
let profiler_metadata = TimerMetadata {
@ -564,7 +563,7 @@ impl ServoParser {
let profiler_chan = self
.document
.window()
.upcast::<GlobalScope>()
.as_global_scope()
.time_profiler_chan()
.clone();
let profiler_metadata = TimerMetadata {
@ -637,7 +636,7 @@ impl ServoParser {
if is_execution_stack_empty() {
self.document
.window()
.upcast::<GlobalScope>()
.as_global_scope()
.perform_a_microtask_checkpoint(can_gc);
}
@ -1401,7 +1400,7 @@ fn create_element_for_token(
if is_execution_stack_empty() {
document
.window()
.upcast::<GlobalScope>()
.as_global_scope()
.perform_a_microtask_checkpoint(can_gc);
}
// Step 6.3