Don't use window

This commit is contained in:
Gregg Van Hove
2017-06-15 14:33:23 -07:00
parent b38decf050
commit eb4671452e
2 changed files with 30 additions and 10 deletions

View File

@@ -1600,7 +1600,9 @@ getJasmineRequireObj().CallTracker = function(j$) {
}; };
getJasmineRequireObj().clearStack = function(j$) { getJasmineRequireObj().clearStack = function(j$) {
function messageChannelImpl(global) { var maxInlineCallCount = 10;
function messageChannelImpl(global, setTimeout) {
var channel = new global.MessageChannel(), var channel = new global.MessageChannel(),
head = {}, head = {},
tail = head; tail = head;
@@ -1623,25 +1625,43 @@ getJasmineRequireObj().clearStack = function(j$) {
} }
}; };
var currentCallCount = 0;
return function clearStack(fn) { return function clearStack(fn) {
tail = tail.next = { task: fn }; currentCallCount++;
channel.port2.postMessage(0);
if (currentCallCount < maxInlineCallCount) {
tail = tail.next = { task: fn };
channel.port2.postMessage(0);
} else {
setTimeout(fn);
}
}; };
} }
function getClearStack(global) { function getClearStack(global) {
var currentCallCount = 0;
var realSetTimeout = global.setTimeout;
var setTimeoutImpl = function clearStack(fn) {
Function.prototype.apply.apply(realSetTimeout, [global, [fn, 0]]);
};
if (j$.isFunction_(global.setImmediate)) { if (j$.isFunction_(global.setImmediate)) {
var realSetImmediate = global.setImmediate; var realSetImmediate = global.setImmediate;
return function(fn) { return function(fn) {
realSetImmediate(fn); currentCallCount++;
if (currentCallCount < maxInlineCallCount) {
realSetImmediate(fn);
} else {
currentCallCount = 0;
setTimeoutImpl(fn);
}
}; };
} else if (!j$.util.isUndefined(global.MessageChannel)) { } else if (!j$.util.isUndefined(global.MessageChannel)) {
return messageChannelImpl(global); return messageChannelImpl(global, setTimeoutImpl);
} else { } else {
var realSetTimeout = global.setTimeout; return setTimeoutImpl;
return function clearStack(fn) {
Function.prototype.apply.apply(realSetTimeout, [global, [fn, 0]]);
};
} }
} }

View File

@@ -954,7 +954,7 @@ describe("Env integration", function() {
describe("with a mock clock", function() { describe("with a mock clock", function() {
beforeEach(function() { beforeEach(function() {
this.originalTimeout = jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL; this.originalTimeout = jasmineUnderTest.DEFAULT_TIMEOUT_INTERVAL;
this.realSetTimeout = window.setTimeout; this.realSetTimeout = setTimeout;
jasmine.clock().install(); jasmine.clock().install();
}); });