@@ -25,6 +25,15 @@ @implementation RCTExceptionsManager
25
25
26
26
@synthesize moduleRegistry = _moduleRegistry;
27
27
28
+ const int FILE_KEY_OF_JS_ERROR = 0 ;
29
+ const int METHOD_NAME_KEY_OF_JS_ERROR = 1 ;
30
+ const int LINE_NUMBER_KEY_OF_JS_ERROR = 2 ;
31
+ const int COLUMN_KEY_OF_JS_ERROR = 3 ;
32
+ const int FRAMES_KEY_OF_JS_ERROR = 4 ;
33
+ const int MESSAGE_KEY_OF_JS_ERROR = 5 ;
34
+ const int ID_KEY_OF_JS_ERROR = 6 ;
35
+ const int IS_FATAL_KEY_OF_JS_ERROR = 7 ;
36
+
28
37
RCT_EXPORT_MODULE ()
29
38
30
39
- (instancetype )initWithDelegate:(id <RCTExceptionsManagerDelegate>)delegate
@@ -150,19 +159,25 @@ - (void)reportFatal:(NSString *)message
150
159
}
151
160
}
152
161
153
- - (void )reportJsException : (NSString *) errorStr
162
+ - (void )reportJsException : (const facebook::react::MapBuffer &) errorMap
154
163
{
155
- NSData *jsonData = [errorStr dataUsingEncoding: NSUTF8StringEncoding];
156
- NSError *jsonError;
157
- NSDictionary *dict = [NSJSONSerialization JSONObjectWithData: jsonData
158
- options: NSJSONWritingPrettyPrinted
159
- error: &jsonError];
160
-
161
- NSString *message = [dict objectForKey: @" message" ];
162
- double exceptionId = [[dict objectForKey: @" id" ] doubleValue ];
163
- NSArray *stack = [dict objectForKey: @" stack" ];
164
- BOOL isFatal = [[dict objectForKey: @" isFatal" ] boolValue ];
165
-
164
+ NSString *message = [NSString stringWithCString: errorMap.getString (MESSAGE_KEY_OF_JS_ERROR).c_str ()
165
+ encoding: [NSString defaultCStringEncoding ]];
166
+ int exceptionId = errorMap.getInt (ID_KEY_OF_JS_ERROR);
167
+ BOOL isFatal = errorMap.getBool (IS_FATAL_KEY_OF_JS_ERROR);
168
+ std::vector<facebook::react::MapBuffer> frames = errorMap.getMapBufferList (FRAMES_KEY_OF_JS_ERROR);
169
+ NSMutableArray *stack = [[NSMutableArray alloc ] init ];
170
+ for (facebook::react::MapBuffer const &mapBuffer : frames) {
171
+ NSDictionary *frame = @{
172
+ @" file" : [NSString stringWithCString: mapBuffer.getString (FILE_KEY_OF_JS_ERROR).c_str ()
173
+ encoding: [NSString defaultCStringEncoding ]],
174
+ @" methodName" : [NSString stringWithCString: mapBuffer.getString (METHOD_NAME_KEY_OF_JS_ERROR).c_str ()
175
+ encoding: [NSString defaultCStringEncoding ]],
176
+ @" lineNumber" : [NSNumber numberWithInt: mapBuffer.getInt (LINE_NUMBER_KEY_OF_JS_ERROR)],
177
+ @" column" : [NSNumber numberWithInt: mapBuffer.getInt (COLUMN_KEY_OF_JS_ERROR)],
178
+ };
179
+ [stack addObject: frame];
180
+ }
166
181
if (isFatal) {
167
182
[self reportFatalException: message stack: stack exceptionId: exceptionId];
168
183
} else {
0 commit comments