2015-06-28 21:54:41 +00:00
|
|
|
var fakeIdToId = {};
|
|
|
|
onmessage = function (event) {
|
|
|
|
var data = event.data,
|
|
|
|
name = data.name,
|
|
|
|
fakeId = data.fakeId,
|
|
|
|
time;
|
|
|
|
if(data.hasOwnProperty('time')) {
|
|
|
|
time = data.time;
|
|
|
|
}
|
|
|
|
switch (name) {
|
|
|
|
case 'setInterval':
|
|
|
|
fakeIdToId[fakeId] = setInterval(function () {
|
|
|
|
postMessage({fakeId: fakeId});
|
|
|
|
}, time);
|
|
|
|
break;
|
|
|
|
case 'clearInterval':
|
2015-07-10 16:08:01 +00:00
|
|
|
if (fakeIdToId.hasOwnProperty (fakeId)) {
|
|
|
|
clearInterval(fakeIdToId[fakeId]);
|
|
|
|
delete fakeIdToId[fakeId];
|
|
|
|
}
|
2015-06-28 21:54:41 +00:00
|
|
|
break;
|
|
|
|
case 'setTimeout':
|
|
|
|
fakeIdToId[fakeId] = setTimeout(function () {
|
|
|
|
postMessage({fakeId: fakeId});
|
2015-07-10 16:08:01 +00:00
|
|
|
if (fakeIdToId.hasOwnProperty (fakeId)) {
|
|
|
|
delete fakeIdToId[fakeId];
|
|
|
|
}
|
2015-06-28 21:54:41 +00:00
|
|
|
}, time);
|
|
|
|
break;
|
|
|
|
case 'clearTimeout':
|
2015-07-10 16:08:01 +00:00
|
|
|
if (fakeIdToId.hasOwnProperty (fakeId)) {
|
|
|
|
clearTimeout(fakeIdToId[fakeId]);
|
|
|
|
delete fakeIdToId[fakeId];
|
|
|
|
}
|
2015-06-28 21:54:41 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|