Convert clearStack from a function to an object

This commit is contained in:
Steve Gravrock
2025-11-11 11:43:18 -08:00
parent e930622548
commit 7b2807b321
9 changed files with 242 additions and 210 deletions

View File

@@ -20,7 +20,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() {
@@ -301,7 +301,7 @@ getJasmineRequireObj().Env = function(j$) {
};
function runQueue(options) {
options.clearStack = options.clearStack || clearStack;
options.clearStack = options.clearStack || stackClearer;
options.timeout = {
setTimeout: realSetTimeout,
clearTimeout: realClearTimeout

View File

@@ -51,11 +51,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();
@@ -235,7 +235,7 @@ getJasmineRequireObj().QueueRunner = function(j$) {
}
}
this.clearStack(() => {
this.clearStack.clearStack(() => {
this.globalErrors.popListener(this.handleFinalError);
if (this.errored_) {

View File

@@ -1,4 +1,4 @@
getJasmineRequireObj().clearStack = function(j$) {
getJasmineRequireObj().StackClearer = function(j$) {
'use strict';
const maxInlineCallCount = 10;
@@ -7,14 +7,17 @@ getJasmineRequireObj().clearStack = function(j$) {
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);
return {
clearStack(fn) {
currentCallCount++;
if (currentCallCount < maxInlineCallCount) {
queueMicrotask(fn);
} else {
currentCallCount = 0;
unclampedSetTimeout(fn);
}
}
};
}
@@ -22,8 +25,10 @@ getJasmineRequireObj().clearStack = function(j$) {
function nodeQueueMicrotaskImpl(global) {
const { queueMicrotask } = global;
return function(fn) {
queueMicrotask(fn);
return {
clearStack(fn) {
queueMicrotask(fn);
}
};
}
@@ -32,14 +37,17 @@ getJasmineRequireObj().clearStack = function(j$) {
const postMessage = getPostMessage(global);
let currentCallCount = 0;
return function clearStack(fn) {
currentCallCount++;
if (currentCallCount < maxInlineCallCount) {
postMessage(fn);
} else {
currentCallCount = 0;
setTimeout(fn);
return {
clearStack(fn) {
currentCallCount++;
if (currentCallCount < maxInlineCallCount) {
postMessage(fn);
} else {
currentCallCount = 0;
setTimeout(fn);
}
}
};
}
@@ -88,7 +96,7 @@ getJasmineRequireObj().clearStack = function(j$) {
};
}
function getClearStack(global) {
function getStackClearer(global) {
const NODE_JS =
global.process &&
global.process.versions &&
@@ -120,5 +128,5 @@ getJasmineRequireObj().clearStack = function(j$) {
}
}
return getClearStack;
return getStackClearer;
};

View File

@@ -31,7 +31,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$);