Bug 1771009 - Make TimeoutManager::SetTimeout no-op if window is dying r=smaug

setTimeout is not affected since nsGlobalWindowInner::SetTimeout is not called at all when it's dying, but that's not the case with AbortSignal.timout, so we have to explicitly deal with such situation.

Differential Revision: https://phabricator.services.mozilla.com/D147368
This commit is contained in:
Kagami Sascha Rosylight 2022-05-27 14:02:53 +00:00
parent 999f79eca9
commit 490bd934d0
3 changed files with 24 additions and 1 deletions

View File

@ -465,7 +465,7 @@ nsresult TimeoutManager::SetTimeout(TimeoutHandler* aHandler, int32_t interval,
// If we don't have a document (we could have been unloaded since
// the call to setTimeout was made), do nothing.
nsCOMPtr<Document> doc = mWindow.GetExtantDoc();
if (!doc) {
if (!doc || mWindow.IsDying()) {
return NS_OK;
}

View File

@ -0,0 +1,22 @@
<!DOCTYPE html>
<html class="test-wait">
<meta charset="utf-8">
<iframe id="iframe"></iframe>
<script>
const srcdoc = `
<!DOCTYPE html>
<meta charset="utf-8">
<script>
const xhr = new XMLHttpRequest()
setTimeout(() => {
xhr.open('GET', '/', false)
xhr.send()
AbortSignal.timeout(41.62684667994843)
}, 1)
setTimeout(() => {
location.href = "about:blank"
parent.document.documentElement.classList.remove("test-wait")
}, 0)
</` + "script>";
iframe.srcdoc = srcdoc;
</script>

View File

@ -341,6 +341,7 @@ SET TIMEOUT: speculation-rules/prerender/resources/prerender-response-code.html
SET TIMEOUT: speculation-rules/prerender/resources/deferred-promise-utils.js
SET TIMEOUT: speculation-rules/prerender/resources/utils.js
SET TIMEOUT: html/browsers/browsing-the-web/back-forward-cache/timers.html
SET TIMEOUT: dom/abort/crashtests/timeout-close.html
# setTimeout use in reftests
SET TIMEOUT: acid/acid3/test.html