From 9a57145f52a03678da02d5d00cbe11eed3f5a0fc Mon Sep 17 00:00:00 2001 From: Moti Zilberman Date: Fri, 6 Sep 2019 10:10:23 -0700 Subject: [PATCH] Implement RCTExceptionsManager.reportException on iOS Summary: Implements the new `reportException` method in the iOS version of `ExceptionsManager`. Reviewed By: sammy-SC Differential Revision: D17226365 fbshipit-source-id: baa81424399175eaf8fc0835d4df01897e7fa468 --- React/CoreModules/RCTExceptionsManager.mm | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/React/CoreModules/RCTExceptionsManager.mm b/React/CoreModules/RCTExceptionsManager.mm index 5d4b0fe77fddef..fd2554147b8cf1 100644 --- a/React/CoreModules/RCTExceptionsManager.mm +++ b/React/CoreModules/RCTExceptionsManager.mm @@ -91,7 +91,34 @@ - (instancetype)initWithDelegate:(id)delegate RCT_EXPORT_METHOD(reportException:(JS::NativeExceptionsManager::ExceptionData &)data) { + NSString *message = data.message(); + double exceptionId = data.id_(); + + // Reserialize data.stack() into an array of untyped dictionaries. + // TODO: (moti) T53588496 Replace `(NSArray *)stack` in + // reportFatalException etc with a typed interface. + NSMutableArray *stackArray = [NSMutableArray new]; + for (auto frame: data.stack()) { + NSMutableDictionary * frameDict = [NSMutableDictionary new]; + if (frame.column().hasValue()) { + frameDict[@"column"] = @(frame.column().value()); + } + frameDict[@"file"] = frame.file(); + if (frame.lineNumber().hasValue()) { + frameDict[@"lineNumber"] = @(frame.lineNumber().value()); + } + frameDict[@"methodName"] = frame.methodName(); + if (frame.collapse().hasValue()) { + frameDict[@"collapse"] = @(frame.collapse().value()); + } + [stackArray addObject:frameDict]; + } + if (data.isFatal()) { + [self reportFatalException:message stack:stackArray exceptionId:exceptionId]; + } else { + [self reportSoftException:message stack:stackArray exceptionId:exceptionId]; + } } - (std::shared_ptr)getTurboModuleWithJsInvoker: