|
14 | 14 | 'use strict'; |
15 | 15 |
|
16 | 16 | var FIREFOX_SAFARI_STACK_REGEXP = /(^|@)\S+\:\d+/; |
17 | | - var CHROME_IE_STACK_REGEXP = /\s*at .*(\S+\:\d+|\(native\))/; |
| 17 | + var CHROME_IE_STACK_REGEXP = /^\s*at .*(\S+\:\d+|\(native\))/m; |
| 18 | + var SAFARI_NATIVE_CODE_REGEXP = /^(eval@)?(\[native code\])?$/; |
18 | 19 |
|
19 | 20 | return { |
20 | 21 | /** |
|
60 | 61 | return error.stack.split('\n').filter(function (line) { |
61 | 62 | return !!line.match(CHROME_IE_STACK_REGEXP); |
62 | 63 | }, this).map(function (line) { |
63 | | - if (line.indexOf('(eval at ') > -1) { |
64 | | - // TODO: we need a way of representing location within eval()'d String |
65 | | - // throw away all intermediate "eval at XXX" and location within eval()'d string |
66 | | - line = line.replace(/(\(eval at [^\()]*)|(\)\,.*$)/g, ''); |
| 64 | + if (line.indexOf('(eval ') > -1) { |
| 65 | + // Throw away eval information until we implement stacktrace.js/stackframe#8 |
| 66 | + line = line.replace(/eval code/g, 'eval').replace(/(\(eval at [^\()]*)|(\)\,.*$)/g, ''); |
67 | 67 | } |
68 | | - var tokens = line.replace(/^\s+/, '').split(/\s+/).slice(1); |
| 68 | + var tokens = line.replace(/^\s+/, '').replace(/\(eval code/g, '(').split(/\s+/).slice(1); |
69 | 69 | var locationParts = this.extractLocation(tokens.pop()); |
70 | 70 | var functionName = tokens.join(' ') || undefined; |
| 71 | + var fileName = locationParts[0] === 'eval' ? undefined : locationParts[0]; |
71 | 72 |
|
72 | | - return new StackFrame(functionName, undefined, locationParts[0], locationParts[1], locationParts[2], line); |
| 73 | + return new StackFrame(functionName, undefined, fileName, locationParts[1], locationParts[2], line); |
73 | 74 | }, this); |
74 | 75 | }, |
75 | 76 |
|
76 | 77 | parseFFOrSafari: function ErrorStackParser$$parseFFOrSafari(error) { |
77 | 78 | return error.stack.split('\n').filter(function (line) { |
78 | | - return !!line.match(FIREFOX_SAFARI_STACK_REGEXP); |
| 79 | + return !line.match(SAFARI_NATIVE_CODE_REGEXP); |
79 | 80 | }, this).map(function (line) { |
80 | | - var tokens = line.split('@'); |
81 | | - var locationParts = this.extractLocation(tokens.pop()); |
82 | | - var functionName = tokens.shift() || undefined; |
83 | | - return new StackFrame(functionName, undefined, locationParts[0], locationParts[1], locationParts[2], line); |
| 81 | + // Throw away eval information until we implement stacktrace.js/stackframe#8 |
| 82 | + if (line.indexOf(' > eval') > -1) { |
| 83 | + line = line.replace(/ line (\d+)(?: > eval line \d+)* > eval\:\d+\:\d+/g, ':$1'); |
| 84 | + } |
| 85 | + |
| 86 | + if (line.indexOf('@') === -1 && line.indexOf(':') === -1) { |
| 87 | + // Safari eval frames only have function names and nothing else |
| 88 | + return new StackFrame(line); |
| 89 | + } else { |
| 90 | + var tokens = line.split('@'); |
| 91 | + var locationParts = this.extractLocation(tokens.pop()); |
| 92 | + var functionName = tokens.shift() || undefined; |
| 93 | + return new StackFrame(functionName, undefined, locationParts[0], locationParts[1], locationParts[2], line); |
| 94 | + } |
84 | 95 | }, this); |
85 | 96 | }, |
86 | 97 |
|
|
0 commit comments