|
10 | 10 | #import "RCTLog.h" |
11 | 11 | #import "RCTUtils.h" |
12 | 12 |
|
| 13 | +/** |
| 14 | +* The RegEx used to parse Error.stack. |
| 15 | +* |
| 16 | +* JavaScriptCore has the following format: |
| 17 | +* |
| 18 | +* Exception: Error: argh |
| 19 | +* func1@/path/to/file.js:2:18 |
| 20 | +* func2@/path/to/file.js:6:8 |
| 21 | +* eval@[native code] |
| 22 | +* global code@/path/to/file.js:13:5 |
| 23 | +* |
| 24 | +* Another supported format: |
| 25 | +* |
| 26 | +* Error: argh |
| 27 | +* at func1 (/path/to/file.js:2:18) |
| 28 | +* at func2 (/path/to/file.js:6:8) |
| 29 | +* at eval (native) |
| 30 | +* at global (/path/to/file.js:13:5) |
| 31 | +*/ |
13 | 32 | static NSRegularExpression *RCTJSStackFrameRegex() |
14 | 33 | { |
15 | 34 | static dispatch_once_t onceToken; |
16 | 35 | static NSRegularExpression *_regex; |
17 | 36 | dispatch_once(&onceToken, ^{ |
| 37 | + NSString *pattern = |
| 38 | + @"\\s*(?:at)?\\s*" // Skip leading "at" and whitespace, noncapturing |
| 39 | + @"(.+?)" // Capture the function name (group 1) |
| 40 | + @"\\s*[@(]" // Skip whitespace, then @ or ( |
| 41 | + @"(.*):" // Capture the file name (group 2), then colon |
| 42 | + @"(\\d+):(\\d+)" // Line and column number (groups 3 and 4) |
| 43 | + @"\\)?$" // Optional closing paren and EOL |
| 44 | + ; |
18 | 45 | NSError *regexError; |
19 | | - _regex = [NSRegularExpression regularExpressionWithPattern:@"^(?:([^@]+)@)?(.*):(\\d+):(\\d+)$" options:0 error:®exError]; |
| 46 | + _regex = [NSRegularExpression regularExpressionWithPattern:pattern options:0 error:®exError]; |
20 | 47 | if (regexError) { |
21 | 48 | RCTLogError(@"Failed to build regex: %@", [regexError localizedDescription]); |
22 | 49 | } |
|
0 commit comments