Restore the original global error hanler to pass all parameters along

This commit is contained in:
Ferdinand Prantl
2019-08-11 09:31:43 +02:00
parent 7c3434723e
commit 527619b0aa
2 changed files with 10 additions and 7 deletions

View File

@@ -12,7 +12,7 @@ describe('GlobalErrors', function() {
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 },
handler = jasmine.createSpy('errorHandler'),
errors = new jasmineUnderTest.GlobalErrors(fakeGlobal),
@@ -23,7 +23,13 @@ describe('GlobalErrors', function() {
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() {

View File

@@ -3,14 +3,11 @@ getJasmineRequireObj().GlobalErrors = function(j$) {
var handlers = [];
global = global || j$.getGlobal();
var onerror = function onerror(message, source, lineno, colno, error) {
var onerror = function onerror() {
var handler = handlers[handlers.length - 1];
if (handler) {
var args = 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);
handler.apply(null, Array.prototype.slice.call(arguments, 0));
} else {
throw arguments[0];
}