Skip to content

Commit 4ad2e92

Browse files
authored
script: Handle when debugger global is active in DedicatedWorkerGlobalScope interrupt (servo#42159)
When interrupting `DedicatedWorkerGlobalScope` execution, handle the case that the `DebuggerGlobalScope` is running its script by just terminating. It seems that this happens sometimes when trusted types terminates a worker script. Testing: This should fix some flaky `expect` failure panics in trusted types WPT tests. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
1 parent 2964846 commit 4ad2e92

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

components/script/dom/workers/dedicatedworkerglobalscope.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -752,11 +752,15 @@ impl DedicatedWorkerGlobalScope {
752752
pub(crate) unsafe extern "C" fn interrupt_callback(cx: *mut JSContext) -> bool {
753753
let in_realm_proof = AlreadyInRealm::assert_for_cx(unsafe { SafeJSContext::from_ptr(cx) });
754754
let global = unsafe { GlobalScope::from_context(cx, InRealm::Already(&in_realm_proof)) };
755-
let worker =
756-
DomRoot::downcast::<WorkerGlobalScope>(global).expect("global is not a worker scope");
757-
assert!(worker.is::<DedicatedWorkerGlobalScope>());
755+
756+
// If we are running the debugger script, just exit immediately.
757+
let Some(worker) = global.downcast::<WorkerGlobalScope>() else {
758+
assert!(global.is::<DebuggerGlobalScope>());
759+
return false;
760+
};
758761

759762
// A false response causes the script to terminate
763+
assert!(worker.is::<DedicatedWorkerGlobalScope>());
760764
!worker.is_closing()
761765
}
762766

0 commit comments

Comments
 (0)