diff options
author | bors-servo <metajack+bors@gmail.com> | 2015-02-05 11:54:48 -0700 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2015-02-05 11:54:48 -0700 |
commit | 5c02f8956d37d39f4482c570621ffa1c61a3f41c (patch) | |
tree | 136f94daa7df20c9855bca3af71bc5a9aa5a0d3f | |
parent | d439c0d16d6ea1449d207858705d124e191ecc13 (diff) | |
parent | af4b371107362fd1a2d7d69848a389aeb82017df (diff) | |
download | servo-5c02f8956d37d39f4482c570621ffa1c61a3f41c.tar.gz servo-5c02f8956d37d39f4482c570621ffa1c61a3f41c.zip |
auto merge of #4845 : KiChjang/servo/location-in-doc, r=jdm
Fixes #4840
-rw-r--r-- | components/script/dom/document.rs | 6 | ||||
-rw-r--r-- | components/script/dom/window.rs | 9 |
2 files changed, 10 insertions, 5 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 682d2dcd9aa..c38cd80dd20 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -9,7 +9,6 @@ use dom::bindings::codegen::Bindings::DocumentBinding::{DocumentMethods, Documen use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; use dom::bindings::codegen::Bindings::NodeFilterBinding::NodeFilter; -use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use dom::bindings::codegen::InheritTypes::{DocumentDerived, EventCast, HTMLElementCast}; use dom::bindings::codegen::InheritTypes::{HTMLHeadElementCast, TextCast, ElementCast}; use dom::bindings::codegen::InheritTypes::{DocumentTypeCast, HTMLHtmlElementCast, NodeCast}; @@ -86,6 +85,7 @@ pub struct Document { window: JS<Window>, idmap: DOMRefCell<HashMap<Atom, Vec<JS<Element>>>>, implementation: MutNullableJS<DOMImplementation>, + location: MutNullableJS<Location>, content_type: DOMString, last_modified: DOMRefCell<Option<DOMString>>, encoding_name: DOMRefCell<DOMString>, @@ -425,6 +425,7 @@ impl Document { window: JS::from_rooted(window), idmap: DOMRefCell::new(HashMap::new()), implementation: Default::default(), + location: Default::default(), content_type: match content_type { Some(string) => string.clone(), None => match is_html_document { @@ -976,7 +977,8 @@ impl<'a> DocumentMethods for JSRef<'a, Document> { fn Location(self) -> Temporary<Location> { let window = self.window.root(); - window.r().Location() + let window = window.r(); + self.location.or_init(|| Location::new(window, window.page_clone())) } // http://dom.spec.whatwg.org/#dom-parentnode-children diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index d1d76cfaa4e..7ac5ebbc5b9 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -7,6 +7,7 @@ use dom::bindings::codegen::Bindings::EventHandlerBinding::{OnErrorEventHandlerN use dom::bindings::codegen::Bindings::FunctionBinding::Function; use dom::bindings::codegen::Bindings::WindowBinding; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; +use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::InheritTypes::EventTargetCast; use dom::bindings::global::global_object_for_js_object; use dom::bindings::error::Fallible; @@ -57,7 +58,6 @@ pub struct Window { script_chan: Box<ScriptChan+Send>, control_chan: ScriptControlChan, console: MutNullableJS<Console>, - location: MutNullableJS<Location>, navigator: MutNullableJS<Navigator>, image_cache_task: ImageCacheTask, compositor: DOMRefCell<Box<ScriptListener+'static>>, @@ -101,6 +101,10 @@ impl Window { &*self.page } + pub fn page_clone(&self) -> Rc<Page> { + self.page.clone() + } + pub fn get_url(&self) -> Url { self.page().get_url() } @@ -200,7 +204,7 @@ impl<'a> WindowMethods for JSRef<'a, Window> { } fn Location(self) -> Temporary<Location> { - self.location.or_init(|| Location::new(self, self.page.clone())) + self.Document().root().r().Location() } fn SessionStorage(self) -> Temporary<Storage> { @@ -401,7 +405,6 @@ impl Window { console: Default::default(), compositor: DOMRefCell::new(compositor), page: page, - location: Default::default(), navigator: Default::default(), image_cache_task: image_cache_task, browser_context: DOMRefCell::new(None), |