diff --git a/Cargo.lock b/Cargo.lock index 37ff3c54bbd..4ab1c1936c9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -429,7 +429,7 @@ dependencies = [ "bitflags 2.6.0", "cexpr", "clang-sys", - "itertools 0.10.5", + "itertools 0.13.0", "proc-macro2", "quote", "regex", @@ -957,7 +957,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "117725a109d387c937a1533ce01b450cbde6b88abceea8473c4d7a85853cda3c" dependencies = [ "lazy_static", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -1862,7 +1862,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33d852cb9b869c2a9b3df2f71a3074817f01e1844f839a144f5fcef059a4eb5d" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -4447,7 +4447,7 @@ dependencies = [ [[package]] name = "mozjs" version = "0.14.1" -source = "git+https://github.com/servo/mozjs#1765a7c7eaf1e4a02fdfff6866c8f427c659dc91" +source = "git+https://github.com/servo/mozjs#0081fc4a3f5fc9891d4377844a874651f7c46041" dependencies = [ "bindgen", "cc", @@ -4460,7 +4460,7 @@ dependencies = [ [[package]] name = "mozjs_sys" version = "0.128.6-1" -source = "git+https://github.com/servo/mozjs#1765a7c7eaf1e4a02fdfff6866c8f427c659dc91" +source = "git+https://github.com/servo/mozjs#0081fc4a3f5fc9891d4377844a874651f7c46041" dependencies = [ "bindgen", "cc", @@ -5889,7 +5889,7 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -7153,7 +7153,7 @@ dependencies = [ "fastrand", "once_cell", "rustix", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -8423,7 +8423,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] diff --git a/components/script/dom/bindings/callback.rs b/components/script/dom/bindings/callback.rs index bb4e59ba75c..5f1ec6d1c07 100644 --- a/components/script/dom/bindings/callback.rs +++ b/components/script/dom/bindings/callback.rs @@ -93,8 +93,9 @@ impl Drop for CallbackObject { #[allow(unsafe_code)] fn drop(&mut self) { unsafe { - let cx = Runtime::get(); - RemoveRawValueRoot(cx, self.permanent_js_root.get_unsafe()); + if let Some(cx) = Runtime::get() { + RemoveRawValueRoot(cx.as_ptr(), self.permanent_js_root.get_unsafe()); + } } } } diff --git a/components/script/dom/bindings/principals.rs b/components/script/dom/bindings/principals.rs index cf95361bccd..30d309a6e37 100644 --- a/components/script/dom/bindings/principals.rs +++ b/components/script/dom/bindings/principals.rs @@ -70,7 +70,9 @@ impl Clone for ServoJSPrincipals { impl Drop for ServoJSPrincipals { #[inline] fn drop(&mut self) { - unsafe { JS_DropPrincipals(Runtime::get(), self.as_raw()) }; + if let Some(cx) = Runtime::get() { + unsafe { JS_DropPrincipals(cx.as_ptr(), self.as_raw()) }; + } } } diff --git a/components/script/dom/bindings/settings_stack.rs b/components/script/dom/bindings/settings_stack.rs index 3da1db5f6f6..3c9f57b7458 100644 --- a/components/script/dom/bindings/settings_stack.rs +++ b/components/script/dom/bindings/settings_stack.rs @@ -117,9 +117,9 @@ impl AutoIncumbentScript { pub fn new(global: &GlobalScope) -> Self { // Step 2-3. unsafe { - let cx = Runtime::get(); - assert!(!cx.is_null()); - HideScriptedCaller(cx); + let cx = + Runtime::get().expect("Creating a new incumbent script after runtime shutdown"); + HideScriptedCaller(cx.as_ptr()); } STACK.with(|stack| { trace!("Prepare to run a callback with {:p}", global); @@ -156,9 +156,9 @@ impl Drop for AutoIncumbentScript { }); unsafe { // Step 1-2. - let cx = Runtime::get(); - assert!(!cx.is_null()); - UnhideScriptedCaller(cx); + if let Some(cx) = Runtime::get() { + UnhideScriptedCaller(cx.as_ptr()); + } } } } @@ -174,9 +174,12 @@ pub fn incumbent_global() -> Option> { // there's nothing on the JS stack, which will cause us to check the // incumbent script stack below. unsafe { - let cx = Runtime::get(); - assert!(!cx.is_null()); - let global = GetScriptedCallerGlobal(cx); + let Some(cx) = Runtime::get() else { + // It's not meaningful to return a global object if the runtime + // no longer exists. + return None; + }; + let global = GetScriptedCallerGlobal(cx.as_ptr()); if !global.is_null() { return Some(GlobalScope::from_object(global)); } diff --git a/components/script/dom/globalscope.rs b/components/script/dom/globalscope.rs index 2779a6be2c8..300c28c636d 100644 --- a/components/script/dom/globalscope.rs +++ b/components/script/dom/globalscope.rs @@ -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 { @@ -3058,14 +3061,13 @@ impl GlobalScope { /// ["current"]: https://html.spec.whatwg.org/multipage/#current #[allow(unsafe_code)] pub fn current() -> Option> { + 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())) } } } diff --git a/components/script/dom/promise.rs b/components/script/dom/promise.rs index f4098ad3d0e..c56d7e91349 100644 --- a/components/script/dom/promise.rs +++ b/components/script/dom/promise.rs @@ -78,9 +78,9 @@ impl Drop for Promise { unsafe { let object = self.permanent_js_root.get().to_object(); assert!(!object.is_null()); - let cx = Runtime::get(); - assert!(!cx.is_null()); - RemoveRawValueRoot(cx, self.permanent_js_root.get_unsafe()); + if let Some(cx) = Runtime::get() { + RemoveRawValueRoot(cx.as_ptr(), self.permanent_js_root.get_unsafe()); + } } } } diff --git a/components/script/script_runtime.rs b/components/script/script_runtime.rs index 0cd2bb91e31..0d3922ec8d9 100644 --- a/components/script/script_runtime.rs +++ b/components/script/script_runtime.rs @@ -621,7 +621,9 @@ impl Runtime { &*(closure as *mut NetworkingTaskSource); let runnable = Runnable(dispatchable); let task = task!(dispatch_to_event_loop_message: move || { - runnable.run(RustRuntime::get(), Dispatchable_MaybeShuttingDown::NotShuttingDown); + if let Some(cx) = RustRuntime::get() { + runnable.run(cx.as_ptr(), Dispatchable_MaybeShuttingDown::NotShuttingDown); + } }); networking_task_src.queue_unconditionally(task).is_ok() @@ -801,6 +803,8 @@ impl Runtime { impl Drop for Runtime { #[allow(unsafe_code)] fn drop(&mut self) { + self.microtask_queue.clear(); + unsafe { DeleteJobQueue(self.job_queue); } diff --git a/tests/wpt/meta/fetch/api/basic/keepalive.any.js.ini b/tests/wpt/meta/fetch/api/basic/keepalive.any.js.ini index 8171e724852..2ce2d784ab5 100644 --- a/tests/wpt/meta/fetch/api/basic/keepalive.any.js.ini +++ b/tests/wpt/meta/fetch/api/basic/keepalive.any.js.ini @@ -1,5 +1,4 @@ [keepalive.any.html] - expected: CRASH [keepalive in onunload in nested frame in another window] expected: FAIL