importscript_worker.js (1068B)
1 var counter = 0; 2 function callByScript() { 3 ++counter; 4 } 5 6 // Use multiple scripts in this load to verify we support that case correctly. 7 // See bug 1249351 for a case where we broke this. 8 importScripts("lorem_script.js", "importscript.sjs"); 9 10 importScripts("importscript.sjs"); 11 12 var missingScriptFailed = false; 13 try { 14 importScripts(["there-is-nothing-here.js"]); 15 } catch (e) { 16 missingScriptFailed = true; 17 } 18 19 onmessage = function (e) { 20 self.clients.matchAll().then(function (res) { 21 if (!res.length) { 22 dump("ERROR: no clients are currently controlled.\n"); 23 } 24 25 if (!missingScriptFailed) { 26 res[0].postMessage("KO"); 27 } 28 29 try { 30 // new unique script should fail 31 importScripts(["importscript.sjs?unique=true"]); 32 res[0].postMessage("KO"); 33 return; 34 } catch (ex) {} 35 36 try { 37 // duplicate script previously offlined should succeed 38 importScripts(["importscript.sjs"]); 39 } catch (ex) { 40 res[0].postMessage("KO"); 41 return; 42 } 43 44 res[0].postMessage(counter == 3 ? "OK" : "KO"); 45 }); 46 };