[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import "RCTModuleMethod.h"
|
|
|
|
|
|
|
|
#import <objc/message.h>
|
|
|
|
|
2015-07-28 20:09:22 +00:00
|
|
|
#import "RCTAssert.h"
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
#import "RCTBridge.h"
|
|
|
|
#import "RCTConvert.h"
|
|
|
|
#import "RCTLog.h"
|
|
|
|
#import "RCTUtils.h"
|
|
|
|
|
2015-08-11 20:18:08 +00:00
|
|
|
typedef BOOL (^RCTArgumentBlock)(RCTBridge *, NSUInteger, id);
|
2015-07-29 12:54:59 +00:00
|
|
|
|
|
|
|
@implementation RCTMethodArgument
|
|
|
|
|
|
|
|
- (instancetype)initWithType:(NSString *)type
|
|
|
|
nullability:(RCTNullability)nullability
|
2015-07-31 13:55:47 +00:00
|
|
|
unused:(BOOL)unused
|
2015-07-29 12:54:59 +00:00
|
|
|
{
|
|
|
|
if ((self = [super init])) {
|
|
|
|
_type = [type copy];
|
|
|
|
_nullability = nullability;
|
2015-07-31 13:55:47 +00:00
|
|
|
_unused = unused;
|
2015-07-29 12:54:59 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
@interface RCTBridge (RCTModuleMethod)
|
|
|
|
|
|
|
|
- (void)_invokeAndProcessModule:(NSString *)module
|
|
|
|
method:(NSString *)method
|
|
|
|
arguments:(NSArray *)args;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RCTModuleMethod
|
|
|
|
{
|
|
|
|
Class _moduleClass;
|
2015-08-06 22:44:15 +00:00
|
|
|
NSInvocation *_invocation;
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
NSArray *_argumentBlocks;
|
2015-08-11 15:33:28 +00:00
|
|
|
NSString *_objCMethodName;
|
|
|
|
SEL _selector;
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
}
|
|
|
|
|
2015-08-03 11:37:47 +00:00
|
|
|
static void RCTLogArgumentError(RCTModuleMethod *method, NSUInteger index,
|
|
|
|
id valueOrType, const char *issue)
|
|
|
|
{
|
|
|
|
RCTLogError(@"Argument %tu (%@) of %@.%@ %s", index, valueOrType,
|
|
|
|
RCTBridgeModuleNameForClass(method->_moduleClass),
|
|
|
|
method->_JSMethodName, issue);
|
|
|
|
}
|
|
|
|
|
2015-08-24 10:14:33 +00:00
|
|
|
RCT_NOT_IMPLEMENTED(- (instancetype)init)
|
2015-07-09 23:45:48 +00:00
|
|
|
|
2015-07-28 20:09:22 +00:00
|
|
|
void RCTParseObjCMethodName(NSString **, NSArray **);
|
2015-07-29 12:54:59 +00:00
|
|
|
void RCTParseObjCMethodName(NSString **objCMethodName, NSArray **arguments)
|
2015-07-28 20:09:22 +00:00
|
|
|
{
|
|
|
|
static NSRegularExpression *typeNameRegex;
|
|
|
|
static dispatch_once_t onceToken;
|
|
|
|
dispatch_once(&onceToken, ^{
|
|
|
|
NSString *unusedPattern = @"(?:__unused|__attribute__\\(\\(unused\\)\\))";
|
|
|
|
NSString *constPattern = @"(?:const)";
|
2015-07-29 12:54:59 +00:00
|
|
|
NSString *nullablePattern = @"(?:__nullable|nullable|__attribute__\\(\\(nullable\\)\\))";
|
|
|
|
NSString *nonnullPattern = @"(?:__nonnull|nonnull|__attribute__\\(\\(nonnull\\)\\))";
|
2015-07-31 13:55:47 +00:00
|
|
|
NSString *annotationPattern = [NSString stringWithFormat:@"(?:(?:(%@)|%@|(%@)|(%@))\\s*)",
|
2015-07-29 12:54:59 +00:00
|
|
|
unusedPattern, constPattern, nullablePattern, nonnullPattern];
|
2015-07-28 20:09:22 +00:00
|
|
|
NSString *pattern = [NSString stringWithFormat:@"(?<=:)(\\s*\\(%1$@?(\\w+?)(?:\\s*\\*)?%1$@?\\))?\\s*\\w+",
|
|
|
|
annotationPattern];
|
|
|
|
typeNameRegex = [[NSRegularExpression alloc] initWithPattern:pattern options:0 error:NULL];
|
|
|
|
});
|
|
|
|
|
|
|
|
// Extract argument types
|
|
|
|
NSString *methodName = *objCMethodName;
|
|
|
|
NSRange methodRange = {0, methodName.length};
|
2015-07-29 12:54:59 +00:00
|
|
|
NSMutableArray *args = [NSMutableArray array];
|
2015-07-28 20:09:22 +00:00
|
|
|
[typeNameRegex enumerateMatchesInString:methodName options:0 range:methodRange usingBlock:^(NSTextCheckingResult *result, __unused NSMatchingFlags flags, __unused BOOL *stop) {
|
2015-07-31 13:55:47 +00:00
|
|
|
NSRange typeRange = [result rangeAtIndex:5];
|
2015-07-29 12:54:59 +00:00
|
|
|
NSString *type = typeRange.length ? [methodName substringWithRange:typeRange] : @"id";
|
2015-07-31 13:55:47 +00:00
|
|
|
BOOL unused = ([result rangeAtIndex:2].length > 0);
|
|
|
|
RCTNullability nullability = [result rangeAtIndex:3].length ? RCTNullable :
|
|
|
|
[result rangeAtIndex:4].length ? RCTNonnullable : RCTNullabilityUnspecified;
|
|
|
|
[args addObject:[[RCTMethodArgument alloc] initWithType:type
|
|
|
|
nullability:nullability
|
|
|
|
unused:unused]];
|
2015-07-28 20:09:22 +00:00
|
|
|
}];
|
2015-07-29 12:54:59 +00:00
|
|
|
*arguments = [args copy];
|
2015-07-28 20:09:22 +00:00
|
|
|
|
|
|
|
// Remove the parameter types and names
|
|
|
|
methodName = [typeNameRegex stringByReplacingMatchesInString:methodName options:0
|
|
|
|
range:methodRange
|
|
|
|
withTemplate:@""];
|
|
|
|
|
|
|
|
// Remove whitespace
|
|
|
|
methodName = [methodName stringByReplacingOccurrencesOfString:@"\n" withString:@""];
|
|
|
|
methodName = [methodName stringByReplacingOccurrencesOfString:@" " withString:@""];
|
|
|
|
|
|
|
|
// Strip trailing semicolon
|
|
|
|
if ([methodName hasSuffix:@";"]) {
|
|
|
|
methodName = [methodName substringToIndex:methodName.length - 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
*objCMethodName = methodName;
|
|
|
|
}
|
|
|
|
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
- (instancetype)initWithObjCMethodName:(NSString *)objCMethodName
|
|
|
|
JSMethodName:(NSString *)JSMethodName
|
|
|
|
moduleClass:(Class)moduleClass
|
|
|
|
{
|
|
|
|
if ((self = [super init])) {
|
|
|
|
|
|
|
|
_moduleClass = moduleClass;
|
2015-08-11 15:33:28 +00:00
|
|
|
_objCMethodName = [objCMethodName copy];
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
_JSMethodName = JSMethodName.length > 0 ? JSMethodName : ({
|
2015-07-28 20:09:22 +00:00
|
|
|
NSString *methodName = objCMethodName;
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
NSRange colonRange = [methodName rangeOfString:@":"];
|
2015-07-28 20:09:22 +00:00
|
|
|
if (colonRange.location != NSNotFound) {
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
methodName = [methodName substringToIndex:colonRange.location];
|
|
|
|
}
|
2015-07-28 20:09:22 +00:00
|
|
|
RCTAssert(methodName.length, @"%@ is not a valid JS function name, please"
|
|
|
|
" supply an alternative using RCT_REMAP_METHOD()", objCMethodName);
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
methodName;
|
|
|
|
});
|
|
|
|
|
2015-08-11 15:33:28 +00:00
|
|
|
if ([_objCMethodName rangeOfString:@"RCTPromise"].length) {
|
|
|
|
_functionType = RCTFunctionTypePromise;
|
|
|
|
} else {
|
|
|
|
_functionType = RCTFunctionTypeNormal;
|
|
|
|
}
|
|
|
|
}
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
2015-08-11 15:33:28 +00:00
|
|
|
return self;
|
|
|
|
}
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
2015-08-11 15:33:28 +00:00
|
|
|
- (void)processMethodSignature
|
|
|
|
{
|
|
|
|
NSArray *arguments;
|
|
|
|
NSString *objCMethodName = _objCMethodName;
|
|
|
|
RCTParseObjCMethodName(&objCMethodName, &arguments);
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
2015-08-11 15:33:28 +00:00
|
|
|
_selector = NSSelectorFromString(objCMethodName);
|
|
|
|
RCTAssert(_selector, @"%@ is not a valid selector", objCMethodName);
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
2015-08-11 15:33:28 +00:00
|
|
|
// Create method invocation
|
|
|
|
NSMethodSignature *methodSignature = [_moduleClass instanceMethodSignatureForSelector:_selector];
|
|
|
|
RCTAssert(methodSignature, @"%@ is not a recognized Objective-C method.", objCMethodName);
|
|
|
|
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:methodSignature];
|
2015-08-24 10:14:33 +00:00
|
|
|
invocation.selector = _selector;
|
2015-08-11 15:33:28 +00:00
|
|
|
[invocation retainArguments];
|
|
|
|
_invocation = invocation;
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
2015-08-11 15:33:28 +00:00
|
|
|
// Process arguments
|
|
|
|
NSUInteger numberOfArguments = methodSignature.numberOfArguments;
|
|
|
|
NSMutableArray *argumentBlocks = [[NSMutableArray alloc] initWithCapacity:numberOfArguments - 2];
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
2015-08-11 15:33:28 +00:00
|
|
|
#define RCT_ARG_BLOCK(_logic) \
|
|
|
|
[argumentBlocks addObject:^(__unused RCTBridge *bridge, NSUInteger index, id json) { \
|
|
|
|
_logic \
|
|
|
|
[invocation setArgument:&value atIndex:(index) + 2]; \
|
2015-08-11 20:18:08 +00:00
|
|
|
return YES; \
|
2015-08-11 15:33:28 +00:00
|
|
|
}];
|
|
|
|
|
|
|
|
__weak RCTModuleMethod *weakSelf = self;
|
|
|
|
void (^addBlockArgument)(void) = ^{
|
|
|
|
RCT_ARG_BLOCK(
|
|
|
|
|
|
|
|
if (RCT_DEBUG && json && ![json isKindOfClass:[NSNumber class]]) {
|
|
|
|
RCTLogArgumentError(weakSelf, index, json, "should be a function");
|
2015-08-11 20:18:08 +00:00
|
|
|
return NO;
|
2015-08-11 15:33:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Marked as autoreleasing, because NSInvocation doesn't retain arguments
|
|
|
|
__autoreleasing id value = (json ? ^(NSArray *args) {
|
|
|
|
[bridge _invokeAndProcessModule:@"BatchedBridge"
|
|
|
|
method:@"invokeCallbackAndReturnFlushedQueue"
|
|
|
|
arguments:@[json, args]];
|
|
|
|
} : ^(__unused NSArray *unused) {});
|
|
|
|
)
|
|
|
|
};
|
|
|
|
|
|
|
|
for (NSUInteger i = 2; i < numberOfArguments; i++) {
|
|
|
|
const char *objcType = [methodSignature getArgumentTypeAtIndex:i];
|
|
|
|
BOOL isNullableType = NO;
|
|
|
|
RCTMethodArgument *argument = arguments[i - 2];
|
|
|
|
NSString *typeName = argument.type;
|
|
|
|
SEL selector = NSSelectorFromString([typeName stringByAppendingString:@":"]);
|
|
|
|
if ([RCTConvert respondsToSelector:selector]) {
|
|
|
|
switch (objcType[0]) {
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
2015-08-06 22:44:15 +00:00
|
|
|
#define RCT_CASE(_value, _type) \
|
2015-08-11 15:33:28 +00:00
|
|
|
case _value: { \
|
|
|
|
_type (*convert)(id, SEL, id) = (typeof(convert))objc_msgSend; \
|
|
|
|
RCT_ARG_BLOCK( _type value = convert([RCTConvert class], selector, json); ) \
|
|
|
|
break; \
|
|
|
|
}
|
2015-08-06 22:44:15 +00:00
|
|
|
|
2015-08-11 15:33:28 +00:00
|
|
|
RCT_CASE(_C_CHR, char)
|
|
|
|
RCT_CASE(_C_UCHR, unsigned char)
|
|
|
|
RCT_CASE(_C_SHT, short)
|
|
|
|
RCT_CASE(_C_USHT, unsigned short)
|
|
|
|
RCT_CASE(_C_INT, int)
|
|
|
|
RCT_CASE(_C_UINT, unsigned int)
|
|
|
|
RCT_CASE(_C_LNG, long)
|
|
|
|
RCT_CASE(_C_ULNG, unsigned long)
|
|
|
|
RCT_CASE(_C_LNG_LNG, long long)
|
|
|
|
RCT_CASE(_C_ULNG_LNG, unsigned long long)
|
|
|
|
RCT_CASE(_C_FLT, float)
|
|
|
|
RCT_CASE(_C_DBL, double)
|
|
|
|
RCT_CASE(_C_BOOL, BOOL)
|
2015-08-06 22:44:15 +00:00
|
|
|
|
|
|
|
#define RCT_NULLABLE_CASE(_value, _type) \
|
2015-08-11 15:33:28 +00:00
|
|
|
case _value: { \
|
|
|
|
isNullableType = YES; \
|
|
|
|
_type (*convert)(id, SEL, id) = (typeof(convert))objc_msgSend; \
|
|
|
|
RCT_ARG_BLOCK( _type value = convert([RCTConvert class], selector, json); ) \
|
|
|
|
break; \
|
|
|
|
}
|
2015-08-06 22:44:15 +00:00
|
|
|
|
2015-08-11 15:33:28 +00:00
|
|
|
RCT_NULLABLE_CASE(_C_SEL, SEL)
|
|
|
|
RCT_NULLABLE_CASE(_C_CHARPTR, const char *)
|
|
|
|
RCT_NULLABLE_CASE(_C_PTR, void *)
|
|
|
|
RCT_NULLABLE_CASE(_C_ID, id)
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
2015-08-11 15:33:28 +00:00
|
|
|
case _C_STRUCT_B: {
|
2015-08-06 22:44:15 +00:00
|
|
|
|
2015-08-11 15:33:28 +00:00
|
|
|
NSMethodSignature *typeSignature = [RCTConvert methodSignatureForSelector:selector];
|
|
|
|
NSInvocation *typeInvocation = [NSInvocation invocationWithMethodSignature:typeSignature];
|
2015-08-24 10:14:33 +00:00
|
|
|
typeInvocation.selector = selector;
|
|
|
|
typeInvocation.target = [RCTConvert class];
|
2015-08-06 22:44:15 +00:00
|
|
|
|
2015-08-18 13:55:25 +00:00
|
|
|
[argumentBlocks addObject:^(__unused RCTBridge *bridge, NSUInteger index, id json) {
|
2015-08-11 15:33:28 +00:00
|
|
|
void *returnValue = malloc(typeSignature.methodReturnLength);
|
|
|
|
[typeInvocation setArgument:&json atIndex:2];
|
|
|
|
[typeInvocation invoke];
|
|
|
|
[typeInvocation getReturnValue:returnValue];
|
|
|
|
[invocation setArgument:returnValue atIndex:index + 2];
|
|
|
|
free(returnValue);
|
2015-08-18 13:55:25 +00:00
|
|
|
return YES;
|
2015-08-11 15:33:28 +00:00
|
|
|
}];
|
|
|
|
break;
|
|
|
|
}
|
2015-07-07 15:47:23 +00:00
|
|
|
|
2015-08-11 15:33:28 +00:00
|
|
|
default: {
|
|
|
|
static const char *blockType = @encode(typeof(^{}));
|
|
|
|
if (!strcmp(objcType, blockType)) {
|
|
|
|
addBlockArgument();
|
|
|
|
} else {
|
|
|
|
RCTLogError(@"Unsupported argument type '%@' in method %@.",
|
|
|
|
typeName, [self methodName]);
|
2015-07-31 13:55:47 +00:00
|
|
|
}
|
2015-07-29 12:54:59 +00:00
|
|
|
}
|
2015-08-11 15:33:28 +00:00
|
|
|
}
|
|
|
|
} else if ([typeName isEqualToString:@"RCTResponseSenderBlock"]) {
|
|
|
|
addBlockArgument();
|
|
|
|
} else if ([typeName isEqualToString:@"RCTResponseErrorBlock"]) {
|
|
|
|
RCT_ARG_BLOCK(
|
2015-07-29 12:54:59 +00:00
|
|
|
|
2015-08-11 15:33:28 +00:00
|
|
|
if (RCT_DEBUG && json && ![json isKindOfClass:[NSNumber class]]) {
|
|
|
|
RCTLogArgumentError(weakSelf, index, json, "should be a function");
|
2015-08-11 20:18:08 +00:00
|
|
|
return NO;
|
2015-08-11 15:33:28 +00:00
|
|
|
}
|
2015-07-29 12:54:59 +00:00
|
|
|
|
2015-08-11 15:33:28 +00:00
|
|
|
// Marked as autoreleasing, because NSInvocation doesn't retain arguments
|
|
|
|
__autoreleasing id value = (json ? ^(NSError *error) {
|
|
|
|
[bridge _invokeAndProcessModule:@"BatchedBridge"
|
2015-08-11 20:18:08 +00:00
|
|
|
method:@"invokeCallbackAndReturnFlushedQueue"
|
2015-08-11 15:33:28 +00:00
|
|
|
arguments:@[json, @[RCTJSErrorFromNSError(error)]]];
|
|
|
|
} : ^(__unused NSError *error) {});
|
|
|
|
)
|
|
|
|
} else if ([typeName isEqualToString:@"RCTPromiseResolveBlock"]) {
|
|
|
|
RCTAssert(i == numberOfArguments - 2,
|
|
|
|
@"The RCTPromiseResolveBlock must be the second to last parameter in -[%@ %@]",
|
|
|
|
_moduleClass, objCMethodName);
|
|
|
|
RCT_ARG_BLOCK(
|
|
|
|
if (RCT_DEBUG && ![json isKindOfClass:[NSNumber class]]) {
|
|
|
|
RCTLogArgumentError(weakSelf, index, json, "should be a promise resolver function");
|
2015-08-11 20:18:08 +00:00
|
|
|
return NO;
|
2015-08-11 15:33:28 +00:00
|
|
|
}
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
2015-08-11 15:33:28 +00:00
|
|
|
// Marked as autoreleasing, because NSInvocation doesn't retain arguments
|
|
|
|
__autoreleasing RCTPromiseResolveBlock value = (^(id result) {
|
|
|
|
[bridge _invokeAndProcessModule:@"BatchedBridge"
|
|
|
|
method:@"invokeCallbackAndReturnFlushedQueue"
|
|
|
|
arguments:@[json, result ? @[result] : @[]]];
|
|
|
|
});
|
|
|
|
)
|
|
|
|
} else if ([typeName isEqualToString:@"RCTPromiseRejectBlock"]) {
|
|
|
|
RCTAssert(i == numberOfArguments - 1,
|
|
|
|
@"The RCTPromiseRejectBlock must be the last parameter in -[%@ %@]",
|
|
|
|
_moduleClass, objCMethodName);
|
|
|
|
RCT_ARG_BLOCK(
|
|
|
|
if (RCT_DEBUG && ![json isKindOfClass:[NSNumber class]]) {
|
|
|
|
RCTLogArgumentError(weakSelf, index, json, "should be a promise rejecter function");
|
2015-08-11 20:18:08 +00:00
|
|
|
return NO;
|
2015-08-11 15:33:28 +00:00
|
|
|
}
|
2015-07-29 12:54:59 +00:00
|
|
|
|
2015-08-11 15:33:28 +00:00
|
|
|
// Marked as autoreleasing, because NSInvocation doesn't retain arguments
|
|
|
|
__autoreleasing RCTPromiseRejectBlock value = (^(NSError *error) {
|
|
|
|
NSDictionary *errorJSON = RCTJSErrorFromNSError(error);
|
|
|
|
[bridge _invokeAndProcessModule:@"BatchedBridge"
|
|
|
|
method:@"invokeCallbackAndReturnFlushedQueue"
|
|
|
|
arguments:@[json, @[errorJSON]]];
|
|
|
|
});
|
|
|
|
)
|
|
|
|
} else {
|
2015-07-31 13:55:47 +00:00
|
|
|
|
2015-08-11 15:33:28 +00:00
|
|
|
// Unknown argument type
|
|
|
|
RCTLogError(@"Unknown argument type '%@' in method %@. Extend RCTConvert"
|
|
|
|
" to support this type.", typeName, [self methodName]);
|
|
|
|
}
|
2015-07-31 13:55:47 +00:00
|
|
|
|
2015-08-11 15:33:28 +00:00
|
|
|
if (RCT_DEBUG) {
|
|
|
|
|
|
|
|
RCTNullability nullability = argument.nullability;
|
|
|
|
if (!isNullableType) {
|
|
|
|
if (nullability == RCTNullable) {
|
|
|
|
RCTLogArgumentError(weakSelf, i - 2, typeName, "is marked as "
|
|
|
|
"nullable, but is not a nullable type.");
|
2015-07-31 13:55:47 +00:00
|
|
|
}
|
2015-08-11 15:33:28 +00:00
|
|
|
nullability = RCTNonnullable;
|
|
|
|
}
|
2015-07-31 13:55:47 +00:00
|
|
|
|
2015-08-11 15:33:28 +00:00
|
|
|
/**
|
|
|
|
* Special case - Numbers are not nullable in Android, so we
|
|
|
|
* don't support this for now. In future we may allow it.
|
|
|
|
*/
|
|
|
|
if ([typeName isEqualToString:@"NSNumber"]) {
|
|
|
|
BOOL unspecified = (nullability == RCTNullabilityUnspecified);
|
|
|
|
if (!argument.unused && (nullability == RCTNullable || unspecified)) {
|
|
|
|
RCTLogArgumentError(weakSelf, i - 2, typeName,
|
|
|
|
[unspecified ? @"has unspecified nullability" : @"is marked as nullable"
|
|
|
|
stringByAppendingString: @" but React requires that all NSNumber "
|
|
|
|
"arguments are explicitly marked as `nonnull` to ensure "
|
|
|
|
"compatibility with Android."].UTF8String);
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
}
|
2015-08-11 15:33:28 +00:00
|
|
|
nullability = RCTNonnullable;
|
2015-07-29 12:54:59 +00:00
|
|
|
}
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
|
2015-08-11 15:33:28 +00:00
|
|
|
if (nullability == RCTNonnullable) {
|
|
|
|
RCTArgumentBlock oldBlock = argumentBlocks[i - 2];
|
|
|
|
argumentBlocks[i - 2] = ^(RCTBridge *bridge, NSUInteger index, id json) {
|
2015-08-11 20:18:08 +00:00
|
|
|
if (json == nil) {
|
2015-08-11 15:33:28 +00:00
|
|
|
RCTLogArgumentError(weakSelf, index, typeName, "must not be null");
|
2015-08-11 20:18:08 +00:00
|
|
|
return NO;
|
2015-08-11 15:33:28 +00:00
|
|
|
} else {
|
2015-08-11 20:18:08 +00:00
|
|
|
return oldBlock(bridge, index, json);
|
2015-08-11 15:33:28 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
}
|
|
|
|
|
2015-08-11 15:33:28 +00:00
|
|
|
_argumentBlocks = [argumentBlocks copy];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (SEL)selector
|
|
|
|
{
|
|
|
|
if (_selector == NULL) {
|
|
|
|
[self processMethodSignature];
|
|
|
|
}
|
|
|
|
return _selector;
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)invokeWithBridge:(RCTBridge *)bridge
|
|
|
|
module:(id)module
|
|
|
|
arguments:(NSArray *)arguments
|
|
|
|
{
|
2015-08-11 15:33:28 +00:00
|
|
|
if (_argumentBlocks == nil) {
|
|
|
|
[self processMethodSignature];
|
|
|
|
}
|
|
|
|
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
if (RCT_DEBUG) {
|
|
|
|
|
|
|
|
// Sanity check
|
|
|
|
RCTAssert([module class] == _moduleClass, @"Attempted to invoke method \
|
|
|
|
%@ on a module of class %@", [self methodName], [module class]);
|
|
|
|
|
|
|
|
// Safety check
|
|
|
|
if (arguments.count != _argumentBlocks.count) {
|
|
|
|
NSInteger actualCount = arguments.count;
|
|
|
|
NSInteger expectedCount = _argumentBlocks.count;
|
|
|
|
|
|
|
|
// Subtract the implicit Promise resolver and rejecter functions for implementations of async functions
|
2015-08-11 15:33:28 +00:00
|
|
|
if (_functionType == RCTFunctionTypePromise) {
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
actualCount -= 2;
|
|
|
|
expectedCount -= 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
RCTLogError(@"%@.%@ was called with %zd arguments, but expects %zd",
|
|
|
|
RCTBridgeModuleNameForClass(_moduleClass), _JSMethodName,
|
|
|
|
actualCount, expectedCount);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set arguments
|
|
|
|
NSUInteger index = 0;
|
|
|
|
for (id json in arguments) {
|
2015-07-29 12:54:59 +00:00
|
|
|
RCTArgumentBlock block = _argumentBlocks[index];
|
2015-08-11 20:18:08 +00:00
|
|
|
if (!block(bridge, index, RCTNilIfNull(json))) {
|
|
|
|
// Invalid argument, abort
|
2015-08-18 13:55:25 +00:00
|
|
|
RCTLogArgumentError(self, index, json,
|
|
|
|
"could not be processed. Aborting method call.");
|
2015-08-11 20:18:08 +00:00
|
|
|
return;
|
|
|
|
}
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Invoke method
|
2015-08-06 22:44:15 +00:00
|
|
|
[_invocation invokeWithTarget:module];
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)methodName
|
|
|
|
{
|
2015-08-11 15:33:28 +00:00
|
|
|
if (_selector == NULL) {
|
|
|
|
[self processMethodSignature];
|
|
|
|
}
|
[ReactNative] Move module info from bridge to RCTModuleData
Summary:
@public
The info about bridge modules (such as id, name, queue, methods...) was spread
across arrays & dictionaries on the bridge, move it into a specific class.
It also removes a lot of information that was statically cached, and now have
the same lifecycle of the bridge.
Also moved RCTModuleMethod, RCTFrameUpdate and RCTBatchedBridge into it's own
files, for organization sake.
NOTE: This diff seems huge, but most of it was just moving code :)
Test Plan:
Tested UIExplorer & UIExplorer tests, Catalyst, MAdMan and Groups. Everything
looks fine.
2015-06-24 23:34:56 +00:00
|
|
|
return [NSString stringWithFormat:@"-[%@ %@]", _moduleClass,
|
|
|
|
NSStringFromSelector(_selector)];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)description
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat:@"<%@: %p; exports %@ as %@();>",
|
|
|
|
[self class], self, [self methodName], _JSMethodName];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|