diff --git a/test/utils.test.js b/test/utils.test.js index 8352b6658bab..b30e4cbefc8a 100644 --- a/test/utils.test.js +++ b/test/utils.test.js @@ -120,6 +120,11 @@ describe('utils', function() { it('should work as advertised', function() { assert.isTrue(isError(new Error())); assert.isTrue(isError(new ReferenceError())); + + if (supportsErrorEvent()) { + assert.isFalse(isError(new ErrorEvent(''))); + } + assert.isTrue(isError(new RavenConfigError())); assert.isTrue(isError(testErrorFromDifferentContext(fromContext))); assert.isTrue(isError(testErrorFromDifferentContext(domException))); diff --git a/test/vendor/tracekit.test.js b/test/vendor/tracekit.test.js index 7831029f7851..d82438ea1bfb 100644 --- a/test/vendor/tracekit.test.js +++ b/test/vendor/tracekit.test.js @@ -2,6 +2,8 @@ 'use strict'; var TraceKit = require('../../vendor/TraceKit/tracekit'); +var utils = require('../../src/utils'); +var supportsErrorEvent = utils.supportsErrorEvent; describe('TraceKit', function() { describe('stacktrace info', function() { @@ -139,9 +141,35 @@ describe('TraceKit', function() { } }); + if (supportsErrorEvent()) { + it("should handle error event object as 'ex' param", function() { + var ex = new ErrorEvent('', { + error: new Error('something went wrong') + }); + subscriptionHandler = function(stackInfo, extra) { + assert.equal(stackInfo.name, 'Error'); + assert.equal(stackInfo.message, 'something went wrong'); + }; + TraceKit.report.subscribe(subscriptionHandler); + window.onerror(undefined, undefined, testLineNo, undefined, ex); + }); + + it("should handle error event object as 'message' param", function() { + var message = new ErrorEvent('', { + message: 'something went wrong' + }); + subscriptionHandler = function(stackInfo, extra) { + assert.equal(stackInfo.name, undefined); + assert.equal(stackInfo.message, 'something went wrong'); + }; + TraceKit.report.subscribe(subscriptionHandler); + window.onerror(message, undefined, testLineNo, undefined, undefined); + }); + } + describe('with undefined arguments', function() { it('should pass undefined:undefined', function() { - // this is probably not good behavior; just writing this test to verify + // this is probably not good behavior; just writing this test to verify // that it doesn't change unintentionally subscriptionHandler = function(stackInfo, extra) { assert.equal(stackInfo.name, undefined); @@ -151,6 +179,7 @@ describe('TraceKit', function() { window.onerror(undefined, undefined, testLineNo); }); }); + describe('when no 5th argument (error object)', function() { it('should seperate name, message for default error types (e.g. ReferenceError)', function( done diff --git a/vendor/TraceKit/tracekit.js b/vendor/TraceKit/tracekit.js index fdbd6760b72d..c2dca23df714 100644 --- a/vendor/TraceKit/tracekit.js +++ b/vendor/TraceKit/tracekit.js @@ -148,6 +148,11 @@ TraceKit.report = (function reportModuleWrapper() { function traceKitWindowOnError(message, url, lineNo, colNo, ex) { var stack = null; + // If 'ex' is ErrorEvent, get real Error from inside + if (utils.isErrorEvent(ex)) ex = ex.error; + // If 'message' is ErrorEvent, get real message from inside + if (utils.isErrorEvent(message)) message = message.message; + if (lastExceptionStack) { TraceKit.computeStackTrace.augmentStackTraceWithInitialElement( lastExceptionStack, @@ -174,6 +179,7 @@ TraceKit.report = (function reportModuleWrapper() { var name = undefined; var msg = message; // must be new var or will modify original `arguments` var groups; + if ({}.toString.call(message) === '[object String]') { var groups = message.match(ERROR_TYPES_RE); if (groups) {