diff --git a/Examples/UIExplorer/UIExplorerUnitTests/RCTModuleMethodTests.m b/Examples/UIExplorer/UIExplorerUnitTests/RCTModuleMethodTests.m index 78a95e2a8..1fb9f5527 100644 --- a/Examples/UIExplorer/UIExplorerUnitTests/RCTModuleMethodTests.m +++ b/Examples/UIExplorer/UIExplorerUnitTests/RCTModuleMethodTests.m @@ -35,6 +35,9 @@ static BOOL RCTLogsError(void (^block)(void)) @end @implementation RCTModuleMethodTests +{ + CGRect _s; +} - (void)doFooWithBar:(__unused NSString *)bar { } @@ -56,6 +59,7 @@ static BOOL RCTLogsError(void (^block)(void)) - (void)doFooWithNumber:(__unused NSNumber *)n { } - (void)doFooWithDouble:(__unused double)n { } - (void)doFooWithInteger:(__unused NSInteger)n { } +- (void)doFooWithCGRect:(CGRect)s { _s = s; } - (void)testNumbersNonnull { @@ -102,4 +106,16 @@ static BOOL RCTLogsError(void (^block)(void)) } } +- (void)testStructArgument +{ + NSString *methodName = @"doFooWithCGRect:(CGRect)s"; + RCTModuleMethod *method = [[RCTModuleMethod alloc] initWithObjCMethodName:methodName + JSMethodName:nil + moduleClass:[self class]]; + + CGRect r = CGRectMake(10, 20, 30, 40); + [method invokeWithBridge:nil module:self arguments:@[@[@10, @20, @30, @40]]]; + XCTAssertTrue(CGRectEqualToRect(r, _s)); +} + @end diff --git a/React/Base/RCTModuleMethod.m b/React/Base/RCTModuleMethod.m index a64bc46ab..f9a493e26 100644 --- a/React/Base/RCTModuleMethod.m +++ b/React/Base/RCTModuleMethod.m @@ -237,17 +237,14 @@ void RCTParseObjCMethodName(NSString **objCMethodName, NSArray **arguments) [typeInvocation setSelector:selector]; [typeInvocation setTarget:[RCTConvert class]]; - [argumentBlocks addObject: - ^(__unused RCTBridge *bridge, NSUInteger index, id json) { - + [argumentBlocks addObject:^(__unused RCTBridge *bridge, NSUInteger index, id json) { void *returnValue = malloc(typeSignature.methodReturnLength); [typeInvocation setArgument:&json atIndex:2]; [typeInvocation invoke]; [typeInvocation getReturnValue:returnValue]; - [invocation setArgument:returnValue atIndex:index + 2]; - free(returnValue); + return YES; }]; break; } @@ -411,6 +408,8 @@ void RCTParseObjCMethodName(NSString **objCMethodName, NSArray **arguments) RCTArgumentBlock block = _argumentBlocks[index]; if (!block(bridge, index, RCTNilIfNull(json))) { // Invalid argument, abort + RCTLogArgumentError(self, index, json, + "could not be processed. Aborting method call."); return; } index++;