Detect global error handler stack corruption
This commit is contained in:
@@ -4117,7 +4117,17 @@ getJasmineRequireObj().GlobalErrors = function(j$) {
|
|||||||
handlers.push(listener);
|
handlers.push(listener);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.popListener = function popListener() {
|
this.popListener = function popListener(listener) {
|
||||||
|
if (!listener) {
|
||||||
|
throw new Error('popListener expects a listener');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (listener !== handlers[handlers.length - 1]) {
|
||||||
|
throw new Error(
|
||||||
|
'popListener was passed a different listener than the current one'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
handlers.pop();
|
handlers.pop();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ describe('GlobalErrors', function() {
|
|||||||
errors.pushListener(handler1);
|
errors.pushListener(handler1);
|
||||||
errors.pushListener(handler2);
|
errors.pushListener(handler2);
|
||||||
|
|
||||||
errors.popListener();
|
errors.popListener(handler2);
|
||||||
|
|
||||||
fakeGlobal.onerror('foo');
|
fakeGlobal.onerror('foo');
|
||||||
|
|
||||||
@@ -66,6 +66,23 @@ describe('GlobalErrors', function() {
|
|||||||
expect(handler2).not.toHaveBeenCalled();
|
expect(handler2).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('throws when no listener is passed to #popListener', function() {
|
||||||
|
var errors = new jasmineUnderTest.GlobalErrors({});
|
||||||
|
expect(function() {
|
||||||
|
errors.popListener();
|
||||||
|
}).toThrowError('popListener expects a listener');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('throws when the argument to #popListener is not the current listener', function() {
|
||||||
|
var errors = new jasmineUnderTest.GlobalErrors({});
|
||||||
|
errors.pushListener(function() {});
|
||||||
|
expect(function() {
|
||||||
|
errors.popListener(function() {});
|
||||||
|
}).toThrowError(
|
||||||
|
'popListener was passed a different listener than the current one'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('uninstalls itself, putting back a previous callback', function() {
|
it('uninstalls itself, putting back a previous callback', function() {
|
||||||
var originalCallback = jasmine.createSpy('error'),
|
var originalCallback = jasmine.createSpy('error'),
|
||||||
fakeGlobal = { onerror: originalCallback },
|
fakeGlobal = { onerror: originalCallback },
|
||||||
|
|||||||
@@ -974,7 +974,6 @@ describe("Env integration", function() {
|
|||||||
env.execute(null, function() {
|
env.execute(null, function() {
|
||||||
expect(delayedFunctionForMockClock).toHaveBeenCalled();
|
expect(delayedFunctionForMockClock).toHaveBeenCalled();
|
||||||
expect(globalSetTimeout).toHaveBeenCalledWith(delayedFunctionForGlobalClock, 100);
|
expect(globalSetTimeout).toHaveBeenCalledWith(delayedFunctionForGlobalClock, 100);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -96,7 +96,17 @@ getJasmineRequireObj().GlobalErrors = function(j$) {
|
|||||||
handlers.push(listener);
|
handlers.push(listener);
|
||||||
};
|
};
|
||||||
|
|
||||||
this.popListener = function popListener() {
|
this.popListener = function popListener(listener) {
|
||||||
|
if (!listener) {
|
||||||
|
throw new Error('popListener expects a listener');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (listener !== handlers[handlers.length - 1]) {
|
||||||
|
throw new Error(
|
||||||
|
'popListener was passed a different listener than the current one'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
handlers.pop();
|
handlers.pop();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user