386 final Type[] callSiteType = toTypeWithoutCallee(callSiteMethodType, 1); // Always has callee |
390 final Type[] callSiteType = toTypeWithoutCallee(callSiteMethodType, 1); // Always has callee |
387 |
391 |
388 int narrowWeightDelta = 0; |
392 int narrowWeightDelta = 0; |
389 int widenWeightDelta = 0; |
393 int widenWeightDelta = 0; |
390 final int minParamsCount = Math.min(Math.min(thisParamCount, otherParamCount), callSiteParamCount); |
394 final int minParamsCount = Math.min(Math.min(thisParamCount, otherParamCount), callSiteParamCount); |
|
395 final boolean convertsNumericArgs = cf.convertsNumericArgs(); |
391 for(int i = 0; i < minParamsCount; ++i) { |
396 for(int i = 0; i < minParamsCount; ++i) { |
392 final int callSiteParamWeight = getParamType(i, callSiteType, csVarArg).getWeight(); |
397 final Type callSiteParamType = getParamType(i, callSiteType, csVarArg); |
|
398 final Type thisParamType = getParamType(i, thisType, thisVarArg); |
|
399 if (!convertsNumericArgs && callSiteParamType.isBoolean() && thisParamType.isNumeric()) { |
|
400 // When an argument is converted to number by a function it is safe to "widen" booleans to numeric types. |
|
401 // However, we must avoid this conversion for generic functions such as Array.prototype.push. |
|
402 return false; |
|
403 } |
|
404 final int callSiteParamWeight = callSiteParamType.getWeight(); |
393 // Delta is negative for narrowing, positive for widening |
405 // Delta is negative for narrowing, positive for widening |
394 final int thisParamWeightDelta = getParamType(i, thisType, thisVarArg).getWeight() - callSiteParamWeight; |
406 final int thisParamWeightDelta = thisParamType.getWeight() - callSiteParamWeight; |
395 final int otherParamWeightDelta = getParamType(i, otherType, otherVarArg).getWeight() - callSiteParamWeight; |
407 final int otherParamWeightDelta = getParamType(i, otherType, otherVarArg).getWeight() - callSiteParamWeight; |
396 // Only count absolute values of narrowings |
408 // Only count absolute values of narrowings |
397 narrowWeightDelta += Math.max(-thisParamWeightDelta, 0) - Math.max(-otherParamWeightDelta, 0); |
409 narrowWeightDelta += Math.max(-thisParamWeightDelta, 0) - Math.max(-otherParamWeightDelta, 0); |
398 // Only count absolute values of widenings |
410 // Only count absolute values of widenings |
399 widenWeightDelta += Math.max(thisParamWeightDelta, 0) - Math.max(otherParamWeightDelta, 0); |
411 widenWeightDelta += Math.max(thisParamWeightDelta, 0) - Math.max(otherParamWeightDelta, 0); |