Skip to content

Commit

Permalink
Move RCTExceptionsManager to CoreModules and make it conform to spec
Browse files Browse the repository at this point in the history
Summary:
`NativeExceptionsManager.js` contains the JS spec for this native module. This diff moves the objc code to CoreModules (since it's the only directory that supports TM at the moment) and makes it conform to the spec.

NOTE: I will update podfiles after this diff is reviewed, before I land. Adding those generated changes makes it really hard to review.

Reviewed By: RSNara

Differential Revision: D16812212

fbshipit-source-id: 38b6e9a20ce15e7e9995df34493b37ed7adb2911
  • Loading branch information
Peter Argany authored and facebook-github-bot committed Aug 16, 2019
1 parent 111cb32 commit 6991e28
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 15 deletions.
4 changes: 4 additions & 0 deletions React/CoreModules/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ rn_apple_library(
["-D PIC_MODIFIER=@PLT"],
)],
plugins = react_module_plugin_providers(
name = "ExceptionsManager",
native_class_func = "RCTExceptionsManagerCls",
) +
react_module_plugin_providers(
name = "ImageLoader",
native_class_func = "RCTImageLoaderCls",
) +
Expand Down
1 change: 1 addition & 0 deletions React/CoreModules/CoreModulesPlugins.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ extern "C" {
Class RCTCoreModulesClassProvider(const char *name);

// Lookup functions
Class RCTExceptionsManagerCls(void);
Class RCTImageLoaderCls(void);
Class RCTPlatformCls(void);

Expand Down
3 changes: 2 additions & 1 deletion React/CoreModules/CoreModulesPlugins.mm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
#import <unordered_map>

static std::unordered_map<std::string, Class (*)(void)> sCoreModuleClassMap = {
{"ImageLoader", RCTImageLoaderCls},
{"ExceptionsManager", RCTExceptionsManagerCls},
{"ImageLoader", RCTImageLoaderCls},
{"PlatformConstants", RCTPlatformCls},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ NS_ASSUME_NONNULL_BEGIN

- (instancetype)initWithDelegate:(id<RCTExceptionsManagerDelegate>)delegate;

- (void)reportSoftException:(nullable NSString *)message stack:(nullable NSArray<NSDictionary *> *)stack exceptionId:(NSNumber *)exceptionId;
- (void)reportFatalException:(nullable NSString *)message stack:(nullable NSArray<NSDictionary *> *)stack exceptionId:(NSNumber *)exceptionId;
- (void)reportSoftException:(nullable NSString *)message stack:(nullable NSArray<NSDictionary *> *)stack exceptionId:(double)exceptionId;
- (void)reportFatalException:(nullable NSString *)message stack:(nullable NSArray<NSDictionary *> *)stack exceptionId:(double)exceptionId;

@property (nonatomic, weak) id<RCTExceptionsManagerDelegate> delegate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@

#import "RCTExceptionsManager.h"

#import "RCTConvert.h"
#import "RCTDefines.h"
#import "RCTLog.h"
#import "RCTRedBox.h"
#import "RCTRootView.h"
#import <FBReactNativeSpec/FBReactNativeSpec.h>
#import <React/RCTConvert.h>
#import <React/RCTDefines.h>
#import <React/RCTLog.h>
#import <React/RCTRedBox.h>
#import <React/RCTRootView.h>

#import "CoreModulesPlugins.h"

@interface RCTExceptionsManager() <NativeExceptionsManagerSpec>

@end

@implementation RCTExceptionsManager

Expand All @@ -29,23 +36,23 @@ - (instancetype)initWithDelegate:(id<RCTExceptionsManagerDelegate>)delegate

RCT_EXPORT_METHOD(reportSoftException:(NSString *)message
stack:(NSArray<NSDictionary *> *)stack
exceptionId:(nonnull NSNumber *)exceptionId)
exceptionId:(double)exceptionId)
{
[_bridge.redBox showErrorMessage:message withStack:stack];

if (_delegate) {
[_delegate handleSoftJSExceptionWithMessage:message stack:stack exceptionId:exceptionId];
[_delegate handleSoftJSExceptionWithMessage:message stack:stack exceptionId:[NSNumber numberWithDouble:exceptionId]];
}
}

RCT_EXPORT_METHOD(reportFatalException:(NSString *)message
stack:(NSArray<NSDictionary *> *)stack
exceptionId:(nonnull NSNumber *)exceptionId)
exceptionId:(double) exceptionId)
{
[_bridge.redBox showErrorMessage:message withStack:stack];

if (_delegate) {
[_delegate handleFatalJSExceptionWithMessage:message stack:stack exceptionId:exceptionId];
[_delegate handleFatalJSExceptionWithMessage:message stack:stack exceptionId:[NSNumber numberWithDouble:exceptionId]];
}

static NSUInteger reloadRetries = 0;
Expand All @@ -61,20 +68,41 @@ - (instancetype)initWithDelegate:(id<RCTExceptionsManagerDelegate>)delegate

RCT_EXPORT_METHOD(updateExceptionMessage:(NSString *)message
stack:(NSArray<NSDictionary *> *)stack
exceptionId:(nonnull NSNumber *)exceptionId)
exceptionId:(double)exceptionId)
{
[_bridge.redBox updateErrorMessage:message withStack:stack];

if (_delegate && [_delegate respondsToSelector:@selector(updateJSExceptionWithMessage:stack:exceptionId:)]) {
[_delegate updateJSExceptionWithMessage:message stack:stack exceptionId:exceptionId];
[_delegate updateJSExceptionWithMessage:message stack:stack exceptionId:[NSNumber numberWithDouble:exceptionId]];
}
}

// Deprecated. Use reportFatalException directly instead.
RCT_EXPORT_METHOD(reportUnhandledException:(NSString *)message
stack:(NSArray<NSDictionary *> *)stack)
{
[self reportFatalException:message stack:stack exceptionId:@-1];
[self reportFatalException:message stack:stack exceptionId:-1];
}

RCT_EXPORT_METHOD(dismissRedbox)
{

}

RCT_EXPORT_METHOD(reportException:(JS::NativeExceptionsManager::ExceptionData &)data)
{

}

- (std::shared_ptr<facebook::react::TurboModule>)getTurboModuleWithJsInvoker:
(std::shared_ptr<facebook::react::JSCallInvoker>)jsInvoker
{
return std::make_shared<facebook::react::NativeExceptionsManagerSpecJSI>(self, jsInvoker);
}

@end

Class RCTExceptionsManagerCls(void)
{
return RCTExceptionsManager.class;
}

0 comments on commit 6991e28

Please sign in to comment.