18
18
export interface StackFrame {
19
19
url : string ;
20
20
func : string ;
21
- args : string [ ] ;
22
21
line : number | null ;
23
22
column : number | null ;
24
23
}
@@ -43,7 +42,7 @@ const UNKNOWN_FUNCTION = '?';
43
42
44
43
// Chromium based browsers: Chrome, Brave, new Opera, new Edge
45
44
const chrome =
46
- / ^ \s * a t (?: ( .* ?) ? \( ) ? ( (?: f i l e | h t t p s ? | b l o b | c h r o m e - e x t e n s i o n | a d d r e s s | n a t i v e | e v a l | w e b p a c k | < a n o n y m o u s > | [ - a - z ] + : | .* b u n d l e | \/ ) .* ?) (?: : ( \d + ) ) ? (?: : ( \d + ) ) ? \) ? \s * $ / i;
45
+ / ^ \s * a t (?: ( .* ?) ? \( (?: a d d r e s s a t ) ? ) ? ( (?: f i l e | h t t p s ? | b l o b | c h r o m e - e x t e n s i o n | a d d r e s s | n a t i v e | e v a l | w e b p a c k | < a n o n y m o u s > | [ - a - z ] + : | .* b u n d l e | \/ ) .* ?) (?: : ( \d + ) ) ? (?: : ( \d + ) ) ? \) ? \s * $ / i;
47
46
// gecko regex: `(?:bundle|\d+\.js)`: `bundle` is for react native, `\d+\.js` also but specifically for ram bundles because it
48
47
// generates filenames without a prefix like `file://` the filenames in the stacktrace are just 42.js
49
48
// We need this specific case for now because we want no other regex to match.
@@ -113,9 +112,8 @@ function computeStackTraceFromStackProp(ex: any): StackTrace | null {
113
112
let parts ;
114
113
let element ;
115
114
116
- for ( let i = 0 ; i < lines . length ; ++ i ) {
117
- if ( ( parts = chrome . exec ( lines [ i ] ) ) ) {
118
- const isNative = parts [ 2 ] && parts [ 2 ] . indexOf ( 'native' ) === 0 ; // start of line
115
+ for ( const line of lines ) {
116
+ if ( ( parts = chrome . exec ( line ) ) ) {
119
117
isEval = parts [ 2 ] && parts [ 2 ] . indexOf ( 'eval' ) === 0 ; // start of line
120
118
if ( isEval && ( submatch = chromeEval . exec ( parts [ 2 ] ) ) ) {
121
119
// throw out eval line/column and use top-most line/column number
@@ -124,43 +122,31 @@ function computeStackTraceFromStackProp(ex: any): StackTrace | null {
124
122
parts [ 4 ] = submatch [ 3 ] ; // column
125
123
}
126
124
127
- // Arpad: Working with the regexp above is super painful. it is quite a hack, but just stripping the `address at `
128
- // prefix here seems like the quickest solution for now.
129
- let url = parts [ 2 ] && parts [ 2 ] . indexOf ( 'address at ' ) === 0 ? parts [ 2 ] . substr ( 'address at ' . length ) : parts [ 2 ] ;
130
125
// Kamil: One more hack won't hurt us right? Understanding and adding more rules on top of these regexps right now
131
126
// would be way too time consuming. (TODO: Rewrite whole RegExp to be more readable)
132
- let func = parts [ 1 ] || UNKNOWN_FUNCTION ;
133
- [ func , url ] = extractSafariExtensionDetails ( func , url ) ;
127
+ const [ func , url ] = extractSafariExtensionDetails ( parts [ 1 ] || UNKNOWN_FUNCTION , parts [ 2 ] ) ;
134
128
135
129
element = {
136
130
url,
137
131
func,
138
- args : isNative ? [ parts [ 2 ] ] : [ ] ,
139
132
line : parts [ 3 ] ? + parts [ 3 ] : null ,
140
133
column : parts [ 4 ] ? + parts [ 4 ] : null ,
141
134
} ;
142
- } else if ( ( parts = winjs . exec ( lines [ i ] ) ) ) {
135
+ } else if ( ( parts = winjs . exec ( line ) ) ) {
143
136
element = {
144
137
url : parts [ 2 ] ,
145
138
func : parts [ 1 ] || UNKNOWN_FUNCTION ,
146
- args : [ ] ,
147
139
line : + parts [ 3 ] ,
148
140
column : parts [ 4 ] ? + parts [ 4 ] : null ,
149
141
} ;
150
- } else if ( ( parts = gecko . exec ( lines [ i ] ) ) ) {
142
+ } else if ( ( parts = gecko . exec ( line ) ) ) {
151
143
isEval = parts [ 3 ] && parts [ 3 ] . indexOf ( ' > eval' ) > - 1 ;
152
144
if ( isEval && ( submatch = geckoEval . exec ( parts [ 3 ] ) ) ) {
153
145
// throw out eval line/column and use top-most line number
154
146
parts [ 1 ] = parts [ 1 ] || `eval` ;
155
147
parts [ 3 ] = submatch [ 1 ] ;
156
148
parts [ 4 ] = submatch [ 2 ] ;
157
149
parts [ 5 ] = '' ; // no column when eval
158
- } else if ( i === 0 && ! parts [ 5 ] && ex . columnNumber !== void 0 ) {
159
- // FireFox uses this awesome columnNumber property for its top frame
160
- // Also note, Firefox's column number is 0-based and everything else expects 1-based,
161
- // so adding 1
162
- // NOTE: this hack doesn't work if top-most frame is eval
163
- stack [ 0 ] . column = ( ex . columnNumber as number ) + 1 ;
164
150
}
165
151
166
152
let url = parts [ 3 ] ;
@@ -170,18 +156,13 @@ function computeStackTraceFromStackProp(ex: any): StackTrace | null {
170
156
element = {
171
157
url,
172
158
func,
173
- args : parts [ 2 ] ? parts [ 2 ] . split ( ',' ) : [ ] ,
174
159
line : parts [ 4 ] ? + parts [ 4 ] : null ,
175
160
column : parts [ 5 ] ? + parts [ 5 ] : null ,
176
161
} ;
177
162
} else {
178
163
continue ;
179
164
}
180
165
181
- if ( ! element . func && element . line ) {
182
- element . func = UNKNOWN_FUNCTION ;
183
- }
184
-
185
166
stack . push ( element ) ;
186
167
}
187
168
@@ -208,7 +189,7 @@ function computeStackTraceFromStacktraceProp(ex: any): StackTrace | null {
208
189
const stacktrace = ex . stacktrace ;
209
190
const opera10Regex = / l i n e ( \d + ) .* s c r i p t (?: i n ) ? ( \S + ) (?: : i n f u n c t i o n ( \S + ) ) ? $ / i;
210
191
const opera11Regex =
211
- / l i n e ( \d + ) , c o l u m n ( \d + ) \s * (?: i n (?: < a n o n y m o u s f u n c t i o n : ( [ ^ > ] + ) > | ( [ ^ ) ] + ) ) \( ( . * ) \) ) ? i n ( .* ) : \s * $ / i;
192
+ / l i n e ( \d + ) , c o l u m n ( \d + ) \s * (?: i n (?: < a n o n y m o u s f u n c t i o n : ( [ ^ > ] + ) > | ( [ ^ ) ] + ) ) \( . * \) ) ? i n ( .* ) : \s * $ / i;
212
193
const lines = stacktrace . split ( '\n' ) ;
213
194
const stack = [ ] ;
214
195
let parts ;
@@ -219,15 +200,13 @@ function computeStackTraceFromStacktraceProp(ex: any): StackTrace | null {
219
200
element = {
220
201
url : parts [ 2 ] ,
221
202
func : parts [ 3 ] ,
222
- args : [ ] ,
223
203
line : + parts [ 1 ] ,
224
204
column : null ,
225
205
} ;
226
206
} else if ( ( parts = opera11Regex . exec ( lines [ line ] ) ) ) {
227
207
element = {
228
- url : parts [ 6 ] ,
208
+ url : parts [ 5 ] ,
229
209
func : parts [ 3 ] || parts [ 4 ] ,
230
- args : parts [ 5 ] ? parts [ 5 ] . split ( ',' ) : [ ] ,
231
210
line : + parts [ 1 ] ,
232
211
column : + parts [ 2 ] ,
233
212
} ;
0 commit comments