diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index e3bb46bf5c03..e50ff071f6e6 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -226,7 +226,6 @@ pub struct Document { node: Node, window: JS, implementation: MutNullableJS, - location: MutNullableJS, content_type: DOMString, last_modified: Option, encoding: Cell, @@ -2222,7 +2221,6 @@ impl Document { window: JS::from_ref(window), has_browsing_context: has_browsing_context == HasBrowsingContext::Yes, implementation: Default::default(), - location: Default::default(), content_type: match content_type { Some(string) => string, None => DOMString::from(match is_html_document { @@ -3438,7 +3436,11 @@ impl DocumentMethods for Document { // https://html.spec.whatwg.org/multipage/#dom-document-location fn GetLocation(&self) -> Option> { - self.browsing_context().map(|_| self.location.or_init(|| Location::new(&self.window))) + if self.is_fully_active() { + Some(self.window.Location()) + } else { + None + } } // https://dom.spec.whatwg.org/#dom-parentnode-children @@ -3815,7 +3817,6 @@ impl DocumentMethods for Document { // Step 19. self.implementation.set(None); - self.location.set(None); self.images.set(None); self.embeds.set(None); self.links.set(None); diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 1cb38d0a7cad..7ad5d0c02ace 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -183,6 +183,7 @@ pub struct Window { image_cache_chan: Sender, window_proxy: MutNullableJS, document: MutNullableJS, + location: MutNullableJS, history: MutNullableJS, custom_element_registry: MutNullableJS, performance: MutNullableJS, @@ -568,7 +569,7 @@ impl WindowMethods for Window { // https://html.spec.whatwg.org/multipage/#dom-location fn Location(&self) -> Root { - self.Document().GetLocation().unwrap() + self.location.or_init(|| Location::new(self)) } // https://html.spec.whatwg.org/multipage/#dom-sessionstorage @@ -1854,6 +1855,7 @@ impl Window { image_cache_chan, image_cache, navigator: Default::default(), + location: Default::default(), history: Default::default(), custom_element_registry: Default::default(), window_proxy: Default::default(),