mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Access browsing context without panic
Current browsing context accessor in Document unwrap the browsing context option which prevents document to handle correctly the case when there is no browsing context.
This commit is contained in:
parent
1794c6673a
commit
f8c7235f73
2 changed files with 8 additions and 3 deletions
|
@ -390,7 +390,7 @@ impl Document {
|
|||
#[inline]
|
||||
pub fn browsing_context(&self) -> Option<Root<BrowsingContext>> {
|
||||
if self.has_browsing_context {
|
||||
Some(self.window.browsing_context())
|
||||
self.window.maybe_browsing_context()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
|
@ -319,10 +319,15 @@ impl Window {
|
|||
&self.image_cache_thread
|
||||
}
|
||||
|
||||
/// This can panic if it is called after the browsing context has been discarded
|
||||
pub fn browsing_context(&self) -> Root<BrowsingContext> {
|
||||
self.browsing_context.get().unwrap()
|
||||
}
|
||||
|
||||
pub fn maybe_browsing_context(&self) -> Option<Root<BrowsingContext>> {
|
||||
self.browsing_context.get()
|
||||
}
|
||||
|
||||
pub fn bluetooth_thread(&self) -> IpcSender<BluetoothRequest> {
|
||||
self.bluetooth_thread.clone()
|
||||
}
|
||||
|
@ -608,7 +613,7 @@ impl WindowMethods for Window {
|
|||
// https://html.spec.whatwg.org/multipage/#dom-parent
|
||||
fn GetParent(&self) -> Option<Root<BrowsingContext>> {
|
||||
// Steps 1. and 2.
|
||||
if self.browsing_context().is_discarded() {
|
||||
if self.maybe_browsing_context().map_or(true, |c| c.is_discarded()) {
|
||||
return None;
|
||||
}
|
||||
match self.parent() {
|
||||
|
@ -622,7 +627,7 @@ impl WindowMethods for Window {
|
|||
// https://html.spec.whatwg.org/multipage/#dom-top
|
||||
fn GetTop(&self) -> Option<Root<BrowsingContext>> {
|
||||
// Steps 1. and 2.
|
||||
if self.browsing_context().is_discarded() {
|
||||
if self.maybe_browsing_context().map_or(true, |c| c.is_discarded()) {
|
||||
return None;
|
||||
}
|
||||
// Step 5.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue