Bug 1748342, don't start FileReader's timer if the worker is shutting down, r=dom-worker-reviewers,jesup

Differential Revision: https://phabricator.services.mozilla.com/D135078
This commit is contained in:
Olli Pettay 2022-01-12 14:57:46 +00:00
parent a3884ad516
commit 4ea70a7334
3 changed files with 35 additions and 0 deletions

View File

@ -501,6 +501,14 @@ JSObject* FileReader::WrapObject(JSContext* aCx,
}
void FileReader::StartProgressEventTimer() {
if (!NS_IsMainThread() && !mWeakWorkerRef) {
// The worker is possibly shutting down if dispatching a DOM event right
// before this call triggered an InterruptCallback call.
// XXX Note, the check is limited to workers for now, since it is unclear
// in the spec how FileReader should behave in this case on the main thread.
return;
}
if (!mProgressNotifier) {
mProgressNotifier = NS_NewTimer(mTarget);
}

View File

@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<script id="worker1" type="javascript/worker">
self.onmessage = async function (e) {
self.close()
const reader = new FileReader()
for (let i = 0; i < 25; i++) {
try { reader.readAsBinaryString(e.data[0]) } catch (e) {}
}
reader.addEventListener("progress", () => {}, {})
}
</script>
<script>
window.addEventListener("load", () => {
const script = new Blob([document.querySelector("#worker1").textContent], { type: "text/javascript" })
const worker = new Worker(window.URL.createObjectURL(script))
const data = new Blob(["70𯸟\n٠𛪇\0𛃧كe۰҅妽󠶖󠙻𝅧𡴶𝌋쮁偵9󠰾󠋼7\r𐇽0🥂.\b፟+፟D󠢪3𣚽󠜎🐾<F3A09C8E>c_߰a<<=𝅦9𝆭𛰅9󠵼ௌ󠌌𖓄ΐ0<CE90>뢈/-᭰*٠٪᷁e <65>𯯐𯬓𯕏걢V*=­￿**󠛐\u2028שּׁ&0󠄯𒡯e\n𛰵󠥿𫍰,󠶒𝅥t\nl𧶈a𦜠09k𯔆䴋<F0AF9486>|󠄷🦻𛝫󠁥𖭄", "*𒗬۰0\u2029/\n\r+󠎔𖼣k*=🿹𯀊\r٪\r󠳐𝲍慑B<E68591>\r󠮱\r\n\"\r\\𯉆۹c卑4󠣰󠻬鴗ꛌ\0⌕:\r\n𝚨9ꛅ٠󠃭𯋾\nJ󠯲9\r゙鈷P\u2029҉󠷒۹e \b緁︡𤆥^𯏂゚੿|٫󠕉揅ᷛ𩊜s𯑳2凅9c8H𦰤-\f%٠𨮫󠚵2𫈮P𝋄窥57\n-゙҄H󠭗𯪞𣃂-ᷢשּׁ貌솽|𝉃c㙡𯐉᭯mL\r"], {
"type": "image/png",
"endings": "transparent"
})
worker.postMessage([data], [])
})
</script>
</head>
</html>

View File

@ -1,3 +1,4 @@
skip-if(ThreadSanitizer) load 1480354.html
load 1562891.html
skip-if(Android||ThreadSanitizer) load 1747185.html # Crashes on Android, times out on TSan.
load 1748342.html