@@ -235,8 +235,9 @@ - (NSString *)description
235
235
RCTRemoteModulesByID = [[NSMutableDictionary alloc ] init ];
236
236
237
237
remoteModules = [[NSMutableDictionary alloc ] init ];
238
- [RCTExportedMethodsByModule () enumerateKeysAndObjectsUsingBlock: ^(NSString *moduleName, NSArray *rawMethods, BOOL *stop) {
239
-
238
+ [RCTBridgeModuleClasses () enumerateKeysAndObjectsUsingBlock: ^(NSString *moduleName, Class moduleClass, BOOL *stop) {
239
+
240
+ NSArray *rawMethods = RCTExportedMethodsByModule ()[moduleName];
240
241
NSMutableDictionary *methods = [NSMutableDictionary dictionaryWithCapacity: rawMethods.count];
241
242
[rawMethods enumerateObjectsUsingBlock: ^(RCTModuleMethod *method, NSUInteger methodID, BOOL *stop) {
242
243
methods[method.JSMethodName] = @{
@@ -249,13 +250,15 @@ - (NSString *)description
249
250
@" moduleID" : @(remoteModules.count ),
250
251
@" methods" : methods
251
252
};
252
-
253
- Class cls = RCTBridgeModuleClasses ()[moduleName];
254
- if (RCTClassOverridesClassMethod (cls, @selector (constantsToExport ))) {
255
- module = [module mutableCopy ];
256
- ((NSMutableDictionary *)module)[@" constants" ] = [cls constantsToExport ];
253
+
254
+ if (RCTClassOverridesClassMethod (moduleClass, @selector (constantsToExport ))) {
255
+ NSDictionary *constants = [moduleClass constantsToExport ];
256
+ if (constants.count ) {
257
+ module = [module mutableCopy ];
258
+ ((NSMutableDictionary *)module)[@" constants" ] = constants;
259
+ }
257
260
}
258
- remoteModules[moduleName] = module;
261
+ remoteModules[moduleName] = [ module copy ] ;
259
262
260
263
// Add module lookup
261
264
RCTRemoteModulesByID[module[@" moduleID" ]] = moduleName;
@@ -303,13 +306,13 @@ - (NSString *)description
303
306
// Add globally used methods
304
307
[JSMethods addObjectsFromArray: @[
305
308
@" Bundler.runApplication" ,
309
+ @" RCTDeviceEventEmitter.emit" ,
306
310
@" RCTEventEmitter.receiveEvent" ,
307
311
@" RCTEventEmitter.receiveTouches" ,
308
312
]];
309
313
310
314
// NOTE: these methods are currently unused in the OSS project
311
315
// @"Dimensions.set",
312
- // @"RCTDeviceEventEmitter.emit",
313
316
// @"RCTNativeAppEventEmitter.emit",
314
317
// @"ReactIOS.unmountComponentAtNodeAndRemoveContainer",
315
318
@@ -376,10 +379,15 @@ - (instancetype)initWithJavaScriptExecutor:(id<RCTJavaScriptExecutor>)javaScript
376
379
_moduleInstances = [[NSMutableDictionary alloc ] init ];
377
380
[RCTBridgeModuleClasses () enumerateKeysAndObjectsUsingBlock: ^(NSString *moduleName, Class moduleClass, BOOL *stop) {
378
381
if (_moduleInstances[moduleName] == nil ) {
382
+ id <RCTBridgeModule> moduleInstance;
379
383
if ([moduleClass instancesRespondToSelector: @selector (initWithBridge: )]) {
380
- _moduleInstances[moduleName] = [[moduleClass alloc ] initWithBridge: self ];
384
+ moduleInstance = [[moduleClass alloc ] initWithBridge: self ];
381
385
} else {
382
- _moduleInstances[moduleName] = [[moduleClass alloc ] init ];
386
+ moduleInstance = [[moduleClass alloc ] init ];
387
+ }
388
+ if (moduleInstance) {
389
+ // If nil, the module doesn't support auto-instantiation
390
+ _moduleInstances[moduleName] = moduleInstance;
383
391
}
384
392
}
385
393
}];
@@ -522,22 +530,22 @@ - (void)_handleBuffer:(id)buffer
522
530
}
523
531
524
532
if (![buffer isKindOfClass: [NSArray class ]]) {
525
- RCTLogMustFix (@" Buffer must be an instance of NSArray, got %@ " , NSStringFromClass ([buffer class ]));
533
+ RCTLogError (@" Buffer must be an instance of NSArray, got %@ " , NSStringFromClass ([buffer class ]));
526
534
return ;
527
535
}
528
536
529
537
NSArray *requestsArray = (NSArray *)buffer;
530
538
NSUInteger bufferRowCount = [requestsArray count ];
531
539
NSUInteger expectedFieldsCount = RCTBridgeFieldResponseReturnValues + 1 ;
532
540
if (bufferRowCount != expectedFieldsCount) {
533
- RCTLogMustFix (@" Must pass all fields to buffer - expected %zd , saw %zd " , expectedFieldsCount, bufferRowCount);
541
+ RCTLogError (@" Must pass all fields to buffer - expected %zd , saw %zd " , expectedFieldsCount, bufferRowCount);
534
542
return ;
535
543
}
536
544
537
545
for (NSUInteger fieldIndex = RCTBridgeFieldRequestModuleIDs; fieldIndex <= RCTBridgeFieldParamss; fieldIndex++) {
538
546
id field = [requestsArray objectAtIndex: fieldIndex];
539
547
if (![field isKindOfClass: [NSArray class ]]) {
540
- RCTLogMustFix (@" Field at index %zd in buffer must be an instance of NSArray, got %@ " , fieldIndex, NSStringFromClass ([field class ]));
548
+ RCTLogError (@" Field at index %zd in buffer must be an instance of NSArray, got %@ " , fieldIndex, NSStringFromClass ([field class ]));
541
549
return ;
542
550
}
543
551
}
@@ -549,7 +557,7 @@ - (void)_handleBuffer:(id)buffer
549
557
NSUInteger numRequests = [moduleIDs count ];
550
558
BOOL allSame = numRequests == [methodIDs count ] && numRequests == [paramsArrays count ];
551
559
if (!allSame) {
552
- RCTLogMustFix (@" Invalid data message - all must be length: %zd " , numRequests);
560
+ RCTLogError (@" Invalid data message - all must be length: %zd " , numRequests);
553
561
return ;
554
562
}
555
563
@@ -578,30 +586,30 @@ - (BOOL)_handleRequestNumber:(NSUInteger)i
578
586
params : (NSArray *)params
579
587
{
580
588
if (![params isKindOfClass: [NSArray class ]]) {
581
- RCTLogMustFix (@" Invalid module/method/params tuple for request #%zd " , i);
589
+ RCTLogError (@" Invalid module/method/params tuple for request #%zd " , i);
582
590
return NO ;
583
591
}
584
592
585
593
NSString *moduleName = RCTRemoteModulesByID[moduleID];
586
594
if (!moduleName) {
587
- RCTLogMustFix (@" Unknown moduleID: %@ " , moduleID);
595
+ RCTLogError (@" Unknown moduleID: %@ " , moduleID);
588
596
return NO ;
589
597
}
590
598
591
599
NSArray *methods = RCTExportedMethodsByModule ()[moduleName];
592
600
if (methodID >= methods.count ) {
593
- RCTLogMustFix (@" Unknown methodID: %zd for module: %@ " , methodID, moduleName);
601
+ RCTLogError (@" Unknown methodID: %zd for module: %@ " , methodID, moduleName);
594
602
return NO ;
595
603
}
596
604
597
605
RCTModuleMethod *method = methods[methodID];
598
606
NSUInteger methodArity = method.arity ;
599
607
if (params.count != methodArity) {
600
- RCTLogMustFix (@" Expected %tu arguments but got %tu invoking %@ .%@ " ,
601
- methodArity,
602
- params.count ,
603
- moduleName,
604
- method.JSMethodName );
608
+ RCTLogError (@" Expected %tu arguments but got %tu invoking %@ .%@ " ,
609
+ methodArity,
610
+ params.count ,
611
+ moduleName,
612
+ method.JSMethodName );
605
613
return NO ;
606
614
}
607
615
@@ -663,13 +671,13 @@ - (BOOL)_handleRequestNumber:(NSUInteger)i
663
671
// TODO: it seems like an error if the param doesn't respond
664
672
// so we should probably surface that error rather than failing silently
665
673
#define CASE (_value, _type, _selector ) \
666
- case _value: \
667
- if ([param respondsToSelector: @selector (_selector )]) { \
668
- _type value = [param _selector ]; \
669
- [invocation setArgument: &value atIndex: argIdx]; \
670
- shouldSet = NO ; \
671
- } \
672
- break ;
674
+ case _value: \
675
+ if ([param respondsToSelector: @selector (_selector )]) { \
676
+ _type value = [param _selector ]; \
677
+ [invocation setArgument: &value atIndex: argIdx]; \
678
+ shouldSet = NO ; \
679
+ } \
680
+ break ;
673
681
674
682
CASE (' c' , char , charValue)
675
683
CASE (' C' , unsigned char , unsignedCharValue)
@@ -698,7 +706,7 @@ - (BOOL)_handleRequestNumber:(NSUInteger)i
698
706
[invocation invoke ];
699
707
}
700
708
@catch (NSException *exception) {
701
- RCTLogMustFix (@" Exception thrown while invoking %@ on target %@ with params %@ : %@ " , method.JSMethodName , target, params, exception);
709
+ RCTLogError (@" Exception thrown while invoking %@ on target %@ with params %@ : %@ " , method.JSMethodName , target, params, exception);
702
710
}
703
711
});
704
712
0 commit comments