[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.
This commit is contained in:
Tadeu Zagallo 2015-06-15 06:04:53 -07:00
Родитель efd386eba2
Коммит d270dca210
2 изменённых файлов: 4 добавлений и 3 удалений

Просмотреть файл

@ -496,7 +496,8 @@ static RCTSparseArray *RCTExportedMethodsByModuleID(void)
Method method = methods[i];
SEL selector = method_getName(method);
if ([NSStringFromSelector(selector) hasPrefix:@"__rct_export__"]) {
NSArray *entries = ((NSArray *(*)(id, SEL))objc_msgSend)(moduleClass, selector);
IMP imp = method_getImplementation(method);
NSArray *entries = ((NSArray *(*)(id, SEL))imp)(moduleClass, selector);
RCTModuleMethod *moduleMethod =
[[RCTModuleMethod alloc] initWithObjCMethodName:entries[1]
JSMethodName:entries[0]
@ -1018,7 +1019,7 @@ RCT_INNER_BRIDGE_ONLY(_invokeAndProcessModule:(NSString *)module method:(NSStrin
if ([module conformsToProtocol:@protocol(RCTFrameUpdateObserver)]) {
[_frameUpdateObservers addObject:module];
}
}
}];
}

Просмотреть файл

@ -176,7 +176,7 @@ extern const dispatch_queue_t RCTJSThread;
* Like RCT_EXTERN_REMAP_METHOD, but allows setting a custom JavaScript name.
*/
#define RCT_EXTERN_REMAP_METHOD(js_name, method) \
+ (NSArray *)RCT_CONCAT(__rct_export__, __COUNTER__) { \
+ (NSArray *)RCT_CONCAT(__rct_export__, RCT_CONCAT(js_name, RCT_CONCAT(__LINE__, __COUNTER__))) { \
return @[@#js_name, @#method]; \
} \