From 7b2807b3212e98203582f11dc21abf9d3a5a61cd Mon Sep 17 00:00:00 2001 From: Steve Gravrock Date: Tue, 11 Nov 2025 11:43:18 -0800 Subject: [PATCH] Convert clearStack from a function to an object --- lib/jasmine-core/jasmine.js | 274 +++++++++--------- spec/core/QueueRunnerSpec.js | 14 +- ...{ClearStackSpec.js => StackClearerSpec.js} | 20 +- spec/core/integration/EnvSpec.js | 38 ++- .../integration/GlobalErrorHandlingSpec.js | 44 ++- src/core/Env.js | 4 +- src/core/QueueRunner.js | 10 +- src/core/{ClearStack.js => StackClearer.js} | 46 +-- src/core/requireCore.js | 2 +- 9 files changed, 242 insertions(+), 210 deletions(-) rename spec/core/{ClearStackSpec.js => StackClearerSpec.js} (91%) rename src/core/{ClearStack.js => StackClearer.js} (82%) diff --git a/lib/jasmine-core/jasmine.js b/lib/jasmine-core/jasmine.js index ca6d8f14..14a13a01 100644 --- a/lib/jasmine-core/jasmine.js +++ b/lib/jasmine-core/jasmine.js @@ -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'; diff --git a/spec/core/QueueRunnerSpec.js b/spec/core/QueueRunnerSpec.js index 26004d33..bfc22490 100644 --- a/spec/core/QueueRunnerSpec.js +++ b/spec/core/QueueRunnerSpec.js @@ -486,7 +486,7 @@ describe('QueueRunner', function() { errorListeners.pop(); } }, - clearStack = jasmine.createSpy('clearStack'), + clearStack = jasmine.createSpyObj('clearStack', ['clearStack']), onException = jasmine.createSpy('onException'), queueRunner = new privateUnderTest.QueueRunner({ queueableFns: [queueableFn], @@ -498,10 +498,10 @@ describe('QueueRunner', function() { queueRunner.execute(); jasmine.clock().tick(); - expect(clearStack).toHaveBeenCalled(); + expect(clearStack.clearStack).toHaveBeenCalled(); expect(errorListeners.length).toEqual(1); errorListeners[0](error); - clearStack.calls.argsFor(0)[0](); + clearStack.clearStack.calls.argsFor(0)[0](); expect(onException).toHaveBeenCalledWith(error); }); }); @@ -908,22 +908,22 @@ describe('QueueRunner', function() { }, afterFn = { fn: jasmine.createSpy('afterFn') }, completeCallback = jasmine.createSpy('completeCallback'), - clearStack = jasmine.createSpy('clearStack'), + clearStack = jasmine.createSpyObj('clearStack', ['clearStack']), queueRunner = new privateUnderTest.QueueRunner({ queueableFns: [asyncFn, afterFn], clearStack: clearStack, onComplete: completeCallback }); - clearStack.and.callFake(function(fn) { + clearStack.clearStack.and.callFake(function(fn) { fn(); }); queueRunner.execute(); jasmine.clock().tick(); expect(afterFn.fn).toHaveBeenCalled(); - expect(clearStack).toHaveBeenCalled(); - clearStack.calls.argsFor(0)[0](); + expect(clearStack.clearStack).toHaveBeenCalled(); + clearStack.clearStack.calls.argsFor(0)[0](); expect(completeCallback).toHaveBeenCalled(); }); }); diff --git a/spec/core/ClearStackSpec.js b/spec/core/StackClearerSpec.js similarity index 91% rename from spec/core/ClearStackSpec.js rename to spec/core/StackClearerSpec.js index 8b2aff34..c015990a 100644 --- a/spec/core/ClearStackSpec.js +++ b/spec/core/StackClearerSpec.js @@ -1,6 +1,6 @@ -describe('ClearStack', function() { +describe('StackClearer', function() { it('works in an integrationy way', function(done) { - const clearStack = privateUnderTest.getClearStack( + const { clearStack } = privateUnderTest.getStackClearer( jasmineUnderTest.getGlobal() ); @@ -36,7 +36,7 @@ describe('ClearStack', function() { queueMicrotask }; - const clearStack = privateUnderTest.getClearStack(global); + const { clearStack } = privateUnderTest.getStackClearer(global); for (let i = 0; i < 9; i++) { clearStack(function() {}); @@ -104,7 +104,7 @@ describe('ClearStack', function() { ...makeGlobal(), MessageChannel: fakeMessageChannel }; - const clearStack = privateUnderTest.getClearStack(global); + const { clearStack } = privateUnderTest.getStackClearer(global); let called = false; clearStack(function() { @@ -125,7 +125,7 @@ describe('ClearStack', function() { return fakeChannel; } }; - const clearStack = privateUnderTest.getClearStack(global); + const { clearStack } = privateUnderTest.getStackClearer(global); for (let i = 0; i < 9; i++) { clearStack(function() {}); @@ -150,7 +150,7 @@ describe('ClearStack', function() { setTimeout, MessageChannel: fakeMessageChannel }; - const clearStack = privateUnderTest.getClearStack(global); + const { clearStack } = privateUnderTest.getStackClearer(global); const fn = jasmine.createSpy('second clearStack function'); clearStack(function() { @@ -170,7 +170,7 @@ describe('ClearStack', function() { fn(); } }; - const clearStack = privateUnderTest.getClearStack(global); + const { clearStack } = privateUnderTest.getStackClearer(global); let called = false; clearStack(function() { @@ -188,7 +188,7 @@ describe('ClearStack', function() { queueMicrotask, setTimeout }; - const clearStack = privateUnderTest.getClearStack(global); + const { clearStack } = privateUnderTest.getStackClearer(global); for (let i = 0; i < 9; i++) { clearStack(function() {}); @@ -215,7 +215,7 @@ describe('ClearStack', function() { fn(); } }; - const clearStack = privateUnderTest.getClearStack(global); + const { clearStack } = privateUnderTest.getStackClearer(global); let called = false; clearStack(function() { @@ -233,7 +233,7 @@ describe('ClearStack', function() { queueMicrotask, setTimeout }; - const clearStack = privateUnderTest.getClearStack(global); + const { clearStack } = privateUnderTest.getStackClearer(global); clearStack(function() {}); clearStack(function() {}); diff --git a/spec/core/integration/EnvSpec.js b/spec/core/integration/EnvSpec.js index 2bb81ef0..9c4c9c47 100644 --- a/spec/core/integration/EnvSpec.js +++ b/spec/core/integration/EnvSpec.js @@ -1181,7 +1181,7 @@ describe('Env integration', function() { global: { setTimeout: function(cb, t) { const stack = new Error().stack; - if (stack.indexOf('ClearStack') >= 0) { + if (stack.indexOf('clearStack') >= 0) { return realSetTimeout(cb, t); } else { return setTimeout(cb, t); @@ -3259,13 +3259,11 @@ describe('Env integration', function() { }); it('is resolved after the stack is cleared', function(done) { - const realClearStack = privateUnderTest.getClearStack( - jasmineUnderTest.getGlobal() - ), - clearStackSpy = jasmine - .createSpy('clearStack') - .and.callFake(realClearStack); - spyOn(privateUnderTest, 'getClearStack').and.returnValue(clearStackSpy); + const stackClearer = privateUnderTest.getStackClearer( + jasmineUnderTest.getGlobal() + ); + spyOn(stackClearer, 'clearStack').and.callThrough(); + spyOn(privateUnderTest, 'getStackClearer').and.returnValue(stackClearer); // Create a new env that has the clearStack defined above env.cleanup_(); @@ -3276,10 +3274,10 @@ describe('Env integration', function() { }); env.execute(null).then(function() { - expect(clearStackSpy).toHaveBeenCalled(); // (many times) - clearStackSpy.calls.reset(); + expect(stackClearer.clearStack).toHaveBeenCalled(); // (many times) + stackClearer.clearStack.calls.reset(); setTimeout(function() { - expect(clearStackSpy).not.toHaveBeenCalled(); + expect(stackClearer.clearStack).not.toHaveBeenCalled(); done(); }); }); @@ -3368,13 +3366,11 @@ describe('Env integration', function() { }); it('is called after the stack is cleared', async function() { - const realClearStack = privateUnderTest.getClearStack( - jasmineUnderTest.getGlobal() - ), - clearStackSpy = jasmine - .createSpy('clearStack') - .and.callFake(realClearStack); - spyOn(privateUnderTest, 'getClearStack').and.returnValue(clearStackSpy); + const stackClearer = privateUnderTest.getStackClearer( + jasmineUnderTest.getGlobal() + ); + spyOn(stackClearer, 'clearStack').and.callThrough(); + spyOn(privateUnderTest, 'getStackClearer').and.returnValue(stackClearer); // Create a new env that has the clearStack defined above env.cleanup_(); @@ -3386,12 +3382,12 @@ describe('Env integration', function() { await env.execute(); - expect(clearStackSpy).toHaveBeenCalled(); // (many times) - clearStackSpy.calls.reset(); + expect(stackClearer.clearStack).toHaveBeenCalled(); // (many times) + stackClearer.clearStack.calls.reset(); await new Promise(resolve => setTimeout(resolve)); - expect(clearStackSpy).not.toHaveBeenCalled(); + expect(stackClearer.clearStack).not.toHaveBeenCalled(); }); it('is called after QueueRunner timeouts are cleared', async function() { diff --git a/spec/core/integration/GlobalErrorHandlingSpec.js b/spec/core/integration/GlobalErrorHandlingSpec.js index b9e77bb2..27fb96a5 100644 --- a/spec/core/integration/GlobalErrorHandlingSpec.js +++ b/spec/core/integration/GlobalErrorHandlingSpec.js @@ -167,10 +167,11 @@ describe('Global error handling (integration)', function() { } }; - const realClearStack = privateUnderTest.getClearStack(global); + const stackClearer = privateUnderTest.getStackClearer(global); + const realClearStack = stackClearer.clearStack; const clearStackCallbacks = {}; let clearStackCallCount = 0; - spyOn(privateUnderTest, 'getClearStack').and.returnValue(function(fn) { + spyOn(stackClearer, 'clearStack').and.callFake(function(fn) { clearStackCallCount++; if (clearStackCallbacks[clearStackCallCount]) { @@ -179,6 +180,9 @@ describe('Global error handling (integration)', function() { realClearStack(fn); }); + spyOn(privateUnderTest, 'getStackClearer').and.returnValue( + stackClearer + ); env.cleanup_(); env = new privateUnderTest.Env({ global }); @@ -282,10 +286,11 @@ describe('Global error handling (integration)', function() { } }; - const realClearStack = privateUnderTest.getClearStack(global); + const stackClearer = privateUnderTest.getStackClearer(global); + const realClearStack = stackClearer.clearStack; const clearStackCallbacks = {}; let clearStackCallCount = 0; - spyOn(privateUnderTest, 'getClearStack').and.returnValue(function(fn) { + spyOn(stackClearer, 'clearStack').and.callFake(function(fn) { clearStackCallCount++; if (clearStackCallbacks[clearStackCallCount]) { @@ -294,6 +299,9 @@ describe('Global error handling (integration)', function() { realClearStack(fn); }); + spyOn(privateUnderTest, 'getStackClearer').and.returnValue( + stackClearer + ); env.cleanup_(); env = new privateUnderTest.Env({ global }); @@ -391,12 +399,13 @@ describe('Global error handling (integration)', function() { } }; - const realClearStack = privateUnderTest.getClearStack(global); + const stackClearer = privateUnderTest.getStackClearer(global); + const realClearStack = stackClearer.clearStack; let clearStackCallCount = 0; let jasmineDone = false; const expectedErrors = []; const expectedErrorsAfterJasmineDone = []; - spyOn(privateUnderTest, 'getClearStack').and.returnValue(function(fn) { + spyOn(stackClearer, 'clearStack').and.callFake(function(fn) { clearStackCallCount++; const msg = `Error in clearStack #${clearStackCallCount}`; @@ -409,6 +418,7 @@ describe('Global error handling (integration)', function() { dispatchErrorEvent(global, 'error', { error: msg }); realClearStack(fn); }); + spyOn(privateUnderTest, 'getStackClearer').and.returnValue(stackClearer); spyOn(console, 'error'); env.cleanup_(); @@ -507,10 +517,11 @@ describe('Global error handling (integration)', function() { } }; - const realClearStack = privateUnderTest.getClearStack(global); + const stackClearer = privateUnderTest.getStackClearer(global); + const realClearStack = stackClearer.clearStack; const clearStackCallbacks = {}; let clearStackCallCount = 0; - spyOn(privateUnderTest, 'getClearStack').and.returnValue(function(fn) { + spyOn(stackClearer, 'clearStack').and.callFake(function(fn) { clearStackCallCount++; if (clearStackCallbacks[clearStackCallCount]) { @@ -519,6 +530,9 @@ describe('Global error handling (integration)', function() { realClearStack(fn); }); + spyOn(privateUnderTest, 'getStackClearer').and.returnValue( + stackClearer + ); env.cleanup_(); env = new privateUnderTest.Env({ global }); @@ -624,10 +638,11 @@ describe('Global error handling (integration)', function() { } }; - const realClearStack = privateUnderTest.getClearStack(global); + const stackClearer = privateUnderTest.getStackClearer(global); + const realClearStack = stackClearer.clearStack; const clearStackCallbacks = {}; let clearStackCallCount = 0; - spyOn(privateUnderTest, 'getClearStack').and.returnValue(function(fn) { + spyOn(stackClearer, 'clearStack').and.callFake(function(fn) { clearStackCallCount++; if (clearStackCallbacks[clearStackCallCount]) { @@ -636,6 +651,9 @@ describe('Global error handling (integration)', function() { realClearStack(fn); }); + spyOn(privateUnderTest, 'getStackClearer').and.returnValue( + stackClearer + ); env.cleanup_(); env = new privateUnderTest.Env({ global }); @@ -735,12 +753,13 @@ describe('Global error handling (integration)', function() { } }; - const realClearStack = privateUnderTest.getClearStack(global); + const stackClearer = privateUnderTest.getStackClearer(global); + const realClearStack = stackClearer.clearStack; let clearStackCallCount = 0; let jasmineDone = false; const expectedErrors = []; const expectedErrorsAfterJasmineDone = []; - spyOn(privateUnderTest, 'getClearStack').and.returnValue(function(fn) { + spyOn(stackClearer, 'clearStack').and.callFake(function(fn) { clearStackCallCount++; const reason = `Error in clearStack #${clearStackCallCount}`; const expectedMsg = `Unhandled promise rejection: ${reason} thrown`; @@ -754,6 +773,7 @@ describe('Global error handling (integration)', function() { dispatchErrorEvent(global, 'unhandledrejection', { reason }); realClearStack(fn); }); + spyOn(privateUnderTest, 'getStackClearer').and.returnValue(stackClearer); spyOn(console, 'error'); env.cleanup_(); diff --git a/src/core/Env.js b/src/core/Env.js index c3a2e710..c0e45908 100644 --- a/src/core/Env.js +++ b/src/core/Env.js @@ -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 diff --git a/src/core/QueueRunner.js b/src/core/QueueRunner.js index 366ef5a1..c9aa3240 100644 --- a/src/core/QueueRunner.js +++ b/src/core/QueueRunner.js @@ -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_) { diff --git a/src/core/ClearStack.js b/src/core/StackClearer.js similarity index 82% rename from src/core/ClearStack.js rename to src/core/StackClearer.js index 6968bddc..2c41c965 100644 --- a/src/core/ClearStack.js +++ b/src/core/StackClearer.js @@ -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; }; diff --git a/src/core/requireCore.js b/src/core/requireCore.js index 0b26678d..e413d6b1 100644 --- a/src/core/requireCore.js +++ b/src/core/requireCore.js @@ -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$);