Skip to content

Commit d270dca

Browse files
committed
[ReactNative] Avoid method clashing on categories
Summary: @public Include `js_name` and `__LINE__` on exported methods' generated names + use the method implementation instead of `objc_msgSend` on the bridge, so it still works in case of clashing. Test Plan: Everything still working, otherwise it'd crash at startup.
1 parent efd386e commit d270dca

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

React/Base/RCTBridge.m

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,8 @@ - (NSString *)description
496496
Method method = methods[i];
497497
SEL selector = method_getName(method);
498498
if ([NSStringFromSelector(selector) hasPrefix:@"__rct_export__"]) {
499-
NSArray *entries = ((NSArray *(*)(id, SEL))objc_msgSend)(moduleClass, selector);
499+
IMP imp = method_getImplementation(method);
500+
NSArray *entries = ((NSArray *(*)(id, SEL))imp)(moduleClass, selector);
500501
RCTModuleMethod *moduleMethod =
501502
[[RCTModuleMethod alloc] initWithObjCMethodName:entries[1]
502503
JSMethodName:entries[0]
@@ -1018,7 +1019,7 @@ - (void)registerModules
10181019

10191020
if ([module conformsToProtocol:@protocol(RCTFrameUpdateObserver)]) {
10201021
[_frameUpdateObservers addObject:module];
1021-
}
1022+
}
10221023
}];
10231024
}
10241025

React/Base/RCTBridgeModule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ extern const dispatch_queue_t RCTJSThread;
176176
* Like RCT_EXTERN_REMAP_METHOD, but allows setting a custom JavaScript name.
177177
*/
178178
#define RCT_EXTERN_REMAP_METHOD(js_name, method) \
179-
+ (NSArray *)RCT_CONCAT(__rct_export__, __COUNTER__) { \
179+
+ (NSArray *)RCT_CONCAT(__rct_export__, RCT_CONCAT(js_name, RCT_CONCAT(__LINE__, __COUNTER__))) { \
180180
return @[@#js_name, @#method]; \
181181
} \
182182

0 commit comments

Comments
 (0)