From 3b71d4f73193b7606961c5cb162f91272e6570ae Mon Sep 17 00:00:00 2001 From: turuslan Date: Fri, 10 Jul 2015 21:08:01 +0500 Subject: [PATCH] Checking fake id in list before removing (clearTimeout, clearInterval) in worker. Removing fake id from list after setTimeout callback was called in worker. Minified version. --- HackTimerWorker.js | 15 +++++++++++---- HackTimerWorker.min.js | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/HackTimerWorker.js b/HackTimerWorker.js index 6b6c33c..336419d 100644 --- a/HackTimerWorker.js +++ b/HackTimerWorker.js @@ -14,17 +14,24 @@ onmessage = function (event) { }, time); break; case 'clearInterval': - clearInterval(fakeIdToId[fakeId]); - delete fakeIdToId[fakeId]; + if (fakeIdToId.hasOwnProperty (fakeId)) { + clearInterval(fakeIdToId[fakeId]); + delete fakeIdToId[fakeId]; + } break; case 'setTimeout': fakeIdToId[fakeId] = setTimeout(function () { postMessage({fakeId: fakeId}); + if (fakeIdToId.hasOwnProperty (fakeId)) { + delete fakeIdToId[fakeId]; + } }, time); break; case 'clearTimeout': - clearTimeout(fakeIdToId[fakeId]); - delete fakeIdToId[fakeId]; + if (fakeIdToId.hasOwnProperty (fakeId)) { + clearTimeout(fakeIdToId[fakeId]); + delete fakeIdToId[fakeId]; + } break; } } diff --git a/HackTimerWorker.min.js b/HackTimerWorker.min.js index 3fec575..b84dda9 100644 --- a/HackTimerWorker.min.js +++ b/HackTimerWorker.min.js @@ -1 +1 @@ -var f={},p=postMessage;onmessage=function(e){var d=e.data,i=d.i,t=d.hasOwnProperty('t')?d.t:0;switch(d.n){case'a':f[i]=setInterval(function(){p(i)},t);break;case'b':clearInterval(f[i]);delete f[i];break;case'c':f[i]=setTimeout(function(){p(i)},t);break;case'd':clearTimeout(f[i]);delete f[i];break}} \ No newline at end of file +var f={},p=postMessage,r='hasOwnProperty';onmessage=function(e){var d=e.data,i=d.i,t=d[r]('t')?d.t:0;switch(d.n){case'a':f[i]=setInterval(function(){p(i)},t);break;case'b':if(f[r](i)){clearInterval(f[i]);delete f[i]}break;case'c':f[i]=setTimeout(function(){p(i);if(f[r](i))delete f[i]},t);break;case'd':if(f[r](i)){clearTimeout(f[i]);delete f[i]}break}} \ No newline at end of file