diff options
author | Connor Brewster <connor.brewster@eagles.oc.edu> | 2017-06-26 22:27:02 -0700 |
---|---|---|
committer | Connor Brewster <connor.brewster@eagles.oc.edu> | 2017-06-27 22:14:19 -1000 |
commit | 79f3237692fa5894eccb4cf3615b6da4a49dc3c8 (patch) | |
tree | def014cefbbb14e645293a588c557242a19f9a83 /components/script/dom/window.rs | |
parent | 3f2d7476890bffdaad6fdc0e66aa7ac7bc995a87 (diff) | |
download | servo-79f3237692fa5894eccb4cf3615b6da4a49dc3c8.tar.gz servo-79f3237692fa5894eccb4cf3615b6da4a49dc3c8.zip |
Don't return window proxy if it has been discarded
Diffstat (limited to 'components/script/dom/window.rs')
-rw-r--r-- | components/script/dom/window.rs | 19 |
1 files changed, 10 insertions, 9 deletions
diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 58f0e7b4a1a..837e10c921b 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -345,8 +345,15 @@ impl Window { self.window_proxy.get().unwrap() } - pub fn maybe_window_proxy(&self) -> Option<Root<WindowProxy>> { + /// Returns the window proxy if it has not been discarded. + /// https://html.spec.whatwg.org/multipage/#a-browsing-context-is-discarded + pub fn undiscarded_window_proxy(&self) -> Option<Root<WindowProxy>> { self.window_proxy.get() + .and_then(|window_proxy| if window_proxy.is_browsing_context_discarded() { + None + } else { + Some(window_proxy) + }) } pub fn bluetooth_thread(&self) -> IpcSender<BluetoothRequest> { @@ -670,13 +677,10 @@ impl WindowMethods for Window { // https://html.spec.whatwg.org/multipage/#dom-parent fn GetParent(&self) -> Option<Root<WindowProxy>> { // Steps 1-3. - let window_proxy = match self.maybe_window_proxy() { + let window_proxy = match self.undiscarded_window_proxy() { Some(window_proxy) => window_proxy, None => return None, }; - if window_proxy.is_browsing_context_discarded() { - return None; - } // Step 4. if let Some(parent) = window_proxy.parent() { return Some(Root::from_ref(parent)); @@ -688,13 +692,10 @@ impl WindowMethods for Window { // https://html.spec.whatwg.org/multipage/#dom-top fn GetTop(&self) -> Option<Root<WindowProxy>> { // Steps 1-3. - let window_proxy = match self.maybe_window_proxy() { + let window_proxy = match self.undiscarded_window_proxy() { Some(window_proxy) => window_proxy, None => return None, }; - if window_proxy.is_browsing_context_discarded() { - return None; - } // Steps 4-5. Some(Root::from_ref(window_proxy.top())) } |