Skip to content

Commit

Permalink
Revert D38460203: Migrate JS error handler to MapBuffer
Browse files Browse the repository at this point in the history
Differential Revision:
D38460203 (e6ef083)

Original commit changeset: 98f6243e31da

Original Phabricator Diff: D38460203 (e6ef083)

fbshipit-source-id: 540a48c807cea7f2898f261b82010da729f3421e
  • Loading branch information
luluwu2032 authored and facebook-github-bot committed Aug 26, 2022
1 parent cd6a913 commit 31b4a92
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 33 deletions.
5 changes: 1 addition & 4 deletions React/CoreModules/BUCK
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@fbsource//tools/build_defs/apple:flag_defs.bzl", "get_objc_arc_preprocessor_flags", "get_preprocessor_flags_for_build_mode")
load("@fbsource//tools/build_defs/oss:rn_defs.bzl", "react_native_xplat_target", "rn_apple_library", "rn_extra_build_flags")
load("@fbsource//tools/build_defs/oss:rn_defs.bzl", "rn_apple_library", "rn_extra_build_flags")
load(
"@fbsource//xplat/configurations/buck/apple/plugins/sad_xplat_hosted_configurations:react_module_registration.bzl",
"react_module_plugin_providers",
Expand Down Expand Up @@ -129,9 +129,6 @@ rn_apple_library(
],
reexport_all_header_dependencies = True,
visibility = ["PUBLIC"],
deps = [
react_native_xplat_target("react/renderer/mapbuffer:mapbufferApple"),
],
exported_deps = [
"//xplat/js/react-native-github:FBReactNativeSpecApple",
"//xplat/js/react-native-github:RCTLinkingApple",
Expand Down
3 changes: 1 addition & 2 deletions React/CoreModules/RCTExceptionsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>
#import <react/renderer/mapbuffer/MapBuffer.h>

NS_ASSUME_NONNULL_BEGIN

Expand Down Expand Up @@ -39,7 +38,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)reportFatalException:(nullable NSString *)message
stack:(nullable NSArray<NSDictionary *> *)stack
exceptionId:(double)exceptionId;
- (void)reportJsException:(const facebook::react::MapBuffer &)errorMap;
- (void)reportJsException:(NSString *)errorMap;

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

Expand Down
39 changes: 12 additions & 27 deletions React/CoreModules/RCTExceptionsManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@ @implementation RCTExceptionsManager

@synthesize moduleRegistry = _moduleRegistry;

const int FILE_KEY_OF_JS_ERROR = 0;
const int METHOD_NAME_KEY_OF_JS_ERROR = 1;
const int LINE_NUMBER_KEY_OF_JS_ERROR = 2;
const int COLUMN_KEY_OF_JS_ERROR = 3;
const int FRAMES_KEY_OF_JS_ERROR = 4;
const int MESSAGE_KEY_OF_JS_ERROR = 5;
const int ID_KEY_OF_JS_ERROR = 6;
const int IS_FATAL_KEY_OF_JS_ERROR = 7;

RCT_EXPORT_MODULE()

- (instancetype)initWithDelegate:(id<RCTExceptionsManagerDelegate>)delegate
Expand Down Expand Up @@ -159,25 +150,19 @@ - (void)reportFatal:(NSString *)message
}
}

- (void)reportJsException:(const facebook::react::MapBuffer &)errorMap
- (void)reportJsException:(NSString *)errorStr
{
NSString *message = [NSString stringWithCString:errorMap.getString(MESSAGE_KEY_OF_JS_ERROR).c_str()
encoding:[NSString defaultCStringEncoding]];
int exceptionId = errorMap.getInt(ID_KEY_OF_JS_ERROR);
BOOL isFatal = errorMap.getBool(IS_FATAL_KEY_OF_JS_ERROR);
std::vector<facebook::react::MapBuffer> frames = errorMap.getMapBufferList(FRAMES_KEY_OF_JS_ERROR);
NSMutableArray *stack = [[NSMutableArray alloc] init];
for (facebook::react::MapBuffer const &mapBuffer : frames) {
NSDictionary *frame = @{
@"file" : [NSString stringWithCString:mapBuffer.getString(FILE_KEY_OF_JS_ERROR).c_str()
encoding:[NSString defaultCStringEncoding]],
@"methodName" : [NSString stringWithCString:mapBuffer.getString(METHOD_NAME_KEY_OF_JS_ERROR).c_str()
encoding:[NSString defaultCStringEncoding]],
@"lineNumber" : [NSNumber numberWithInt:mapBuffer.getInt(LINE_NUMBER_KEY_OF_JS_ERROR)],
@"column" : [NSNumber numberWithInt:mapBuffer.getInt(COLUMN_KEY_OF_JS_ERROR)],
};
[stack addObject:frame];
}
NSData *jsonData = [errorStr dataUsingEncoding:NSUTF8StringEncoding];
NSError *jsonError;
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData
options:NSJSONWritingPrettyPrinted
error:&jsonError];

NSString *message = [dict objectForKey:@"message"];
double exceptionId = [[dict objectForKey:@"id"] doubleValue];
NSArray *stack = [dict objectForKey:@"stack"];
BOOL isFatal = [[dict objectForKey:@"isFatal"] boolValue];

if (isFatal) {
[self reportFatalException:message stack:stack exceptionId:exceptionId];
} else {
Expand Down

0 comments on commit 31b4a92

Please sign in to comment.