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:
Josh Matthews 2024-12-26 03:23:27 -05:00 committed by GitHub
parent 981616f918
commit 4a6d2f8ff0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 41 additions and 30 deletions

View file

@ -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()))
}
}
}