From 3a7fc638790014d6ac79b0bdac88976655ba5dc4 Mon Sep 17 00:00:00 2001 From: Ferdinand Prantl Date: Sun, 11 Aug 2019 09:32:31 +0200 Subject: [PATCH] Pick the error instance to pass to error handlers in QueueRunner The first number is the error message in HTML5 browser, which does not include the call stack. The error instance allows logging the complete call stack in reporters. --- spec/core/QueueRunnerSpec.js | 26 ++++++++++++++++++++++++++ src/core/QueueRunner.js | 7 +++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/spec/core/QueueRunnerSpec.js b/spec/core/QueueRunnerSpec.js index e0b4c23c..ac18b81d 100644 --- a/spec/core/QueueRunnerSpec.js +++ b/spec/core/QueueRunnerSpec.js @@ -514,6 +514,32 @@ describe('QueueRunner', function() { }); }); + it('passes the error instance to exception handlers in HTML browsers', function() { + var error = new Error('fake error'), + onExceptionCallback = jasmine.createSpy('on exception callback'), + queueRunner = new jasmineUnderTest.QueueRunner({ + onException: onExceptionCallback + }); + + queueRunner.execute(); + queueRunner.handleFinalError(error.message, 'fake.js', 1, 1, error); + + expect(onExceptionCallback).toHaveBeenCalledWith(error); + }); + + it('passes the first argument to exception handlers for compatibility', function() { + var error = new Error('fake error'), + onExceptionCallback = jasmine.createSpy('on exception callback'), + queueRunner = new jasmineUnderTest.QueueRunner({ + onException: onExceptionCallback + }); + + queueRunner.execute(); + queueRunner.handleFinalError(error.message); + + expect(onExceptionCallback).toHaveBeenCalledWith(error.message); + }); + it('calls exception handlers when an exception is thrown in a fn', function() { var queueableFn = { type: 'queueable', diff --git a/src/core/QueueRunner.js b/src/core/QueueRunner.js index 27b57695..639296d7 100644 --- a/src/core/QueueRunner.js +++ b/src/core/QueueRunner.js @@ -49,8 +49,11 @@ getJasmineRequireObj().QueueRunner = function(j$) { QueueRunner.prototype.execute = function() { var self = this; - this.handleFinalError = function(error) { - self.onException(error); + this.handleFinalError = function(message, source, lineno, colno, error) { + // Older browsers would send the error as the first parameter. HTML5 + // specifies the the five parameters above. The error instance should + // be preffered, otherwise the call stack would get lost. + self.onException(error || message); }; this.globalErrors.pushListener(this.handleFinalError); this.run(0);