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 Project: TencentKona-8   Author: Tencent   File: NashornLinker.java    License: 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 Project: TencentKona-8   Author: Tencent   File: MethodEmitter.java    License: 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 Project: jdk8u60   Author: chenghanpeng   File: NashornLinker.java    License: 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 #4
Source Project: jdk8u60   Author: chenghanpeng   File: MethodEmitter.java    License: 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 #5
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: NashornLinker.java    License: 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 Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: MethodEmitter.java    License: 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 Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: NashornLinker.java    License: 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 #8
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: MethodEmitter.java    License: 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 #9
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: MethodEmitter.java    License: 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 #10
Source Project: hottub   Author: dsrg-uoft   File: NashornLinker.java    License: 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 #11
Source Project: hottub   Author: dsrg-uoft   File: MethodEmitter.java    License: 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 #12
Source Project: openjdk-8-source   Author: keerath   File: NashornLinker.java    License: 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 #13
Source Project: openjdk-8   Author: bpupadhyaya   File: NashornLinker.java    License: 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 #14
Source Project: jdk8u_nashorn   Author: JetBrains   File: NashornLinker.java    License: 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 #15
Source Project: jdk8u_nashorn   Author: JetBrains   File: MethodEmitter.java    License: 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 #16
Source Project: TencentKona-8   Author: Tencent   File: NashornLinker.java    License: 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 Project: jdk8u60   Author: chenghanpeng   File: NashornLinker.java    License: 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 Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: NashornLinker.java    License: 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 #19
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: NashornLinker.java    License: 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 Project: openjdk-jdk9   Author: AdoptOpenJDK   File: NashornLinker.java    License: 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 #21
Source Project: hottub   Author: dsrg-uoft   File: NashornLinker.java    License: 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 #22
Source Project: openjdk-8-source   Author: keerath   File: NashornLinker.java    License: 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 #23
Source Project: openjdk-8   Author: bpupadhyaya   File: NashornLinker.java    License: 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 Project: jdk8u_nashorn   Author: JetBrains   File: NashornLinker.java    License: 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 Project: TencentKona-8   Author: Tencent   File: LiteralNode.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public Type getType() {
    return Type.typeFor(NativeArray.class);
}
 
Example #26
Source Project: TencentKona-8   Author: Tencent   File: JDK_8078414_Test.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testCanConvertScriptObjectSubclassToMirror() {
    assertCanConvertToMirror(NativeArray.class);
}
 
Example #27
Source Project: jdk8u60   Author: chenghanpeng   File: LiteralNode.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public Type getType() {
    return Type.typeFor(NativeArray.class);
}
 
Example #28
Source Project: jdk8u60   Author: chenghanpeng   File: JDK_8078414_Test.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testCanConvertScriptObjectSubclassToMirror() {
    assertCanConvertToMirror(NativeArray.class);
}
 
Example #29
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: LiteralNode.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public Type getType() {
    return Type.typeFor(NativeArray.class);
}
 
Example #30
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: JDK_8078414_Test.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Test
public void testCanConvertScriptObjectSubclassToMirror() {
    assertCanConvertToMirror(NativeArray.class);
}