@@ -75,6 +75,7 @@ TraceKit.wrap = function traceKitWrapper(func) {
75
75
*/
76
76
TraceKit . report = ( function reportModuleWrapper ( ) {
77
77
var handlers = [ ] ,
78
+ lastArgs = null ,
78
79
lastException = null ,
79
80
lastExceptionStack = null ;
80
81
@@ -111,9 +112,9 @@ TraceKit.report = (function reportModuleWrapper() {
111
112
* Dispatch stack information to all handlers.
112
113
* @param {Object.<string, *> } stack
113
114
*/
114
- function notifyHandlers ( stack , windowError ) {
115
+ function notifyHandlers ( stack , isWindowError ) {
115
116
var exception = null ;
116
- if ( windowError && ! TraceKit . collectWindowErrors ) {
117
+ if ( isWindowError && ! TraceKit . collectWindowErrors ) {
117
118
return ;
118
119
}
119
120
for ( var i in handlers ) {
@@ -145,19 +146,16 @@ TraceKit.report = (function reportModuleWrapper() {
145
146
* @param {?Error } ex The actual Error object.
146
147
*/
147
148
function traceKitWindowOnError ( message , url , lineNo , colNo , ex ) {
148
- var stack = null , skipNotify = false ;
149
+ var stack = null ;
149
150
150
151
if ( ! isUndefined ( ex ) ) {
151
152
// New chrome and blink send along a real error object
152
153
// Let's just report that like a normal error.
153
154
// See: https://mikewest.org/2013/08/debugging-runtime-errors-with-window-onerror
154
155
report ( ex , false ) ;
155
- skipNotify = true ;
156
156
} else if ( lastExceptionStack ) {
157
157
TraceKit . computeStackTrace . augmentStackTraceWithInitialElement ( lastExceptionStack , url , lineNo , message ) ;
158
- stack = lastExceptionStack ;
159
- lastExceptionStack = null ;
160
- lastException = null ;
158
+ processLastException ( ) ;
161
159
} else {
162
160
var location = {
163
161
'url' : url ,
@@ -173,10 +171,7 @@ TraceKit.report = (function reportModuleWrapper() {
173
171
'stack' : [ location ] ,
174
172
'useragent' : navigator . userAgent
175
173
} ;
176
- }
177
-
178
- if ( ! skipNotify ) {
179
- notifyHandlers ( stack , 'from window.onerror' ) ;
174
+ notifyHandlers ( stack , true ) ;
180
175
}
181
176
182
177
if ( _oldOnerrorHandler ) {
@@ -206,6 +201,15 @@ TraceKit.report = (function reportModuleWrapper() {
206
201
_oldOnerrorHandler = undefined ;
207
202
}
208
203
204
+ function processLastException ( ) {
205
+ var _lastExceptionStack = lastExceptionStack ,
206
+ _lastArgs = lastArgs ;
207
+ lastArgs = null ;
208
+ lastExceptionStack = null ;
209
+ lastException = null ;
210
+ notifyHandlers . apply ( null , [ _lastExceptionStack , false ] . concat ( _lastArgs ) ) ;
211
+ }
212
+
209
213
/**
210
214
* Reports an unhandled Error to TraceKit.
211
215
* @param {Error } ex
@@ -219,26 +223,22 @@ TraceKit.report = (function reportModuleWrapper() {
219
223
if ( lastException === ex ) {
220
224
return ; // already caught by an inner catch block, ignore
221
225
} else {
222
- var s = lastExceptionStack ;
223
- lastExceptionStack = null ;
224
- lastException = null ;
225
- notifyHandlers . apply ( null , [ s , null ] . concat ( args ) ) ;
226
+ processLastException ( ) ;
226
227
}
227
228
}
228
229
229
230
var stack = TraceKit . computeStackTrace ( ex ) ;
230
231
lastExceptionStack = stack ;
231
232
lastException = ex ;
233
+ lastArgs = args ;
232
234
233
235
// If the stack trace is incomplete, wait for 2 seconds for
234
236
// slow slow IE to see if onerror occurs or not before reporting
235
237
// this exception; otherwise, we will end up with an incomplete
236
238
// stack trace
237
239
window . setTimeout ( function ( ) {
238
240
if ( lastException === ex ) {
239
- lastExceptionStack = null ;
240
- lastException = null ;
241
- notifyHandlers . apply ( null , [ stack , null ] . concat ( args ) ) ;
241
+ processLastException ( ) ;
242
242
}
243
243
} , ( stack . incomplete ? 2000 : 0 ) ) ;
244
244
0 commit comments