Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

Commit

Permalink
[iOS] Allow redundant arguments provided for callNative. (#1987)
Browse files Browse the repository at this point in the history
  • Loading branch information
wqyfavor authored and doumafang committed Jan 2, 2019
1 parent 5f162ca commit ab262a1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 5 additions & 6 deletions ios/sdk/WeexSDK/Sources/Bridge/WXBridgeMethod.m
Expand Up @@ -102,11 +102,10 @@ - (NSInvocation *)invocationWithTarget:(id)target selector:(SEL)selector
return nil;
}

NSUInteger redundantArgumentCount = 0;
NSArray *arguments = _arguments;
if (signature.numberOfArguments - 2 < arguments.count) {
NSString *errorMessage = [NSString stringWithFormat:@"%@, the parameters in calling method [%@] and registered method [%@] are not consistent!", target, _methodName, NSStringFromSelector(selector)];
WX_MONITOR_FAIL(WXMTJSBridge, WX_ERR_INVOKE_NATIVE, errorMessage);
return nil;
redundantArgumentCount = arguments.count - (signature.numberOfArguments - 2); // JS provides more arguments than required.
}

NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
Expand All @@ -116,8 +115,8 @@ - (NSInvocation *)invocationWithTarget:(id)target selector:(SEL)selector
void **freeList = NULL;

NSMutableArray *blockArray = [NSMutableArray array];
WX_ALLOC_FLIST(freeList, arguments.count);
for (int i = 0; i < arguments.count; i ++ ) {
WX_ALLOC_FLIST(freeList, arguments.count - redundantArgumentCount);
for (int i = 0; i < arguments.count - redundantArgumentCount; i ++ ) {
id obj = arguments[i];
const char *parameterType = [signature getArgumentTypeAtIndex:i + 2];
obj = [self parseArgument:obj parameterType:parameterType order:i];
Expand All @@ -138,7 +137,7 @@ - (NSInvocation *)invocationWithTarget:(id)target selector:(SEL)selector
}
}
[invocation retainArguments];
WX_FREE_FLIST(freeList, arguments.count);
WX_FREE_FLIST(freeList, arguments.count - redundantArgumentCount);

return invocation;
}
Expand Down
2 changes: 1 addition & 1 deletion ios/sdk/WeexSDK/Sources/Utility/WXUtility.h
Expand Up @@ -52,7 +52,7 @@ do {\

#define WX_FREE_FLIST(_ppFree, _count) \
do {\
for(int i = 0; i < _count; i++){\
for(int i = 0; i < (_count); i++){\
if(*(_ppFree + i ) != 0) {\
free(*(_ppFree + i));\
}\
Expand Down

0 comments on commit ab262a1

Please sign in to comment.