Convert clearStack from a function to an object
This commit is contained in:
@@ -55,7 +55,7 @@ var getJasmineRequireObj = (function() {
|
||||
j$.private.Anything = jRequire.Anything(j$);
|
||||
j$.private.CallTracker = jRequire.CallTracker(j$);
|
||||
j$.private.MockDate = jRequire.MockDate(j$);
|
||||
j$.private.getClearStack = jRequire.clearStack(j$);
|
||||
j$.private.getStackClearer = jRequire.StackClearer(j$);
|
||||
j$.private.Clock = jRequire.Clock();
|
||||
j$.private.DelayedFunctionScheduler = jRequire.DelayedFunctionScheduler(j$);
|
||||
j$.private.Deprecator = jRequire.Deprecator(j$);
|
||||
@@ -1244,7 +1244,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
|
||||
const realSetTimeout = global.setTimeout;
|
||||
const realClearTimeout = global.clearTimeout;
|
||||
const clearStack = j$.private.getClearStack(global);
|
||||
const stackClearer = j$.private.getStackClearer(global);
|
||||
this.clock = new j$.private.Clock(
|
||||
global,
|
||||
function() {
|
||||
@@ -1525,7 +1525,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
};
|
||||
|
||||
function runQueue(options) {
|
||||
options.clearStack = options.clearStack || clearStack;
|
||||
options.clearStack = options.clearStack || stackClearer;
|
||||
options.timeout = {
|
||||
setTimeout: realSetTimeout,
|
||||
clearTimeout: realClearTimeout
|
||||
@@ -2919,131 +2919,6 @@ getJasmineRequireObj().CallTracker = function(j$) {
|
||||
return CallTracker;
|
||||
};
|
||||
|
||||
getJasmineRequireObj().clearStack = function(j$) {
|
||||
'use strict';
|
||||
|
||||
const maxInlineCallCount = 10;
|
||||
|
||||
function browserQueueMicrotaskImpl(global) {
|
||||
const unclampedSetTimeout = getUnclampedSetTimeout(global);
|
||||
const { queueMicrotask } = global;
|
||||
let currentCallCount = 0;
|
||||
return function clearStack(fn) {
|
||||
currentCallCount++;
|
||||
|
||||
if (currentCallCount < maxInlineCallCount) {
|
||||
queueMicrotask(fn);
|
||||
} else {
|
||||
currentCallCount = 0;
|
||||
unclampedSetTimeout(fn);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function nodeQueueMicrotaskImpl(global) {
|
||||
const { queueMicrotask } = global;
|
||||
|
||||
return function(fn) {
|
||||
queueMicrotask(fn);
|
||||
};
|
||||
}
|
||||
|
||||
function messageChannelImpl(global) {
|
||||
const { setTimeout } = global;
|
||||
const postMessage = getPostMessage(global);
|
||||
|
||||
let currentCallCount = 0;
|
||||
return function clearStack(fn) {
|
||||
currentCallCount++;
|
||||
|
||||
if (currentCallCount < maxInlineCallCount) {
|
||||
postMessage(fn);
|
||||
} else {
|
||||
currentCallCount = 0;
|
||||
setTimeout(fn);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function getUnclampedSetTimeout(global) {
|
||||
const { setTimeout } = global;
|
||||
if (!global.MessageChannel) {
|
||||
return setTimeout;
|
||||
}
|
||||
|
||||
const postMessage = getPostMessage(global);
|
||||
return function unclampedSetTimeout(fn) {
|
||||
postMessage(function() {
|
||||
setTimeout(fn);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function getPostMessage(global) {
|
||||
const { MessageChannel, setTimeout } = global;
|
||||
const channel = new MessageChannel();
|
||||
let head = {};
|
||||
let tail = head;
|
||||
|
||||
let taskRunning = false;
|
||||
channel.port1.onmessage = function() {
|
||||
head = head.next;
|
||||
const task = head.task;
|
||||
delete head.task;
|
||||
|
||||
if (taskRunning) {
|
||||
setTimeout(task, 0);
|
||||
} else {
|
||||
try {
|
||||
taskRunning = true;
|
||||
task();
|
||||
} finally {
|
||||
taskRunning = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return function postMessage(fn) {
|
||||
tail = tail.next = { task: fn };
|
||||
channel.port2.postMessage(0);
|
||||
};
|
||||
}
|
||||
|
||||
function getClearStack(global) {
|
||||
const NODE_JS =
|
||||
global.process &&
|
||||
global.process.versions &&
|
||||
typeof global.process.versions.node === 'string';
|
||||
|
||||
// Windows builds of WebKit have a fairly generic user agent string when no application name is provided:
|
||||
// e.g. "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/605.1.15 (KHTML, like Gecko)"
|
||||
const SAFARI_OR_WIN_WEBKIT =
|
||||
global.navigator &&
|
||||
/(^((?!chrome|android).)*safari)|(Win64; x64\) AppleWebKit\/[0-9.]+ \(KHTML, like Gecko\)$)/i.test(
|
||||
global.navigator.userAgent
|
||||
);
|
||||
|
||||
if (NODE_JS) {
|
||||
// Unlike browsers, Node doesn't require us to do a periodic setTimeout
|
||||
// so we avoid the overhead.
|
||||
return nodeQueueMicrotaskImpl(global);
|
||||
} else if (SAFARI_OR_WIN_WEBKIT || !global.MessageChannel /* tests */) {
|
||||
// queueMicrotask is dramatically faster than MessageChannel in Safari
|
||||
// and other WebKit-based browsers, such as the one distributed by Playwright
|
||||
// to test Safari-like behavior on Windows.
|
||||
// Some of our own integration tests provide a mock queueMicrotask in all
|
||||
// environments because it's simpler to mock than MessageChannel.
|
||||
return browserQueueMicrotaskImpl(global);
|
||||
} else {
|
||||
// MessageChannel is faster than queueMicrotask in supported browsers
|
||||
// other than Safari.
|
||||
return messageChannelImpl(global);
|
||||
}
|
||||
}
|
||||
|
||||
return getClearStack;
|
||||
};
|
||||
|
||||
getJasmineRequireObj().Clock = function() {
|
||||
'use strict';
|
||||
|
||||
@@ -8663,11 +8538,11 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
}
|
||||
|
||||
this.onComplete = attrs.onComplete || emptyFn;
|
||||
this.clearStack =
|
||||
attrs.clearStack ||
|
||||
function(fn) {
|
||||
this.clearStack = attrs.clearStack || {
|
||||
clearStack(fn) {
|
||||
fn();
|
||||
};
|
||||
}
|
||||
};
|
||||
this.onException = attrs.onException || emptyFn;
|
||||
this.onMultipleDone = attrs.onMultipleDone || fallbackOnMultipleDone;
|
||||
this.userContext = attrs.userContext || new j$.private.UserContext();
|
||||
@@ -8847,7 +8722,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
|
||||
}
|
||||
}
|
||||
|
||||
this.clearStack(() => {
|
||||
this.clearStack.clearStack(() => {
|
||||
this.globalErrors.popListener(this.handleFinalError);
|
||||
|
||||
if (this.errored_) {
|
||||
@@ -10783,6 +10658,139 @@ getJasmineRequireObj().SpyStrategy = function(j$) {
|
||||
return SpyStrategy;
|
||||
};
|
||||
|
||||
getJasmineRequireObj().StackClearer = function(j$) {
|
||||
'use strict';
|
||||
|
||||
const maxInlineCallCount = 10;
|
||||
|
||||
function browserQueueMicrotaskImpl(global) {
|
||||
const unclampedSetTimeout = getUnclampedSetTimeout(global);
|
||||
const { queueMicrotask } = global;
|
||||
let currentCallCount = 0;
|
||||
|
||||
return {
|
||||
clearStack(fn) {
|
||||
currentCallCount++;
|
||||
|
||||
if (currentCallCount < maxInlineCallCount) {
|
||||
queueMicrotask(fn);
|
||||
} else {
|
||||
currentCallCount = 0;
|
||||
unclampedSetTimeout(fn);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function nodeQueueMicrotaskImpl(global) {
|
||||
const { queueMicrotask } = global;
|
||||
|
||||
return {
|
||||
clearStack(fn) {
|
||||
queueMicrotask(fn);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function messageChannelImpl(global) {
|
||||
const { setTimeout } = global;
|
||||
const postMessage = getPostMessage(global);
|
||||
|
||||
let currentCallCount = 0;
|
||||
|
||||
return {
|
||||
clearStack(fn) {
|
||||
currentCallCount++;
|
||||
|
||||
if (currentCallCount < maxInlineCallCount) {
|
||||
postMessage(fn);
|
||||
} else {
|
||||
currentCallCount = 0;
|
||||
setTimeout(fn);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function getUnclampedSetTimeout(global) {
|
||||
const { setTimeout } = global;
|
||||
if (!global.MessageChannel) {
|
||||
return setTimeout;
|
||||
}
|
||||
|
||||
const postMessage = getPostMessage(global);
|
||||
return function unclampedSetTimeout(fn) {
|
||||
postMessage(function() {
|
||||
setTimeout(fn);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
function getPostMessage(global) {
|
||||
const { MessageChannel, setTimeout } = global;
|
||||
const channel = new MessageChannel();
|
||||
let head = {};
|
||||
let tail = head;
|
||||
|
||||
let taskRunning = false;
|
||||
channel.port1.onmessage = function() {
|
||||
head = head.next;
|
||||
const task = head.task;
|
||||
delete head.task;
|
||||
|
||||
if (taskRunning) {
|
||||
setTimeout(task, 0);
|
||||
} else {
|
||||
try {
|
||||
taskRunning = true;
|
||||
task();
|
||||
} finally {
|
||||
taskRunning = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return function postMessage(fn) {
|
||||
tail = tail.next = { task: fn };
|
||||
channel.port2.postMessage(0);
|
||||
};
|
||||
}
|
||||
|
||||
function getStackClearer(global) {
|
||||
const NODE_JS =
|
||||
global.process &&
|
||||
global.process.versions &&
|
||||
typeof global.process.versions.node === 'string';
|
||||
|
||||
// Windows builds of WebKit have a fairly generic user agent string when no application name is provided:
|
||||
// e.g. "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/605.1.15 (KHTML, like Gecko)"
|
||||
const SAFARI_OR_WIN_WEBKIT =
|
||||
global.navigator &&
|
||||
/(^((?!chrome|android).)*safari)|(Win64; x64\) AppleWebKit\/[0-9.]+ \(KHTML, like Gecko\)$)/i.test(
|
||||
global.navigator.userAgent
|
||||
);
|
||||
|
||||
if (NODE_JS) {
|
||||
// Unlike browsers, Node doesn't require us to do a periodic setTimeout
|
||||
// so we avoid the overhead.
|
||||
return nodeQueueMicrotaskImpl(global);
|
||||
} else if (SAFARI_OR_WIN_WEBKIT || !global.MessageChannel /* tests */) {
|
||||
// queueMicrotask is dramatically faster than MessageChannel in Safari
|
||||
// and other WebKit-based browsers, such as the one distributed by Playwright
|
||||
// to test Safari-like behavior on Windows.
|
||||
// Some of our own integration tests provide a mock queueMicrotask in all
|
||||
// environments because it's simpler to mock than MessageChannel.
|
||||
return browserQueueMicrotaskImpl(global);
|
||||
} else {
|
||||
// MessageChannel is faster than queueMicrotask in supported browsers
|
||||
// other than Safari.
|
||||
return messageChannelImpl(global);
|
||||
}
|
||||
}
|
||||
|
||||
return getStackClearer;
|
||||
};
|
||||
|
||||
getJasmineRequireObj().StackTrace = function(j$) {
|
||||
'use strict';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user