jdk.nashorn.internal.objects.NativeArray Java Examples

The following examples show how to use jdk.nashorn.internal.objects.NativeArray. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NashornLinker.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a guarded invocation that converts from a source type that is NativeArray to a Java array or List or
 * Queue or Deque or Collection type.
 * @param sourceType the source type (presumably NativeArray a superclass of it)
 * @param targetType the target type (presumably an array type, or List or Queue, or Deque, or Collection)
 * @return a guarded invocation that converts from the source type to the target type. null is returned if
 * either the source type is neither NativeArray, nor a superclass of it, or if the target type is not an array
 * type, List, Queue, Deque, or Collection.
 */
private static GuardedInvocation getArrayConverter(final Class<?> sourceType, final Class<?> targetType) {
    final boolean isSourceTypeNativeArray = sourceType == NativeArray.class;
    // If source type is more generic than NativeArray class, we'll need to use a guard
    final boolean isSourceTypeGeneric = !isSourceTypeNativeArray && sourceType.isAssignableFrom(NativeArray.class);

    if (isSourceTypeNativeArray || isSourceTypeGeneric) {
        final MethodHandle guard = isSourceTypeGeneric ? IS_NATIVE_ARRAY : null;
        if(targetType.isArray()) {
            return new GuardedInvocation(ARRAY_CONVERTERS.get(targetType), guard);
        } else if(targetType == List.class) {
            return new GuardedInvocation(TO_LIST, guard);
        } else if(targetType == Deque.class) {
            return new GuardedInvocation(TO_DEQUE, guard);
        } else if(targetType == Queue.class) {
            return new GuardedInvocation(TO_QUEUE, guard);
        } else if(targetType == Collection.class) {
            return new GuardedInvocation(TO_COLLECTION, guard);
        }
    }
    return null;
}
 
Example #2
Source File: MethodEmitter.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Helper function to generate a function signature based on stack contents
 * and argument count and return type
 *
 * @param returnType return type
 * @param argCount   argument count
 *
 * @return function signature for stack contents
 */
private String getDynamicSignature(final Type returnType, final int argCount) {
    final Type[]         paramTypes = new Type[argCount];

    int pos = 0;
    for (int i = argCount - 1; i >= 0; i--) {
        Type pt = stack.peek(pos++);
        // "erase" specific ScriptObject subtype info - except for NativeArray.
        // NativeArray is used for array/List/Deque conversion for Java calls.
        if (ScriptObject.class.isAssignableFrom(pt.getTypeClass()) &&
            !NativeArray.class.isAssignableFrom(pt.getTypeClass())) {
            pt = Type.SCRIPT_OBJECT;
        }
        paramTypes[i] = pt;
    }
    final String descriptor = Type.getMethodDescriptor(returnType, paramTypes);
    for (int i = 0; i < argCount; i++) {
        popType(paramTypes[argCount - i - 1]);
    }

    return descriptor;
}
 
Example #3
Source File: MethodEmitter.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Helper function to generate a function signature based on stack contents
 * and argument count and return type
 *
 * @param returnType return type
 * @param argCount   argument count
 *
 * @return function signature for stack contents
 */
private String getDynamicSignature(final Type returnType, final int argCount) {
    final Type[]         paramTypes = new Type[argCount];

    int pos = 0;
    for (int i = argCount - 1; i >= 0; i--) {
        Type pt = stack.peek(pos++);
        // "erase" specific ScriptObject subtype info - except for NativeArray.
        // NativeArray is used for array/List/Deque conversion for Java calls.
        if (ScriptObject.class.isAssignableFrom(pt.getTypeClass()) &&
            !NativeArray.class.isAssignableFrom(pt.getTypeClass())) {
            pt = Type.SCRIPT_OBJECT;
        }
        paramTypes[i] = pt;
    }
    final String descriptor = Type.getMethodDescriptor(returnType, paramTypes);
    for (int i = 0; i < argCount; i++) {
        popType(paramTypes[argCount - i - 1]);
    }

    return descriptor;
}
 
Example #4
Source File: NashornLinker.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a guarded invocation that converts from a source type that is NativeArray to a Java array or List or
 * Queue or Deque or Collection type.
 * @param sourceType the source type (presumably NativeArray a superclass of it)
 * @param targetType the target type (presumably an array type, or List or Queue, or Deque, or Collection)
 * @return a guarded invocation that converts from the source type to the target type. null is returned if
 * either the source type is neither NativeArray, nor a superclass of it, or if the target type is not an array
 * type, List, Queue, Deque, or Collection.
 */
private static GuardedInvocation getArrayConverter(final Class<?> sourceType, final Class<?> targetType) {
    final boolean isSourceTypeNativeArray = sourceType == NativeArray.class;
    // If source type is more generic than NativeArray class, we'll need to use a guard
    final boolean isSourceTypeGeneric = !isSourceTypeNativeArray && sourceType.isAssignableFrom(NativeArray.class);

    if (isSourceTypeNativeArray || isSourceTypeGeneric) {
        final MethodHandle guard = isSourceTypeGeneric ? IS_NATIVE_ARRAY : null;
        if(targetType.isArray()) {
            return new GuardedInvocation(ARRAY_CONVERTERS.get(targetType), guard);
        } else if(targetType == List.class) {
            return new GuardedInvocation(TO_LIST, guard);
        } else if(targetType == Deque.class) {
            return new GuardedInvocation(TO_DEQUE, guard);
        } else if(targetType == Queue.class) {
            return new GuardedInvocation(TO_QUEUE, guard);
        } else if(targetType == Collection.class) {
            return new GuardedInvocation(TO_COLLECTION, guard);
        }
    }
    return null;
}
 
Example #5
Source File: NashornLinker.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a guarded invocation that converts from a source type that is NativeArray to a Java array or List or
 * Queue or Deque or Collection type.
 * @param sourceType the source type (presumably NativeArray a superclass of it)
 * @param targetType the target type (presumably an array type, or List or Queue, or Deque, or Collection)
 * @return a guarded invocation that converts from the source type to the target type. null is returned if
 * either the source type is neither NativeArray, nor a superclass of it, or if the target type is not an array
 * type, List, Queue, Deque, or Collection.
 */
private static GuardedInvocation getArrayConverter(final Class<?> sourceType, final Class<?> targetType) {
    final boolean isSourceTypeNativeArray = sourceType == NativeArray.class;
    // If source type is more generic than NativeArray class, we'll need to use a guard
    final boolean isSourceTypeGeneric = !isSourceTypeNativeArray && sourceType.isAssignableFrom(NativeArray.class);

    if (isSourceTypeNativeArray || isSourceTypeGeneric) {
        final MethodHandle guard = isSourceTypeGeneric ? IS_NATIVE_ARRAY : null;
        if(targetType.isArray()) {
            return new GuardedInvocation(ARRAY_CONVERTERS.get(targetType), guard);
        } else if(targetType == List.class) {
            return new GuardedInvocation(TO_LIST, guard);
        } else if(targetType == Deque.class) {
            return new GuardedInvocation(TO_DEQUE, guard);
        } else if(targetType == Queue.class) {
            return new GuardedInvocation(TO_QUEUE, guard);
        } else if(targetType == Collection.class) {
            return new GuardedInvocation(TO_COLLECTION, guard);
        }
    }
    return null;
}
 
Example #6
Source File: MethodEmitter.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Helper function to generate a function signature based on stack contents
 * and argument count and return type
 *
 * @param returnType return type
 * @param argCount   argument count
 *
 * @return function signature for stack contents
 */
private String getDynamicSignature(final Type returnType, final int argCount) {
    final Type[]         paramTypes = new Type[argCount];

    int pos = 0;
    for (int i = argCount - 1; i >= 0; i--) {
        Type pt = stack.peek(pos++);
        // "erase" specific ScriptObject subtype info - except for NativeArray.
        // NativeArray is used for array/List/Deque conversion for Java calls.
        if (ScriptObject.class.isAssignableFrom(pt.getTypeClass()) &&
            !NativeArray.class.isAssignableFrom(pt.getTypeClass())) {
            pt = Type.SCRIPT_OBJECT;
        }
        paramTypes[i] = pt;
    }
    final String descriptor = Type.getMethodDescriptor(returnType, paramTypes);
    for (int i = 0; i < argCount; i++) {
        popType(paramTypes[argCount - i - 1]);
    }

    return descriptor;
}
 
Example #7
Source File: MethodEmitter.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Helper function to generate a function signature based on stack contents
 * and argument count and return type
 *
 * @param returnType return type
 * @param argCount   argument count
 *
 * @return function signature for stack contents
 */
private String getDynamicSignature(final Type returnType, final int argCount) {
    final Type[]         paramTypes = new Type[argCount];

    int pos = 0;
    for (int i = argCount - 1; i >= 0; i--) {
        Type pt = stack.peek(pos++);
        // "erase" specific ScriptObject subtype info - except for NativeArray.
        // NativeArray is used for array/List/Deque conversion for Java calls.
        if (ScriptObject.class.isAssignableFrom(pt.getTypeClass()) &&
            !NativeArray.class.isAssignableFrom(pt.getTypeClass())) {
            pt = Type.SCRIPT_OBJECT;
        }
        paramTypes[i] = pt;
    }
    final String descriptor = Type.getMethodDescriptor(returnType, paramTypes);
    for (int i = 0; i < argCount; i++) {
        popType(paramTypes[argCount - i - 1]);
    }

    return descriptor;
}
 
Example #8
Source File: NashornLinker.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a guarded invocation that converts from a source type that is NativeArray to a Java array or List or
 * Deque type.
 * @param sourceType the source type (presumably NativeArray a superclass of it)
 * @param targetType the target type (presumably an array type, or List or Deque)
 * @return a guarded invocation that converts from the source type to the target type. null is returned if
 * either the source type is neither NativeArray, nor a superclass of it, or if the target type is not an array
 * type, List, or Deque.
 */
private static GuardedInvocation getArrayConverter(final Class<?> sourceType, final Class<?> targetType) {
    final boolean isSourceTypeNativeArray = sourceType == NativeArray.class;
    // If source type is more generic than ScriptFunction class, we'll need to use a guard
    final boolean isSourceTypeGeneric = !isSourceTypeNativeArray && sourceType.isAssignableFrom(NativeArray.class);

    if (isSourceTypeNativeArray || isSourceTypeGeneric) {
        final MethodHandle guard = isSourceTypeGeneric ? IS_NATIVE_ARRAY : null;
        if(targetType.isArray()) {
            return new GuardedInvocation(ARRAY_CONVERTERS.get(targetType), guard);
        }
        if(targetType == List.class) {
            return new GuardedInvocation(JSType.TO_JAVA_LIST.methodHandle(), guard);
        }
        if(targetType == Deque.class) {
            return new GuardedInvocation(JSType.TO_JAVA_DEQUE.methodHandle(), guard);
        }
    }
    return null;
}
 
Example #9
Source File: NashornLinker.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a guarded invocation that converts from a source type that is NativeArray to a Java array or List or
 * Deque type.
 * @param sourceType the source type (presumably NativeArray a superclass of it)
 * @param targetType the target type (presumably an array type, or List or Deque)
 * @return a guarded invocation that converts from the source type to the target type. null is returned if
 * either the source type is neither NativeArray, nor a superclass of it, or if the target type is not an array
 * type, List, or Deque.
 */
private static GuardedInvocation getArrayConverter(final Class<?> sourceType, final Class<?> targetType) {
    final boolean isSourceTypeNativeArray = sourceType == NativeArray.class;
    // If source type is more generic than ScriptFunction class, we'll need to use a guard
    final boolean isSourceTypeGeneric = !isSourceTypeNativeArray && sourceType.isAssignableFrom(NativeArray.class);

    if (isSourceTypeNativeArray || isSourceTypeGeneric) {
        final MethodHandle guard = isSourceTypeGeneric ? IS_NATIVE_ARRAY : null;
        if(targetType.isArray()) {
            return new GuardedInvocation(ARRAY_CONVERTERS.get(targetType), guard);
        }
        if(targetType == List.class) {
            return new GuardedInvocation(JSType.TO_JAVA_LIST.methodHandle(), guard);
        }
        if(targetType == Deque.class) {
            return new GuardedInvocation(JSType.TO_JAVA_DEQUE.methodHandle(), guard);
        }
    }
    return null;
}
 
Example #10
Source File: MethodEmitter.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Helper function to generate a function signature based on stack contents
 * and argument count and return type
 *
 * @param returnType return type
 * @param argCount   argument count
 *
 * @return function signature for stack contents
 */
private String getDynamicSignature(final Type returnType, final int argCount) {
    final Type[]         paramTypes = new Type[argCount];

    int pos = 0;
    for (int i = argCount - 1; i >= 0; i--) {
        Type pt = stack.peek(pos++);
        // "erase" specific ScriptObject subtype info - except for NativeArray.
        // NativeArray is used for array/List/Deque conversion for Java calls.
        if (ScriptObject.class.isAssignableFrom(pt.getTypeClass()) &&
            !NativeArray.class.isAssignableFrom(pt.getTypeClass())) {
            pt = Type.SCRIPT_OBJECT;
        }
        paramTypes[i] = pt;
    }
    final String descriptor = Type.getMethodDescriptor(returnType, paramTypes);
    for (int i = 0; i < argCount; i++) {
        popType(paramTypes[argCount - i - 1]);
    }

    return descriptor;
}
 
Example #11
Source File: NashornLinker.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a guarded invocation that converts from a source type that is NativeArray to a Java array or List or
 * Queue or Deque or Collection type.
 * @param sourceType the source type (presumably NativeArray a superclass of it)
 * @param targetType the target type (presumably an array type, or List or Queue, or Deque, or Collection)
 * @return a guarded invocation that converts from the source type to the target type. null is returned if
 * either the source type is neither NativeArray, nor a superclass of it, or if the target type is not an array
 * type, List, Queue, Deque, or Collection.
 */
private static GuardedInvocation getArrayConverter(final Class<?> sourceType, final Class<?> targetType) {
    final boolean isSourceTypeNativeArray = sourceType == NativeArray.class;
    // If source type is more generic than NativeArray class, we'll need to use a guard
    final boolean isSourceTypeGeneric = !isSourceTypeNativeArray && sourceType.isAssignableFrom(NativeArray.class);

    if (isSourceTypeNativeArray || isSourceTypeGeneric) {
        final MethodHandle guard = isSourceTypeGeneric ? IS_NATIVE_ARRAY : null;
        if(targetType.isArray()) {
            return new GuardedInvocation(ARRAY_CONVERTERS.get(targetType), guard);
        } else if(targetType == List.class) {
            return new GuardedInvocation(TO_LIST, guard);
        } else if(targetType == Deque.class) {
            return new GuardedInvocation(TO_DEQUE, guard);
        } else if(targetType == Queue.class) {
            return new GuardedInvocation(TO_QUEUE, guard);
        } else if(targetType == Collection.class) {
            return new GuardedInvocation(TO_COLLECTION, guard);
        }
    }
    return null;
}
 
Example #12
Source File: NashornLinker.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a guarded invocation that converts from a source type that is NativeArray to a Java array or List or
 * Queue or Deque or Collection type.
 * @param sourceType the source type (presumably NativeArray a superclass of it)
 * @param targetType the target type (presumably an array type, or List or Queue, or Deque, or Collection)
 * @return a guarded invocation that converts from the source type to the target type. null is returned if
 * either the source type is neither NativeArray, nor a superclass of it, or if the target type is not an array
 * type, List, Queue, Deque, or Collection.
 */
private static GuardedInvocation getArrayConverter(final Class<?> sourceType, final Class<?> targetType) {
    final boolean isSourceTypeNativeArray = sourceType == NativeArray.class;
    // If source type is more generic than NativeArray class, we'll need to use a guard
    final boolean isSourceTypeGeneric = !isSourceTypeNativeArray && sourceType.isAssignableFrom(NativeArray.class);

    if (isSourceTypeNativeArray || isSourceTypeGeneric) {
        final MethodHandle guard = isSourceTypeGeneric ? IS_NATIVE_ARRAY : null;
        if(targetType.isArray()) {
            return new GuardedInvocation(ARRAY_CONVERTERS.get(targetType), guard);
        } else if(targetType == List.class) {
            return new GuardedInvocation(TO_LIST, guard);
        } else if(targetType == Deque.class) {
            return new GuardedInvocation(TO_DEQUE, guard);
        } else if(targetType == Queue.class) {
            return new GuardedInvocation(TO_QUEUE, guard);
        } else if(targetType == Collection.class) {
            return new GuardedInvocation(TO_COLLECTION, guard);
        }
    }
    return null;
}
 
Example #13
Source File: MethodEmitter.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Helper function to generate a function signature based on stack contents
 * and argument count and return type
 *
 * @param returnType return type
 * @param argCount   argument count
 *
 * @return function signature for stack contents
 */
private String getDynamicSignature(final Type returnType, final int argCount) {
    final Type[]         paramTypes = new Type[argCount];

    int pos = 0;
    for (int i = argCount - 1; i >= 0; i--) {
        Type pt = stack.peek(pos++);
        // "erase" specific ScriptObject subtype info - except for NativeArray.
        // NativeArray is used for array/List/Deque conversion for Java calls.
        if (ScriptObject.class.isAssignableFrom(pt.getTypeClass()) &&
            !NativeArray.class.isAssignableFrom(pt.getTypeClass())) {
            pt = Type.SCRIPT_OBJECT;
        }
        paramTypes[i] = pt;
    }
    final String descriptor = Type.getMethodDescriptor(returnType, paramTypes);
    for (int i = 0; i < argCount; i++) {
        popType(paramTypes[argCount - i - 1]);
    }

    return descriptor;
}
 
Example #14
Source File: MethodEmitter.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Helper function to generate a function signature based on stack contents
 * and argument count and return type
 *
 * @param returnType return type
 * @param argCount   argument count
 *
 * @return function signature for stack contents
 */
private String getDynamicSignature(final Type returnType, final int argCount) {
    final Type[]         paramTypes = new Type[argCount];

    int pos = 0;
    for (int i = argCount - 1; i >= 0; i--) {
        Type pt = stack.peek(pos++);
        // "erase" specific ScriptObject subtype info - except for NativeArray.
        // NativeArray is used for array/List/Deque conversion for Java calls.
        if (ScriptObject.class.isAssignableFrom(pt.getTypeClass()) &&
            !NativeArray.class.isAssignableFrom(pt.getTypeClass())) {
            pt = Type.SCRIPT_OBJECT;
        }
        paramTypes[i] = pt;
    }
    final String descriptor = Type.getMethodDescriptor(returnType, paramTypes);
    for (int i = 0; i < argCount; i++) {
        popType(paramTypes[argCount - i - 1]);
    }

    return descriptor;
}
 
Example #15
Source File: NashornLinker.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a guarded invocation that converts from a source type that is NativeArray to a Java array or List or
 * Queue or Deque or Collection type.
 * @param sourceType the source type (presumably NativeArray a superclass of it)
 * @param targetType the target type (presumably an array type, or List or Queue, or Deque, or Collection)
 * @return a guarded invocation that converts from the source type to the target type. null is returned if
 * either the source type is neither NativeArray, nor a superclass of it, or if the target type is not an array
 * type, List, Queue, Deque, or Collection.
 */
private static GuardedInvocation getArrayConverter(final Class<?> sourceType, final Class<?> targetType) {
    final boolean isSourceTypeNativeArray = sourceType == NativeArray.class;
    // If source type is more generic than NativeArray class, we'll need to use a guard
    final boolean isSourceTypeGeneric = !isSourceTypeNativeArray && sourceType.isAssignableFrom(NativeArray.class);

    if (isSourceTypeNativeArray || isSourceTypeGeneric) {
        final MethodHandle guard = isSourceTypeGeneric ? IS_NATIVE_ARRAY : null;
        if(targetType.isArray()) {
            return new GuardedInvocation(ARRAY_CONVERTERS.get(targetType), guard);
        } else if(targetType == List.class) {
            return new GuardedInvocation(TO_LIST, guard);
        } else if(targetType == Deque.class) {
            return new GuardedInvocation(TO_DEQUE, guard);
        } else if(targetType == Queue.class) {
            return new GuardedInvocation(TO_QUEUE, guard);
        } else if(targetType == Collection.class) {
            return new GuardedInvocation(TO_COLLECTION, guard);
        }
    }
    return null;
}
 
Example #16
Source File: NashornLinker.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Comparison compareConversion(final Class<?> sourceType, final Class<?> targetType1, final Class<?> targetType2) {
    if(sourceType == NativeArray.class) {
        // Prefer those types we can convert to with just a wrapper (cheaper than Java array creation).
        if(isArrayPreferredTarget(targetType1)) {
            if(!isArrayPreferredTarget(targetType2)) {
                return Comparison.TYPE_1_BETTER;
            }
        } else if(isArrayPreferredTarget(targetType2)) {
            return Comparison.TYPE_2_BETTER;
        }
        // Then prefer Java arrays
        if(targetType1.isArray()) {
            if(!targetType2.isArray()) {
                return Comparison.TYPE_1_BETTER;
            }
        } else if(targetType2.isArray()) {
            return Comparison.TYPE_2_BETTER;
        }
    }
    if(ScriptObject.class.isAssignableFrom(sourceType)) {
        // Prefer interfaces
        if(targetType1.isInterface()) {
            if(!targetType2.isInterface()) {
                return Comparison.TYPE_1_BETTER;
            }
        } else if(targetType2.isInterface()) {
            return Comparison.TYPE_2_BETTER;
        }
    }
    return Comparison.INDETERMINATE;
}
 
Example #17
Source File: NashornLinker.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Comparison compareConversion(final Class<?> sourceType, final Class<?> targetType1, final Class<?> targetType2) {
    if(sourceType == NativeArray.class) {
        // Prefer lists, as they're less costly to create than arrays.
        if(isList(targetType1)) {
            if(!isList(targetType2)) {
                return Comparison.TYPE_1_BETTER;
            }
        } else if(isList(targetType2)) {
            return Comparison.TYPE_2_BETTER;
        }
        // Then prefer arrays
        if(targetType1.isArray()) {
            if(!targetType2.isArray()) {
                return Comparison.TYPE_1_BETTER;
            }
        } else if(targetType2.isArray()) {
            return Comparison.TYPE_2_BETTER;
        }
    }
    if(ScriptObject.class.isAssignableFrom(sourceType)) {
        // Prefer interfaces
        if(targetType1.isInterface()) {
            if(!targetType2.isInterface()) {
                return Comparison.TYPE_1_BETTER;
            }
        } else if(targetType2.isInterface()) {
            return Comparison.TYPE_2_BETTER;
        }
    }
    return Comparison.INDETERMINATE;
}
 
Example #18
Source File: NashornLinker.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Comparison compareConversion(final Class<?> sourceType, final Class<?> targetType1, final Class<?> targetType2) {
    if(sourceType == NativeArray.class) {
        // Prefer lists, as they're less costly to create than arrays.
        if(isList(targetType1)) {
            if(!isList(targetType2)) {
                return Comparison.TYPE_1_BETTER;
            }
        } else if(isList(targetType2)) {
            return Comparison.TYPE_2_BETTER;
        }
        // Then prefer arrays
        if(targetType1.isArray()) {
            if(!targetType2.isArray()) {
                return Comparison.TYPE_1_BETTER;
            }
        } else if(targetType2.isArray()) {
            return Comparison.TYPE_2_BETTER;
        }
    }
    if(ScriptObject.class.isAssignableFrom(sourceType)) {
        // Prefer interfaces
        if(targetType1.isInterface()) {
            if(!targetType2.isInterface()) {
                return Comparison.TYPE_1_BETTER;
            }
        } else if(targetType2.isInterface()) {
            return Comparison.TYPE_2_BETTER;
        }
    }
    return Comparison.INDETERMINATE;
}
 
Example #19
Source File: NashornLinker.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Comparison compareConversion(final Class<?> sourceType, final Class<?> targetType1, final Class<?> targetType2) {
    if(sourceType == NativeArray.class) {
        // Prefer those types we can convert to with just a wrapper (cheaper than Java array creation).
        if(isArrayPreferredTarget(targetType1)) {
            if(!isArrayPreferredTarget(targetType2)) {
                return Comparison.TYPE_1_BETTER;
            }
        } else if(isArrayPreferredTarget(targetType2)) {
            return Comparison.TYPE_2_BETTER;
        }
        // Then prefer Java arrays
        if(targetType1.isArray()) {
            if(!targetType2.isArray()) {
                return Comparison.TYPE_1_BETTER;
            }
        } else if(targetType2.isArray()) {
            return Comparison.TYPE_2_BETTER;
        }
    }
    if(ScriptObject.class.isAssignableFrom(sourceType)) {
        // Prefer interfaces
        if(targetType1.isInterface()) {
            if(!targetType2.isInterface()) {
                return Comparison.TYPE_1_BETTER;
            }
        } else if(targetType2.isInterface()) {
            return Comparison.TYPE_2_BETTER;
        }
    }
    return Comparison.INDETERMINATE;
}
 
Example #20
Source File: NashornLinker.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Comparison compareConversion(final Class<?> sourceType, final Class<?> targetType1, final Class<?> targetType2) {
    if(sourceType == NativeArray.class) {
        // Prefer lists, as they're less costly to create than arrays.
        if(isList(targetType1)) {
            if(!isList(targetType2)) {
                return Comparison.TYPE_1_BETTER;
            }
        } else if(isList(targetType2)) {
            return Comparison.TYPE_2_BETTER;
        }
        // Then prefer arrays
        if(targetType1.isArray()) {
            if(!targetType2.isArray()) {
                return Comparison.TYPE_1_BETTER;
            }
        } else if(targetType2.isArray()) {
            return Comparison.TYPE_2_BETTER;
        }
    }
    if(ScriptObject.class.isAssignableFrom(sourceType)) {
        // Prefer interfaces
        if(targetType1.isInterface()) {
            if(!targetType2.isInterface()) {
                return Comparison.TYPE_1_BETTER;
            }
        } else if(targetType2.isInterface()) {
            return Comparison.TYPE_2_BETTER;
        }
    }
    return Comparison.INDETERMINATE;
}
 
Example #21
Source File: NashornLinker.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Comparison compareConversion(final Class<?> sourceType, final Class<?> targetType1, final Class<?> targetType2) {
    if(sourceType == NativeArray.class) {
        // Prefer those types we can convert to with just a wrapper (cheaper than Java array creation).
        if(isArrayPreferredTarget(targetType1)) {
            if(!isArrayPreferredTarget(targetType2)) {
                return Comparison.TYPE_1_BETTER;
            }
        } else if(isArrayPreferredTarget(targetType2)) {
            return Comparison.TYPE_2_BETTER;
        }
        // Then prefer Java arrays
        if(targetType1.isArray()) {
            if(!targetType2.isArray()) {
                return Comparison.TYPE_1_BETTER;
            }
        } else if(targetType2.isArray()) {
            return Comparison.TYPE_2_BETTER;
        }
    }
    if(ScriptObject.class.isAssignableFrom(sourceType)) {
        // Prefer interfaces
        if(targetType1.isInterface()) {
            if(!targetType2.isInterface()) {
                return Comparison.TYPE_1_BETTER;
            }
        } else if(targetType2.isInterface()) {
            return Comparison.TYPE_2_BETTER;
        }
    }
    return Comparison.INDETERMINATE;
}
 
Example #22
Source File: NashornLinker.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Comparison compareConversion(final Class<?> sourceType, final Class<?> targetType1, final Class<?> targetType2) {
    if(sourceType == NativeArray.class) {
        // Prefer those types we can convert to with just a wrapper (cheaper than Java array creation).
        if(isArrayPreferredTarget(targetType1)) {
            if(!isArrayPreferredTarget(targetType2)) {
                return Comparison.TYPE_1_BETTER;
            }
        } else if(isArrayPreferredTarget(targetType2)) {
            return Comparison.TYPE_2_BETTER;
        }
        // Then prefer Java arrays
        if(targetType1.isArray()) {
            if(!targetType2.isArray()) {
                return Comparison.TYPE_1_BETTER;
            }
        } else if(targetType2.isArray()) {
            return Comparison.TYPE_2_BETTER;
        }
    }
    if(ScriptObject.class.isAssignableFrom(sourceType)) {
        // Prefer interfaces
        if(targetType1.isInterface()) {
            if(!targetType2.isInterface()) {
                return Comparison.TYPE_1_BETTER;
            }
        } else if(targetType2.isInterface()) {
            return Comparison.TYPE_2_BETTER;
        }
    }
    return Comparison.INDETERMINATE;
}
 
Example #23
Source File: NashornLinker.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Comparison compareConversion(final Class<?> sourceType, final Class<?> targetType1, final Class<?> targetType2) {
    if(sourceType == NativeArray.class) {
        // Prefer lists, as they're less costly to create than arrays.
        if(isList(targetType1)) {
            if(!isList(targetType2)) {
                return Comparison.TYPE_1_BETTER;
            }
        } else if(isList(targetType2)) {
            return Comparison.TYPE_2_BETTER;
        }
        // Then prefer arrays
        if(targetType1.isArray()) {
            if(!targetType2.isArray()) {
                return Comparison.TYPE_1_BETTER;
            }
        } else if(targetType2.isArray()) {
            return Comparison.TYPE_2_BETTER;
        }
    }
    if(ScriptObject.class.isAssignableFrom(sourceType)) {
        // Prefer interfaces
        if(targetType1.isInterface()) {
            if(!targetType2.isInterface()) {
                return Comparison.TYPE_1_BETTER;
            }
        } else if(targetType2.isInterface()) {
            return Comparison.TYPE_2_BETTER;
        }
    }
    return Comparison.INDETERMINATE;
}
 
Example #24
Source File: NashornLinker.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Override
public Comparison compareConversion(final Class<?> sourceType, final Class<?> targetType1, final Class<?> targetType2) {
    if(sourceType == NativeArray.class) {
        // Prefer those types we can convert to with just a wrapper (cheaper than Java array creation).
        if(isArrayPreferredTarget(targetType1)) {
            if(!isArrayPreferredTarget(targetType2)) {
                return Comparison.TYPE_1_BETTER;
            }
        } else if(isArrayPreferredTarget(targetType2)) {
            return Comparison.TYPE_2_BETTER;
        }
        // Then prefer Java arrays
        if(targetType1.isArray()) {
            if(!targetType2.isArray()) {
                return Comparison.TYPE_1_BETTER;
            }
        } else if(targetType2.isArray()) {
            return Comparison.TYPE_2_BETTER;
        }
    }
    if(ScriptObject.class.isAssignableFrom(sourceType)) {
        // Prefer interfaces
        if(targetType1.isInterface()) {
            if(!targetType2.isInterface()) {
                return Comparison.TYPE_1_BETTER;
            }
        } else if(targetType2.isInterface()) {
            return Comparison.TYPE_2_BETTER;
        }
    }
    return Comparison.INDETERMINATE;
}
 
Example #25
Source File: JDK_8078414_Test.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testCanConvertScriptObjectSubclassToMirror() {
    assertCanConvertToMirror(NativeArray.class);
}
 
Example #26
Source File: LiteralNode.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Type getType() {
    return Type.typeFor(NativeArray.class);
}
 
Example #27
Source File: LiteralNode.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Type getType() {
    return Type.typeFor(NativeArray.class);
}
 
Example #28
Source File: JDK_8078414_Test.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testCanConvertScriptObjectSubclassToMirror() {
    assertCanConvertToMirror(NativeArray.class);
}
 
Example #29
Source File: LiteralNode.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Type getType() {
    return Type.typeFor(NativeArray.class);
}
 
Example #30
Source File: LiteralNode.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Type getType() {
    return Type.typeFor(NativeArray.class);
}