servo: Merge #11548 - Make Document::DefaultView return a null value when there's no browsing context (from kevgs:default_view2); r=Ms2ger
authorKosov Eugene <claprix@yandex.ru>
Thu, 09 Jun 2016 02:48:30 -0500
changeset 339049 b9bef04df02b855ff9611fd5dce940ec51fd2975
parent 339048 5f15da4310f008abe6b7fb824a67276c6d99508f
child 339050 57c812687fa2fff552d7f91630b9e3370419ee38
push id31307
push usergszorc@mozilla.com
push dateSat, 04 Feb 2017 00:59:06 +0000
treeherdermozilla-central@94079d43835f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMs2ger
servo: Merge #11548 - Make Document::DefaultView return a null value when there's no browsing context (from kevgs:default_view2); r=Ms2ger Fixes #11469. Source-Repo: https://github.com/servo/servo Source-Revision: 77e0089c1234b4a762f0676a46f1921c76b7f362
servo/components/script/dom/document.rs
servo/components/script/dom/element.rs
servo/components/script/dom/webidls/Document.webidl
--- a/servo/components/script/dom/document.rs
+++ b/servo/components/script/dom/document.rs
@@ -2546,18 +2546,22 @@ impl DocumentMethods for Document {
     }
 
     // https://html.spec.whatwg.org/multipage/#dom-document-readystate
     fn ReadyState(&self) -> DocumentReadyState {
         self.ready_state.get()
     }
 
     // https://html.spec.whatwg.org/multipage/#dom-document-defaultview
-    fn DefaultView(&self) -> Root<Window> {
-        Root::from_ref(&*self.window)
+    fn GetDefaultView(&self) -> Option<Root<Window>> {
+        if self.browsing_context.is_none() {
+            None
+        } else {
+            Some(Root::from_ref(&*self.window))
+        }
     }
 
     // https://html.spec.whatwg.org/multipage/#dom-document-cookie
     fn GetCookie(&self) -> Fallible<DOMString> {
         if self.is_cookie_averse() {
             return Ok(DOMString::new());
         }
 
--- a/servo/components/script/dom/element.rs
+++ b/servo/components/script/dom/element.rs
@@ -1310,17 +1310,20 @@ impl Element {
         let doc = node.owner_doc();
 
         // Step 4
         if !doc.is_fully_active() {
             return;
         }
 
         // Step 5
-        let win = doc.DefaultView();
+        let win = match doc.GetDefaultView() {
+            None => return,
+            Some(win) => win,
+        };
 
         // Step 7
         if *self.root_element() == *self {
             if doc.quirks_mode() != Quirks {
                 win.scroll(x, y, behavior);
             }
 
             return;
@@ -1648,17 +1651,20 @@ impl ElementMethods for Element {
         let doc = node.owner_doc();
 
         // Step 2
         if !doc.is_fully_active() {
             return 0.0;
         }
 
         // Step 3
-        let win = doc.DefaultView();
+        let win = match doc.GetDefaultView() {
+            None => return 0.0,
+            Some(win) => win,
+        };
 
         // Step 5
         if *self.root_element() == *self {
             if doc.quirks_mode() == Quirks {
                 return 0.0;
             }
 
             // Step 6
@@ -1696,17 +1702,20 @@ impl ElementMethods for Element {
         let doc = node.owner_doc();
 
         // Step 4
         if !doc.is_fully_active() {
             return;
         }
 
         // Step 5
-        let win = doc.DefaultView();
+        let win = match doc.GetDefaultView() {
+            None => return,
+            Some(win) => win,
+        };
 
         // Step 7
         if *self.root_element() == *self {
             if doc.quirks_mode() != Quirks {
                 win.scroll(win.ScrollX() as f64, y, behavior);
             }
 
             return;
@@ -1734,17 +1743,20 @@ impl ElementMethods for Element {
         let doc = node.owner_doc();
 
         // Step 2
         if !doc.is_fully_active() {
             return 0.0;
         }
 
         // Step 3
-        let win = doc.DefaultView();
+        let win = match doc.GetDefaultView() {
+            None => return 0.0,
+            Some(win) => win,
+        };
 
         // Step 5
         if *self.root_element() == *self {
             if doc.quirks_mode() != Quirks {
                 // Step 6
                 return win.ScrollX() as f64;
             }
 
@@ -1782,17 +1794,20 @@ impl ElementMethods for Element {
         let doc = node.owner_doc();
 
         // Step 4
         if !doc.is_fully_active() {
             return;
         }
 
         // Step 5
-        let win = doc.DefaultView();
+        let win = match doc.GetDefaultView() {
+            None => return,
+            Some(win) => win,
+        };
 
         // Step 7
         if *self.root_element() == *self {
             if doc.quirks_mode() == Quirks {
                 return;
             }
 
             win.scroll(x, win.ScrollY() as f64, behavior);
--- a/servo/components/script/dom/webidls/Document.webidl
+++ b/servo/components/script/dom/webidls/Document.webidl
@@ -113,17 +113,17 @@ partial /*sealed*/ interface Document {
   // dynamic markup insertion
   // Document open(optional DOMString type = "text/html", optional DOMString replace = "");
   // WindowProxy open(DOMString url, DOMString name, DOMString features, optional boolean replace = false);
   // void close();
   // void write(DOMString... text);
   // void writeln(DOMString... text);
 
   // user interaction
-  readonly attribute Window/*Proxy?*/ defaultView;
+  readonly attribute Window?/*Proxy?*/ defaultView;
   readonly attribute Element? activeElement;
   boolean hasFocus();
   // attribute DOMString designMode;
   // boolean execCommand(DOMString commandId, optional boolean showUI = false, optional DOMString value = "");
   // boolean queryCommandEnabled(DOMString commandId);
   // boolean queryCommandIndeterm(DOMString commandId);
   // boolean queryCommandState(DOMString commandId);
   // boolean queryCommandSupported(DOMString commandId);