Skip to content

Commit

Permalink
chore(ios): optimize parameter check tips
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwcg committed May 14, 2024
1 parent e4d2df8 commit b1dea84
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions framework/ios/base/modules/HippyModuleMethod.mm
Original file line number Diff line number Diff line change
Expand Up @@ -480,9 +480,15 @@ - (id)invokeWithBridge:(HippyBridge *)bridge module:(id)module arguments:(NSArra
NSInteger actualCount = arguments.count;
NSInteger expectedCount = _argumentBlocks.count;
BOOL isArgumentsMismatch = NO;
if (actualCount > expectedCount ||
(self.functionType == HippyFunctionTypePromise && actualCount < expectedCount - 2)) {
if (actualCount > expectedCount) {
isArgumentsMismatch = YES;
} else if (self.functionType == HippyFunctionTypePromise && actualCount < expectedCount - 2) {
for (NSInteger index = actualCount; index < expectedCount - 2; index++) {
id<HippyBridgeArgument> arg = self.arguments[index];
if (arg.nullability != HippyNullable) {
isArgumentsMismatch = YES;
}
}
}
if (isArgumentsMismatch) {
HippyLogError(@"%@.%@ was called with %lld arguments but expects %lld arguments. "
Expand All @@ -499,8 +505,7 @@ - (id)invokeWithBridge:(HippyBridge *)bridge module:(id)module arguments:(NSArra
// Set arguments
NSUInteger index = 0;
for (id json in arguments) {
// release模式下,如果前端给的参数多于终端所需参数,那会造成数组越界,引起整个逻辑return。
//这里做个修改,如果前端给的参数过多,那忽略多余的参数。
// 如果前端给的参数过多,忽略多余的参数
if ([_argumentBlocks count] <= index) {
break;
}
Expand Down

0 comments on commit b1dea84

Please sign in to comment.