sharedWorker_fetch.js (862B)
1 var clients = new Array(); 2 clients.length = 0; 3 4 var broadcast = function (message) { 5 var length = clients.length; 6 for (var i = 0; i < length; i++) { 7 port = clients[i]; 8 port.postMessage(message); 9 } 10 }; 11 12 onconnect = function (e) { 13 clients.push(e.ports[0]); 14 if (clients.length == 1) { 15 clients[0].postMessage("Connected"); 16 } else if (clients.length == 2) { 17 broadcast("BothConnected"); 18 clients[0].onmessage = function (msg) { 19 if (msg.data == "StartFetchWithWrongIntegrity") { 20 // The fetch will succeed because the integrity value is invalid and we 21 // are looking for the console message regarding the bad integrity value. 22 fetch("SharedWorker_SRIFailed.html", { integrity: "abc" }).then( 23 function () { 24 clients[0].postMessage("SRI_failed"); 25 } 26 ); 27 } 28 }; 29 } 30 };