diff --git a/index.js b/index.js index 4e771ee..e591e66 100644 --- a/index.js +++ b/index.js @@ -339,6 +339,14 @@ class WorkerHelper { }); this._worker.onmessage = (e) => { const {id, data} = e.data; + if (data == "messageerror") { + this._bad = true; + // resolve all existing promises + this._promisesByIdMap.forEach(({resolve}) => { + resolve({}); + }); + return; + } this._messagesByIdMap.set(id, data); this._process(id); }; @@ -440,21 +448,13 @@ async function checkWorkers(workerType) { } } - addSupportsRow('requestAnimationFrame', rAF); + if (workerType === "dedicated") { + addSupportsRow('requestAnimationFrame', rAF); + } addSupportsRow('transferControlToOffscreen', offscreen); addSupportsRow('OffscreenCanvas', offscreenSupported); addSupportsRow('CanvasRenderingContext2D', twoD); - let moduleSupport = false; - try { - const workerModule = new WorkerHelper('worker-module.js'); - const data = await workerModule.getMessage('ping'); - moduleSupport = true; - } catch (e) { - // - } - addSupportsRow('es6 modules', moduleSupport); - addElemToDocument(el('table', { className: 'worker' }, [ el('tbody', {}, mapLikeToTableRows(obj, false)), ])); diff --git a/worker-import.js b/worker-import.js deleted file mode 100644 index 55a033d..0000000 --- a/worker-import.js +++ /dev/null @@ -1,3 +0,0 @@ -const msg = "imported"; - -export default msg; \ No newline at end of file diff --git a/worker-module.js b/worker-module.js deleted file mode 100644 index 4dd6fc3..0000000 --- a/worker-module.js +++ /dev/null @@ -1,16 +0,0 @@ -import msg from './worker-import.js'; - -const handlers = { - ping(id) { - postMessage({id, data: {msg}}); - }, -}; - -self.onmessage = function(e) { - const {command, id, data} = e.data; - const handler = handlers[command]; - if (!handler) { - throw new Error(`unknown command: ${command}`); - } - handler(id, data); -}; \ No newline at end of file diff --git a/worker.js b/worker.js index d205446..d1d6577 100644 --- a/worker.js +++ b/worker.js @@ -62,4 +62,7 @@ self.onconnect = function(e) { port.onmessage = function(event) { handleMessage.call(port, event); }; + port.onmessageerror = function() { + port.postMessage({data: 'messageerror'}); + }; };