Update fakeworker.js

This commit is contained in:
Namhyeon Go 2022-10-28 01:31:20 +09:00
parent e190b98a5e
commit de8d37bc57

View File

@ -24,32 +24,23 @@ function FakeWorker() {
}; };
this.clearInterval = function(intervalID) { this.clearInterval = function(intervalID) {
if (!this.__isWindow__) {
for (var i = 0; i < this.__intervals__.length; i++) { for (var i = 0; i < this.__intervals__.length; i++) {
if (this.__intervals__[i].id == intervalID) { if (this.__intervals__[i].id == intervalID) {
this.__intervals__[i].cleared = true; this.__intervals__[i].cleared = true;
break; break;
} }
} }
} else {
return this.clearInterval.apply(null, arguments);
}
}; };
this.clearTimeout = function(timeoutID) { this.clearTimeout = function(timeoutID) {
if (!this.__isWindow__) {
for (var i = 0; i < this.__timeouts__.length; i++) { for (var i = 0; i < this.__timeouts__.length; i++) {
if (this.__timeouts__[i].id == timeoutID) { if (this.__timeouts__[i].id == timeoutID) {
this.__timeouts__[i].cleared = true; this.__timeouts__[i].cleared = true;
} }
} }
} else {
return this.clearTimeout.apply(null, arguments);
}
}; };
this.setInterval = function(code, delay) { this.setInterval = function(code, delay) {
if (!this.__isWindow__) {
this.__lastIntervalID__++; this.__lastIntervalID__++;
this.__intervals__.push({ this.__intervals__.push({
'id': this.__lastIntervalID__, 'id': this.__lastIntervalID__,
@ -61,13 +52,9 @@ function FakeWorker() {
'callback': null 'callback': null
}); });
return this.__lastIntervalID__; return this.__lastIntervalID__;
} else {
return window.setInterval.apply(null, arguments);
}
}; };
this.setTimeout = function(code, delay) { this.setTimeout = function(code, delay) {
if (!this.__isWindow__) {
this.__lastTimeoutID__++; this.__lastTimeoutID__++;
this.__timeouts__.push({ this.__timeouts__.push({
'id': this.__lastTimeoutID__, 'id': this.__lastTimeoutID__,
@ -78,12 +65,9 @@ function FakeWorker() {
'cleared': false 'cleared': false
}); });
return this.__lastTimeoutID__; return this.__lastTimeoutID__;
} else {
return window.setTimeout.apply(null, arguments);
}
}; };
this.__setIntervalWithCallback__ = function(code, callback) { this.setIntervalWithCallback = function(code, callback) {
this.__lastIntervalID__++; this.__lastIntervalID__++;
this.__intervals__.push({ this.__intervals__.push({
'id': this.__lastIntervalID__, 'id': this.__lastIntervalID__,
@ -97,7 +81,7 @@ function FakeWorker() {
return this.__lastIntervalID__; return this.__lastIntervalID__;
}; };
this.__getIntervals__ = function() { this.getIntervals = function() {
var intervals = []; var intervals = [];
var cur = Date.now(); var cur = Date.now();
@ -114,7 +98,7 @@ function FakeWorker() {
return intervals; return intervals;
}; };
this.__getTimeouts__ = function() { this.getTimeouts = function() {
var timeouts = []; var timeouts = [];
var cur = Date.now(); var cur = Date.now();