src/jdk/nashorn/internal/runtime/ScriptObject.java

Print this page




2059      * fewer parameters than declared and other things that JavaScript allows. This might involve
2060      * creating collectors.
2061      *
2062      * Make sure arguments are paired correctly.
2063      * @param methodHandle MethodHandle to adjust.
2064      * @param callType     MethodType of caller.
2065      * @param callerVarArg true if the caller is vararg, false otherwise, null if it should be inferred.
2066      *
2067      * @return method handle with adjusted arguments
2068      */
2069     public static MethodHandle pairArguments(final MethodHandle methodHandle, final MethodType callType, final Boolean callerVarArg) {
2070 
2071         final MethodType methodType = methodHandle.type();
2072         if (methodType.equals(callType)) {
2073             return methodHandle;
2074         }
2075 
2076         final int parameterCount = methodType.parameterCount();
2077         final int callCount      = callType.parameterCount();
2078 
2079         final boolean isCalleeVarArg = parameterCount > 1 && methodType.parameterType(parameterCount - 1).isArray();
2080         final boolean isCallerVarArg = callerVarArg != null ? callerVarArg.booleanValue() : (callCount > 1 &&
2081                 callType.parameterType(callCount - 1).isArray());
2082 
2083         if (callCount < parameterCount) {
2084             final int      missingArgs = parameterCount - callCount;
2085             final Object[] fillers     = new Object[missingArgs];
2086 
2087             Arrays.fill(fillers, UNDEFINED);
2088 
2089             if (isCalleeVarArg) {
2090                 fillers[missingArgs - 1] = new Object[0];
2091             }
2092 
2093             return MH.insertArguments(
2094                 methodHandle,
2095                 parameterCount - missingArgs,
2096                 fillers);
2097         }
2098 
2099         if (isCalleeVarArg) {




2059      * fewer parameters than declared and other things that JavaScript allows. This might involve
2060      * creating collectors.
2061      *
2062      * Make sure arguments are paired correctly.
2063      * @param methodHandle MethodHandle to adjust.
2064      * @param callType     MethodType of caller.
2065      * @param callerVarArg true if the caller is vararg, false otherwise, null if it should be inferred.
2066      *
2067      * @return method handle with adjusted arguments
2068      */
2069     public static MethodHandle pairArguments(final MethodHandle methodHandle, final MethodType callType, final Boolean callerVarArg) {
2070 
2071         final MethodType methodType = methodHandle.type();
2072         if (methodType.equals(callType)) {
2073             return methodHandle;
2074         }
2075 
2076         final int parameterCount = methodType.parameterCount();
2077         final int callCount      = callType.parameterCount();
2078 
2079         final boolean isCalleeVarArg = parameterCount > 0 && methodType.parameterType(parameterCount - 1).isArray();
2080         final boolean isCallerVarArg = callerVarArg != null ? callerVarArg.booleanValue() : (callCount > 1 &&
2081                 callType.parameterType(callCount - 1).isArray());
2082 
2083         if (callCount < parameterCount) {
2084             final int      missingArgs = parameterCount - callCount;
2085             final Object[] fillers     = new Object[missingArgs];
2086 
2087             Arrays.fill(fillers, UNDEFINED);
2088 
2089             if (isCalleeVarArg) {
2090                 fillers[missingArgs - 1] = new Object[0];
2091             }
2092 
2093             return MH.insertArguments(
2094                 methodHandle,
2095                 parameterCount - missingArgs,
2096                 fillers);
2097         }
2098 
2099         if (isCalleeVarArg) {