Don't use window

This commit is contained in:
Gregg Van Hove
2017-06-15 14:32:18 -07:00
parent c60d669940
commit 2e737f50ca
2 changed files with 31 additions and 10 deletions

View File

@@ -138,6 +138,7 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
j$.MAX_PRETTY_PRINT_DEPTH = 40;
/**
* Maximum number of array elements to display when pretty printing objects.
* This will also limit the number of keys and values displayed for an object.
* Elements past this number will be ellipised.
* @name jasmine.MAX_PRETTY_PRINT_ARRAY_LENGTH
*/
@@ -1611,7 +1612,9 @@ getJasmineRequireObj().CallTracker = function(j$) {
};
getJasmineRequireObj().clearStack = function(j$) {
function messageChannelImpl(global) {
var maxInlineCallCount = 10;
function messageChannelImpl(global, setTimeout) {
var channel = new global.MessageChannel(),
head = {},
tail = head;
@@ -1634,25 +1637,43 @@ getJasmineRequireObj().clearStack = function(j$) {
}
};
var currentCallCount = 0;
return function clearStack(fn) {
tail = tail.next = { task: fn };
channel.port2.postMessage(0);
currentCallCount++;
if (currentCallCount < maxInlineCallCount) {
tail = tail.next = { task: fn };
channel.port2.postMessage(0);
} else {
setTimeout(fn);
}
};
}
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)) {
var realSetImmediate = global.setImmediate;
return function(fn) {
realSetImmediate(fn);
currentCallCount++;
if (currentCallCount < maxInlineCallCount) {
realSetImmediate(fn);
} else {
currentCallCount = 0;
setTimeoutImpl(fn);
}
};
} else if (!j$.util.isUndefined(global.MessageChannel)) {
return messageChannelImpl(global);
return messageChannelImpl(global, setTimeoutImpl);
} else {
var realSetTimeout = global.setTimeout;
return function clearStack(fn) {
Function.prototype.apply.apply(realSetTimeout, [global, [fn, 0]]);
};
return setTimeoutImpl;
}
}

View File

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