Window should own Location, Document shouldn't

This commit is contained in:
Alan Jeffrey 2017-09-20 13:47:12 -05:00
parent eefd59e933
commit 3d00b0e2ac
2 changed files with 8 additions and 5 deletions

View file

@ -226,7 +226,6 @@ pub struct Document {
node: Node, node: Node,
window: JS<Window>, window: JS<Window>,
implementation: MutNullableJS<DOMImplementation>, implementation: MutNullableJS<DOMImplementation>,
location: MutNullableJS<Location>,
content_type: DOMString, content_type: DOMString,
last_modified: Option<String>, last_modified: Option<String>,
encoding: Cell<EncodingRef>, encoding: Cell<EncodingRef>,
@ -2222,7 +2221,6 @@ impl Document {
window: JS::from_ref(window), window: JS::from_ref(window),
has_browsing_context: has_browsing_context == HasBrowsingContext::Yes, has_browsing_context: has_browsing_context == HasBrowsingContext::Yes,
implementation: Default::default(), implementation: Default::default(),
location: Default::default(),
content_type: match content_type { content_type: match content_type {
Some(string) => string, Some(string) => string,
None => DOMString::from(match is_html_document { None => DOMString::from(match is_html_document {
@ -3438,7 +3436,11 @@ impl DocumentMethods for Document {
// https://html.spec.whatwg.org/multipage/#dom-document-location // https://html.spec.whatwg.org/multipage/#dom-document-location
fn GetLocation(&self) -> Option<Root<Location>> { fn GetLocation(&self) -> Option<Root<Location>> {
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 // https://dom.spec.whatwg.org/#dom-parentnode-children
@ -3815,7 +3817,6 @@ impl DocumentMethods for Document {
// Step 19. // Step 19.
self.implementation.set(None); self.implementation.set(None);
self.location.set(None);
self.images.set(None); self.images.set(None);
self.embeds.set(None); self.embeds.set(None);
self.links.set(None); self.links.set(None);

View file

@ -183,6 +183,7 @@ pub struct Window {
image_cache_chan: Sender<ImageCacheMsg>, image_cache_chan: Sender<ImageCacheMsg>,
window_proxy: MutNullableJS<WindowProxy>, window_proxy: MutNullableJS<WindowProxy>,
document: MutNullableJS<Document>, document: MutNullableJS<Document>,
location: MutNullableJS<Location>,
history: MutNullableJS<History>, history: MutNullableJS<History>,
custom_element_registry: MutNullableJS<CustomElementRegistry>, custom_element_registry: MutNullableJS<CustomElementRegistry>,
performance: MutNullableJS<Performance>, performance: MutNullableJS<Performance>,
@ -568,7 +569,7 @@ impl WindowMethods for Window {
// https://html.spec.whatwg.org/multipage/#dom-location // https://html.spec.whatwg.org/multipage/#dom-location
fn Location(&self) -> Root<Location> { fn Location(&self) -> Root<Location> {
self.Document().GetLocation().unwrap() self.location.or_init(|| Location::new(self))
} }
// https://html.spec.whatwg.org/multipage/#dom-sessionstorage // https://html.spec.whatwg.org/multipage/#dom-sessionstorage
@ -1854,6 +1855,7 @@ impl Window {
image_cache_chan, image_cache_chan,
image_cache, image_cache,
navigator: Default::default(), navigator: Default::default(),
location: Default::default(),
history: Default::default(), history: Default::default(),
custom_element_registry: Default::default(), custom_element_registry: Default::default(),
window_proxy: Default::default(), window_proxy: Default::default(),