return Option from GlobalScope::current

handles the case where GlobalScope::current calls CurrentGlobalOrNull
and the result is null
This commit is contained in:
Jyotsna Prakash 2017-06-21 20:34:21 -07:00
parent dfc44a0d35
commit 433cd90bc3
4 changed files with 10 additions and 6 deletions

View file

@ -543,12 +543,16 @@ impl GlobalScope {
/// ///
/// ["current"]: https://html.spec.whatwg.org/multipage/#current /// ["current"]: https://html.spec.whatwg.org/multipage/#current
#[allow(unsafe_code)] #[allow(unsafe_code)]
pub fn current() -> Root<Self> { pub fn current() -> Option<Root<Self>> {
unsafe { unsafe {
let cx = Runtime::get(); let cx = Runtime::get();
assert!(!cx.is_null()); assert!(!cx.is_null());
let global = CurrentGlobalOrNull(cx); let global = CurrentGlobalOrNull(cx);
global_scope_from_global(global) if global.is_null() {
None
} else {
Some(global_scope_from_global(global))
}
} }
} }

View file

@ -590,7 +590,7 @@ impl HTMLIFrameElementMethods for HTMLIFrameElement {
Some(document) => document, Some(document) => document,
}; };
// Step 4. // Step 4.
let current = GlobalScope::current().as_window().Document(); let current = GlobalScope::current().expect("No current global object").as_window().Document();
if !current.origin().same_origin_domain(document.origin()) { if !current.origin().same_origin_domain(document.origin()) {
return None; return None;
} }

View file

@ -241,7 +241,7 @@ impl PermissionAlgorithm for Permissions {
let state = let state =
prompt_user(&format!("{} {} ?", REQUEST_DIALOG_MESSAGE, perm_name.clone())); prompt_user(&format!("{} {} ?", REQUEST_DIALOG_MESSAGE, perm_name.clone()));
let globalscope = GlobalScope::current(); let globalscope = GlobalScope::current().expect("No current global object");
globalscope.as_window() globalscope.as_window()
.permission_state_invocation_results() .permission_state_invocation_results()
.borrow_mut() .borrow_mut()
@ -266,7 +266,7 @@ pub fn get_descriptor_permission_state(permission_name: PermissionName,
// Step 1. // Step 1.
let settings = match env_settings_obj { let settings = match env_settings_obj {
Some(env_settings_obj) => Root::from_ref(env_settings_obj), Some(env_settings_obj) => Root::from_ref(env_settings_obj),
None => GlobalScope::current(), None => GlobalScope::current().expect("No current global object"),
}; };
// Step 2. // Step 2.

View file

@ -586,7 +586,7 @@ impl WindowMethods for Window {
}; };
// Step 6. // Step 6.
let container_doc = document_from_node(container); let container_doc = document_from_node(container);
let current_doc = GlobalScope::current().as_window().Document(); let current_doc = GlobalScope::current().expect("No current global object").as_window().Document();
if !current_doc.origin().same_origin_domain(container_doc.origin()) { if !current_doc.origin().same_origin_domain(container_doc.origin()) {
return None; return None;
} }