Skip to content

Commit 1956b18

Browse files
committed
feat: Return original arguments when handling ErrorEvent objects in TraceKit
1 parent 315dab5 commit 1956b18

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

test/utils.test.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,9 @@ describe('utils', function() {
118118
}
119119

120120
it('should work as advertised', function() {
121+
if (supportsErrorEvent()) assert.isFalse(isError(new ErrorEvent('')));
121122
assert.isTrue(isError(new Error()));
122123
assert.isTrue(isError(new ReferenceError()));
123-
124-
if (supportsErrorEvent()) {
125-
assert.isFalse(isError(new ErrorEvent('')));
126-
}
127-
128124
assert.isTrue(isError(new RavenConfigError()));
129125
assert.isTrue(isError(testErrorFromDifferentContext(fromContext)));
130126
assert.isTrue(isError(testErrorFromDifferentContext(domException)));

vendor/TraceKit/tracekit.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -137,22 +137,21 @@ TraceKit.report = (function reportModuleWrapper() {
137137
/**
138138
* Ensures all global unhandled exceptions are recorded.
139139
* Supported by Gecko and IE.
140-
* @param {string} message Error message.
140+
* @param {string} msg Error message.
141141
* @param {string} url URL of script that generated the exception.
142142
* @param {(number|string)} lineNo The line number at which the error
143143
* occurred.
144144
* @param {?(number|string)} colNo The column number at which the error
145145
* occurred.
146146
* @param {?Error} ex The actual Error object.
147147
*/
148-
function traceKitWindowOnError(message, url, lineNo, colNo, ex) {
148+
function traceKitWindowOnError(msg, url, lineNo, colNo, ex) {
149149
var stack = null;
150-
151150
// If 'ex' is ErrorEvent, get real Error from inside
152-
if (utils.isErrorEvent(ex)) ex = ex.error;
153-
// If 'message' is ErrorEvent, get real message from inside
154-
if (utils.isErrorEvent(message)) message = message.message;
155-
151+
var exception = utils.isErrorEvent(ex) ? ex.error : ex;
152+
// If 'msg' is ErrorEvent, get real message from inside
153+
var message = utils.isErrorEvent(msg) ? msg.message : msg;
154+
156155
if (lastExceptionStack) {
157156
TraceKit.computeStackTrace.augmentStackTraceWithInitialElement(
158157
lastExceptionStack,
@@ -161,13 +160,13 @@ TraceKit.report = (function reportModuleWrapper() {
161160
message
162161
);
163162
processLastException();
164-
} else if (ex && utils.isError(ex)) {
165-
// non-string `ex` arg; attempt to extract stack trace
163+
} else if (exception && utils.isError(exception)) {
164+
// non-string `exception` arg; attempt to extract stack trace
166165

167166
// New chrome and blink send along a real error object
168167
// Let's just report that like a normal error.
169168
// See: https://mikewest.org/2013/08/debugging-runtime-errors-with-window-onerror
170-
stack = TraceKit.computeStackTrace(ex);
169+
stack = TraceKit.computeStackTrace(exception);
171170
notifyHandlers(stack, true);
172171
} else {
173172
var location = {
@@ -177,22 +176,21 @@ TraceKit.report = (function reportModuleWrapper() {
177176
};
178177

179178
var name = undefined;
180-
var msg = message; // must be new var or will modify original `arguments`
181179
var groups;
182180

183181
if ({}.toString.call(message) === '[object String]') {
184182
var groups = message.match(ERROR_TYPES_RE);
185183
if (groups) {
186184
name = groups[1];
187-
msg = groups[2];
185+
message = groups[2];
188186
}
189187
}
190188

191189
location.func = UNKNOWN_FUNCTION;
192190

193191
stack = {
194192
name: name,
195-
message: msg,
193+
message: message,
196194
url: getLocationHref(),
197195
stack: [location]
198196
};

0 commit comments

Comments
 (0)