mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-11-27 18:11:20 +00:00
Update fakeworker.js
This commit is contained in:
parent
e190b98a5e
commit
de8d37bc57
|
|
@ -24,66 +24,50 @@ function FakeWorker() {
|
|||
};
|
||||
|
||||
this.clearInterval = function(intervalID) {
|
||||
if (!this.__isWindow__) {
|
||||
for (var i = 0; i < this.__intervals__.length; i++) {
|
||||
if (this.__intervals__[i].id == intervalID) {
|
||||
this.__intervals__[i].cleared = true;
|
||||
break;
|
||||
}
|
||||
for (var i = 0; i < this.__intervals__.length; i++) {
|
||||
if (this.__intervals__[i].id == intervalID) {
|
||||
this.__intervals__[i].cleared = true;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
return this.clearInterval.apply(null, arguments);
|
||||
}
|
||||
};
|
||||
|
||||
this.clearTimeout = function(timeoutID) {
|
||||
if (!this.__isWindow__) {
|
||||
for (var i = 0; i < this.__timeouts__.length; i++) {
|
||||
if (this.__timeouts__[i].id == timeoutID) {
|
||||
this.__timeouts__[i].cleared = true;
|
||||
}
|
||||
for (var i = 0; i < this.__timeouts__.length; i++) {
|
||||
if (this.__timeouts__[i].id == timeoutID) {
|
||||
this.__timeouts__[i].cleared = true;
|
||||
}
|
||||
} else {
|
||||
return this.clearTimeout.apply(null, arguments);
|
||||
}
|
||||
};
|
||||
|
||||
this.setInterval = function(code, delay) {
|
||||
if (!this.__isWindow__) {
|
||||
this.__lastIntervalID__++;
|
||||
this.__intervals__.push({
|
||||
'id': this.__lastIntervalID__,
|
||||
'code': code,
|
||||
'delay': delay,
|
||||
'arguments': (arguments.length > 2 ? arguments.slice(2) : []),
|
||||
'timestamp': Date.now(),
|
||||
'cleared': false,
|
||||
'callback': null
|
||||
});
|
||||
return this.__lastIntervalID__;
|
||||
} else {
|
||||
return window.setInterval.apply(null, arguments);
|
||||
}
|
||||
this.__lastIntervalID__++;
|
||||
this.__intervals__.push({
|
||||
'id': this.__lastIntervalID__,
|
||||
'code': code,
|
||||
'delay': delay,
|
||||
'arguments': (arguments.length > 2 ? arguments.slice(2) : []),
|
||||
'timestamp': Date.now(),
|
||||
'cleared': false,
|
||||
'callback': null
|
||||
});
|
||||
return this.__lastIntervalID__;
|
||||
};
|
||||
|
||||
this.setTimeout = function(code, delay) {
|
||||
if (!this.__isWindow__) {
|
||||
this.__lastTimeoutID__++;
|
||||
this.__timeouts__.push({
|
||||
'id': this.__lastTimeoutID__,
|
||||
'code': code,
|
||||
'delay': delay,
|
||||
'arguments': (arguments.length > 2 ? arguments.slice(2) : []),
|
||||
'timestamp': Date.now(),
|
||||
'cleared': false
|
||||
});
|
||||
return this.__lastTimeoutID__;
|
||||
} else {
|
||||
return window.setTimeout.apply(null, arguments);
|
||||
}
|
||||
this.__lastTimeoutID__++;
|
||||
this.__timeouts__.push({
|
||||
'id': this.__lastTimeoutID__,
|
||||
'code': code,
|
||||
'delay': delay,
|
||||
'arguments': (arguments.length > 2 ? arguments.slice(2) : []),
|
||||
'timestamp': Date.now(),
|
||||
'cleared': false
|
||||
});
|
||||
return this.__lastTimeoutID__;
|
||||
};
|
||||
|
||||
this.__setIntervalWithCallback__ = function(code, callback) {
|
||||
this.setIntervalWithCallback = function(code, callback) {
|
||||
this.__lastIntervalID__++;
|
||||
this.__intervals__.push({
|
||||
'id': this.__lastIntervalID__,
|
||||
|
|
@ -97,7 +81,7 @@ function FakeWorker() {
|
|||
return this.__lastIntervalID__;
|
||||
};
|
||||
|
||||
this.__getIntervals__ = function() {
|
||||
this.getIntervals = function() {
|
||||
var intervals = [];
|
||||
var cur = Date.now();
|
||||
|
||||
|
|
@ -114,10 +98,10 @@ function FakeWorker() {
|
|||
return intervals;
|
||||
};
|
||||
|
||||
this.__getTimeouts__ = function() {
|
||||
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]);
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user