Restore the original global error hanler to pass all parameters along
This commit is contained in:
@@ -12,7 +12,7 @@ describe('GlobalErrors', function() {
|
|||||||
expect(handler).toHaveBeenCalledWith('foo');
|
expect(handler).toHaveBeenCalledWith('foo');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('prefers passing the error including stack to the handler', function() {
|
it('calls the global error handler with all parameters', function() {
|
||||||
var fakeGlobal = { onerror: null },
|
var fakeGlobal = { onerror: null },
|
||||||
handler = jasmine.createSpy('errorHandler'),
|
handler = jasmine.createSpy('errorHandler'),
|
||||||
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal),
|
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal),
|
||||||
@@ -23,7 +23,13 @@ describe('GlobalErrors', function() {
|
|||||||
|
|
||||||
fakeGlobal.onerror(fooError.message, 'foo.js', 1, 1, fooError);
|
fakeGlobal.onerror(fooError.message, 'foo.js', 1, 1, fooError);
|
||||||
|
|
||||||
expect(handler).toHaveBeenCalledWith(fooError);
|
expect(handler).toHaveBeenCalledWith(
|
||||||
|
fooError.message,
|
||||||
|
'foo.js',
|
||||||
|
1,
|
||||||
|
1,
|
||||||
|
fooError
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('only calls the most recent handler', function() {
|
it('only calls the most recent handler', function() {
|
||||||
|
|||||||
@@ -3,14 +3,11 @@ getJasmineRequireObj().GlobalErrors = function(j$) {
|
|||||||
var handlers = [];
|
var handlers = [];
|
||||||
global = global || j$.getGlobal();
|
global = global || j$.getGlobal();
|
||||||
|
|
||||||
var onerror = function onerror(message, source, lineno, colno, error) {
|
var onerror = function onerror() {
|
||||||
var handler = handlers[handlers.length - 1];
|
var handler = handlers[handlers.length - 1];
|
||||||
|
|
||||||
if (handler) {
|
if (handler) {
|
||||||
var args = Array.prototype.slice.call(arguments, 0);
|
handler.apply(null, Array.prototype.slice.call(arguments, 0));
|
||||||
// Prefer passing the error to the error handler
|
|
||||||
// to be able to print the stack trace.
|
|
||||||
handler.apply(null, error instanceof Error ? [error] : args);
|
|
||||||
} else {
|
} else {
|
||||||
throw arguments[0];
|
throw arguments[0];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user