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

[iOS] Allow redundant arguments provided for callNative. #1987

Merged
merged 1 commit into from
Jan 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions ios/sdk/WeexSDK/Sources/Bridge/WXBridgeMethod.m
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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