Rename for stack-clearing post spec run to be more clear; use the real setTimeout when clearing stack
This commit is contained in:
@@ -312,6 +312,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
|
||||
var catchExceptions = true;
|
||||
|
||||
var realSetTimeout = global.setTimeout;
|
||||
this.clock = new j$.Clock(global, new j$.DelayedFunctionScheduler());
|
||||
|
||||
this.spies_ = [];
|
||||
@@ -413,11 +414,11 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
var maximumSpecCallbackDepth = 100;
|
||||
var currentSpecCallbackDepth = 0;
|
||||
|
||||
function encourageGarbageCollection(fn) {
|
||||
function clearStack(fn) {
|
||||
currentSpecCallbackDepth++;
|
||||
if (currentSpecCallbackDepth > maximumSpecCallbackDepth) {
|
||||
currentSpecCallbackDepth = 0;
|
||||
global.setTimeout(fn, 0);
|
||||
realSetTimeout(fn, 0);
|
||||
} else {
|
||||
fn();
|
||||
}
|
||||
@@ -425,7 +426,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
|
||||
var queueRunnerFactory = function(options) {
|
||||
options.catchException = self.catchException;
|
||||
options.encourageGC = options.encourageGarbageCollection || encourageGarbageCollection;
|
||||
options.clearStack = options.clearStack || clearStack;
|
||||
|
||||
new j$.QueueRunner(options).run(options.fns, 0);
|
||||
};
|
||||
@@ -1289,7 +1290,7 @@ getJasmineRequireObj().QueueRunner = function() {
|
||||
function QueueRunner(attrs) {
|
||||
this.fns = attrs.fns || [];
|
||||
this.onComplete = attrs.onComplete || function() {};
|
||||
this.encourageGC = attrs.encourageGC || function(fn) {fn();};
|
||||
this.clearStack = attrs.clearStack || function(fn) {fn();};
|
||||
this.onException = attrs.onException || function() {};
|
||||
this.catchException = attrs.catchException || function() { return true; };
|
||||
}
|
||||
@@ -1300,7 +1301,7 @@ getJasmineRequireObj().QueueRunner = function() {
|
||||
|
||||
QueueRunner.prototype.run = function(fns, index) {
|
||||
if (index >= fns.length) {
|
||||
this.encourageGC(this.onComplete);
|
||||
this.clearStack(this.onComplete);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1462,7 +1463,7 @@ getJasmineRequireObj().Suite = function() {
|
||||
this.onStart = attrs.onStart || function() {};
|
||||
this.completeCallback = attrs.completeCallback || function() {};
|
||||
this.resultCallback = attrs.resultCallback || function() {};
|
||||
this.encourageGC = attrs.encourageGC || function(fn) {fn();};
|
||||
this.clearStack = attrs.clearStack || function(fn) {fn();};
|
||||
|
||||
this.beforeFns = [];
|
||||
this.afterFns = [];
|
||||
|
||||
@@ -118,15 +118,15 @@ describe("QueueRunner", function() {
|
||||
it("calls a provided garbage collection function with the complete callback when done", function() {
|
||||
var fn = jasmine.createSpy('fn'),
|
||||
completeCallback = jasmine.createSpy('completeCallback'),
|
||||
encourageGC = jasmine.createSpy('encourageGC'),
|
||||
clearStack = jasmine.createSpy('clearStack'),
|
||||
queueRunner = new j$.QueueRunner({
|
||||
fns: [fn],
|
||||
encourageGC: encourageGC,
|
||||
clearStack: clearStack,
|
||||
onComplete: completeCallback
|
||||
});
|
||||
|
||||
queueRunner.execute();
|
||||
|
||||
expect(encourageGC).toHaveBeenCalledWith(completeCallback);
|
||||
expect(clearStack).toHaveBeenCalledWith(completeCallback);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,6 +7,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
|
||||
var catchExceptions = true;
|
||||
|
||||
var realSetTimeout = global.setTimeout;
|
||||
this.clock = new j$.Clock(global, new j$.DelayedFunctionScheduler());
|
||||
|
||||
this.spies_ = [];
|
||||
@@ -108,11 +109,11 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
var maximumSpecCallbackDepth = 100;
|
||||
var currentSpecCallbackDepth = 0;
|
||||
|
||||
function encourageGarbageCollection(fn) {
|
||||
function clearStack(fn) {
|
||||
currentSpecCallbackDepth++;
|
||||
if (currentSpecCallbackDepth > maximumSpecCallbackDepth) {
|
||||
currentSpecCallbackDepth = 0;
|
||||
global.setTimeout(fn, 0);
|
||||
realSetTimeout(fn, 0);
|
||||
} else {
|
||||
fn();
|
||||
}
|
||||
@@ -120,7 +121,7 @@ getJasmineRequireObj().Env = function(j$) {
|
||||
|
||||
var queueRunnerFactory = function(options) {
|
||||
options.catchException = self.catchException;
|
||||
options.encourageGC = options.encourageGarbageCollection || encourageGarbageCollection;
|
||||
options.clearStack = options.clearStack || clearStack;
|
||||
|
||||
new j$.QueueRunner(options).run(options.fns, 0);
|
||||
};
|
||||
|
||||
@@ -3,7 +3,7 @@ getJasmineRequireObj().QueueRunner = function() {
|
||||
function QueueRunner(attrs) {
|
||||
this.fns = attrs.fns || [];
|
||||
this.onComplete = attrs.onComplete || function() {};
|
||||
this.encourageGC = attrs.encourageGC || function(fn) {fn();};
|
||||
this.clearStack = attrs.clearStack || function(fn) {fn();};
|
||||
this.onException = attrs.onException || function() {};
|
||||
this.catchException = attrs.catchException || function() { return true; };
|
||||
}
|
||||
@@ -14,7 +14,7 @@ getJasmineRequireObj().QueueRunner = function() {
|
||||
|
||||
QueueRunner.prototype.run = function(fns, index) {
|
||||
if (index >= fns.length) {
|
||||
this.encourageGC(this.onComplete);
|
||||
this.clearStack(this.onComplete);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ getJasmineRequireObj().Suite = function() {
|
||||
this.onStart = attrs.onStart || function() {};
|
||||
this.completeCallback = attrs.completeCallback || function() {};
|
||||
this.resultCallback = attrs.resultCallback || function() {};
|
||||
this.encourageGC = attrs.encourageGC || function(fn) {fn();};
|
||||
this.clearStack = attrs.clearStack || function(fn) {fn();};
|
||||
|
||||
this.beforeFns = [];
|
||||
this.afterFns = [];
|
||||
|
||||
Reference in New Issue
Block a user