Update fakeworker.js

This commit is contained in:
Namhyeon Go 2022-10-28 01:22:44 +09:00
parent 9e3b4c1327
commit 44914f7067

View File

@ -27,7 +27,7 @@ function FakeWorker() {
if (!this.__isWindow__) {
for (var i = 0; i < this.__intervals__.length; i++) {
if (this.__intervals__[i].id == intervalID) {
delete this.__intervals__[i];
this.__intervals__[i].cleared = true;
break;
}
}
@ -40,8 +40,7 @@ function FakeWorker() {
if (!this.__isWindow__) {
for (var i = 0; i < this.__timeouts__.length; i++) {
if (this.__timeouts__[i].id == timeoutID) {
delete this.__timeouts__[i];
break;
this.__timeouts__[i].cleared = true;
}
}
} else {
@ -57,7 +56,8 @@ function FakeWorker() {
'code': code,
'delay': delay,
'arguments': (arguments.length > 2 ? arguments.slice(2) : []),
'timestamp': Date.now()
'timestamp': Date.now(),
'cleared': false
});
return this.__lastIntervalID__;
} else {
@ -73,13 +73,42 @@ function FakeWorker() {
'code': code,
'delay': delay,
'arguments': (arguments.length > 2 ? arguments.slice(2) : []),
'timestamp': Date.now()
'timestamp': Date.now(),
'cleared': false
});
return this.__lastTimeoutID__;
} else {
return window.setTimeout.apply(null, arguments);
}
};
this.getIntervals = function() {
var intervals = [];
var cur = Date.now();
for (var i = 0; i < this.__intervals__.length; i++) {
if (!this.__intervals__[i].cleared && (this.__intervals__[i].timestamp + this.__intervals__[i].delay) >= cur) {
intervals.push(this.__intervals__[i]);
this.__intervals__[i].timestamp = cur;
}
}
return intervals;
};
this.getTimeouts = function() {
var timeouts = [];
var cur = Date.now();
for (var i = 0; i < this.__timeouts__.length; i++) {
if (!this.__timeouts__[i].cleared && (this.__timeouts__[i].timestamp + this.__timeouts__[i].delay) >= cur) {
timeouts.push(this.__timeouts__[i]);
this.__timeouts__[i].cleared = true;
}
}
return timeouts;
};
}
exports.create = function() {