mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
script: Handle null contexts better during JS runtime shutdown. (#34769)
* script: Handle null contexts better during JS runtime shutdown. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * lock file Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net> Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com> Co-authored-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
parent
981616f918
commit
4a6d2f8ff0
8 changed files with 41 additions and 30 deletions
|
@ -2253,7 +2253,10 @@ impl GlobalScope {
|
|||
|
||||
#[allow(unsafe_code)]
|
||||
pub fn get_cx() -> SafeJSContext {
|
||||
unsafe { SafeJSContext::from_ptr(Runtime::get()) }
|
||||
let cx = Runtime::get()
|
||||
.expect("Can't obtain context after runtime shutdown")
|
||||
.as_ptr();
|
||||
unsafe { SafeJSContext::from_ptr(cx) }
|
||||
}
|
||||
|
||||
pub fn crypto(&self) -> DomRoot<Crypto> {
|
||||
|
@ -3058,14 +3061,13 @@ impl GlobalScope {
|
|||
/// ["current"]: https://html.spec.whatwg.org/multipage/#current
|
||||
#[allow(unsafe_code)]
|
||||
pub fn current() -> Option<DomRoot<Self>> {
|
||||
let cx = Runtime::get()?;
|
||||
unsafe {
|
||||
let cx = Runtime::get();
|
||||
assert!(!cx.is_null());
|
||||
let global = CurrentGlobalOrNull(cx);
|
||||
let global = CurrentGlobalOrNull(cx.as_ptr());
|
||||
if global.is_null() {
|
||||
None
|
||||
} else {
|
||||
Some(global_scope_from_global(global, cx))
|
||||
Some(global_scope_from_global(global, cx.as_ptr()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue