servo: Merge #10257 - #10141 : Document::location set null for documents without a browsing context (from slayerjain:first_bug); r=KiChjang
authorshubham_jain <shubhamkjain@outlook.com>
Sun, 10 Apr 2016 00:10:21 +0500
changeset 476635 706bafebf7c38a81cb0f8378aa580875d1f624e3
parent 476634 d07ee1178d980f2d5ff8a86d6c429eb0d3e9a82b
child 476636 1c3e662ecb2d6a03198b69711afd715e664da892
push id44079
push userbmo:gps@mozilla.com
push dateSat, 04 Feb 2017 00:14:49 +0000
reviewersKiChjang
servo: Merge #10257 - #10141 : Document::location set null for documents without a browsing context (from slayerjain:first_bug); r=KiChjang Fixes #10141. Source-Repo: https://github.com/servo/servo Source-Revision: c33bf4987af3479c515351195a55c12dacfcc871
servo/components/script/dom/document.rs
servo/components/script/dom/webidls/Document.webidl
servo/components/script/dom/window.rs
servo/components/script/dom/xmldocument.rs
--- a/servo/components/script/dom/document.rs
+++ b/servo/components/script/dom/document.rs
@@ -2418,18 +2418,18 @@ impl DocumentMethods for Document {
         // FIXME: This should be return OBJECT elements containing applets.
         self.applets.or_init(|| {
             let filter = box AppletsFilter;
             HTMLCollection::create(&self.window, self.upcast(), filter)
         })
     }
 
     // https://html.spec.whatwg.org/multipage/#dom-document-location
-    fn Location(&self) -> Root<Location> {
-        self.location.or_init(|| Location::new(&self.window))
+    fn GetLocation(&self) -> Option<Root<Location>> {
+        self.browsing_context().map(|_| self.location.or_init(|| Location::new(&self.window)))
     }
 
     // https://dom.spec.whatwg.org/#dom-parentnode-children
     fn Children(&self) -> Root<HTMLCollection> {
         HTMLCollection::children(&self.window, self.upcast())
     }
 
     // https://dom.spec.whatwg.org/#dom-parentnode-firstelementchild
@@ -2772,9 +2772,8 @@ pub enum FocusType {
     Parent,     // Focusing a parent element (an iframe)
 }
 
 /// Focus events
 pub enum FocusEventType {
     Focus,      // Element gained focus. Doesn't bubble.
     Blur,       // Element lost focus. Doesn't bubble.
 }
-
--- a/servo/components/script/dom/webidls/Document.webidl
+++ b/servo/components/script/dom/webidls/Document.webidl
@@ -76,17 +76,17 @@ Document implements ParentNode;
 
 enum DocumentReadyState { "loading", "interactive", "complete" };
 
 // https://html.spec.whatwg.org/multipage/#the-document-object
 // [OverrideBuiltins]
 partial /*sealed*/ interface Document {
   // resource metadata management
   [/*PutForwards=href, */Unforgeable]
-  readonly attribute Location/*?*/ location;
+  readonly attribute Location? location;
   readonly attribute DOMString domain;
   // readonly attribute DOMString referrer;
   [Throws]
   attribute DOMString cookie;
   readonly attribute DOMString lastModified;
   readonly attribute DocumentReadyState readyState;
 
   // DOM tree accessors
--- a/servo/components/script/dom/window.rs
+++ b/servo/components/script/dom/window.rs
@@ -436,17 +436,17 @@ impl WindowMethods for Window {
 
     // https://html.spec.whatwg.org/multipage/#dom-document-2
     fn Document(&self) -> Root<Document> {
         self.browsing_context().active_document()
     }
 
     // https://html.spec.whatwg.org/multipage/#dom-location
     fn Location(&self) -> Root<Location> {
-        self.Document().Location()
+        self.Document().GetLocation().unwrap()
     }
 
     // https://html.spec.whatwg.org/multipage/#dom-sessionstorage
     fn SessionStorage(&self) -> Root<Storage> {
         self.session_storage.or_init(|| Storage::new(&GlobalRef::Window(self), StorageType::Session))
     }
 
     // https://html.spec.whatwg.org/multipage/#dom-localstorage
--- a/servo/components/script/dom/xmldocument.rs
+++ b/servo/components/script/dom/xmldocument.rs
@@ -71,18 +71,18 @@ impl XMLDocument {
             node.set_owner_doc(&doc.r().document);
         }
         doc
     }
 }
 
 impl XMLDocumentMethods for XMLDocument {
     // https://html.spec.whatwg.org/multipage/#dom-document-location
-    fn Location(&self) -> Root<Location> {
-        self.document.Location()
+    fn GetLocation(&self) -> Option<Root<Location>> {
+        self.document.GetLocation()
     }
 
     // https://html.spec.whatwg.org/multipage/#dom-tree-accessors:supported-property-names
     fn SupportedPropertyNames(&self) -> Vec<DOMString> {
         self.document.SupportedPropertyNames()
     }
 
     // https://html.spec.whatwg.org/multipage/#dom-tree-accessors:dom-document-nameditem-filter