Java Code Examples for jdk.nashorn.internal.runtime.JSType#isPrimitive()

The following examples show how to use jdk.nashorn.internal.runtime.JSType#isPrimitive() . 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: DefaultValueImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
static Object getDefaultValue(final JSObject jsobj, final Class<?> hint) throws UnsupportedOperationException {
    final boolean isNumber = hint == null || hint == Number.class;
    for(final String methodName: isNumber ? DEFAULT_VALUE_FNS_NUMBER : DEFAULT_VALUE_FNS_STRING) {
        final Object objMember = jsobj.getMember(methodName);
        if (objMember instanceof JSObject) {
            final JSObject member = (JSObject)objMember;
            if (member.isFunction()) {
                final Object value = member.call(jsobj);
                if (JSType.isPrimitive(value)) {
                    return value;
                }
            }
        }
    }
    throw new UnsupportedOperationException(isNumber ? "cannot.get.default.number" : "cannot.get.default.string");
}
 
Example 2
Source File: DefaultValueImpl.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
static Object getDefaultValue(final JSObject jsobj, final Class<?> hint) throws UnsupportedOperationException {
    final boolean isNumber = hint == null || hint == Number.class;
    for(final String methodName: isNumber ? DEFAULT_VALUE_FNS_NUMBER : DEFAULT_VALUE_FNS_STRING) {
        final Object objMember = jsobj.getMember(methodName);
        if (objMember instanceof JSObject) {
            final JSObject member = (JSObject)objMember;
            if (member.isFunction()) {
                final Object value = member.call(jsobj);
                if (JSType.isPrimitive(value)) {
                    return value;
                }
            }
        }
    }
    throw new UnsupportedOperationException(isNumber ? "cannot.get.default.number" : "cannot.get.default.string");
}
 
Example 3
Source File: DefaultValueImpl.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
static Object getDefaultValue(final JSObject jsobj, final Class<?> hint) throws UnsupportedOperationException {
    final boolean isNumber = hint == null || hint == Number.class;
    for(final String methodName: isNumber ? DEFAULT_VALUE_FNS_NUMBER : DEFAULT_VALUE_FNS_STRING) {
        final Object objMember = jsobj.getMember(methodName);
        if (objMember instanceof JSObject) {
            final JSObject member = (JSObject)objMember;
            if (member.isFunction()) {
                final Object value = member.call(jsobj);
                if (JSType.isPrimitive(value)) {
                    return value;
                }
            }
        }
    }
    throw new UnsupportedOperationException(isNumber ? "cannot.get.default.number" : "cannot.get.default.string");
}
 
Example 4
Source File: DefaultValueImpl.java    From jdk8u_nashorn with GNU General Public License v2.0 6 votes vote down vote up
static Object getDefaultValue(final JSObject jsobj, final Class<?> hint) throws UnsupportedOperationException {
    final boolean isNumber = hint == null || hint == Number.class;
    for(final String methodName: isNumber ? DEFAULT_VALUE_FNS_NUMBER : DEFAULT_VALUE_FNS_STRING) {
        final Object objMember = jsobj.getMember(methodName);
        if (objMember instanceof JSObject) {
            final JSObject member = (JSObject)objMember;
            if (member.isFunction()) {
                final Object value = member.call(jsobj);
                if (JSType.isPrimitive(value)) {
                    return value;
                }
            }
        }
    }
    throw new UnsupportedOperationException(isNumber ? "cannot.get.default.number" : "cannot.get.default.string");
}
 
Example 5
Source File: DefaultValueImpl.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
static Object getDefaultValue(final JSObject jsobj, final Class<?> hint) throws UnsupportedOperationException {
    final boolean isNumber = hint == null || hint == Number.class;
    for(final String methodName: isNumber ? DEFAULT_VALUE_FNS_NUMBER : DEFAULT_VALUE_FNS_STRING) {
        final Object objMember = jsobj.getMember(methodName);
        if (objMember instanceof JSObject) {
            final JSObject member = (JSObject)objMember;
            if (member.isFunction()) {
                final Object value = member.call(jsobj);
                if (JSType.isPrimitive(value)) {
                    return value;
                }
            }
        }
    }
    throw new UnsupportedOperationException(isNumber ? "cannot.get.default.number" : "cannot.get.default.string");
}
 
Example 6
Source File: DefaultValueImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
static Object getDefaultValue(final JSObject jsobj, final Class<?> hint) throws UnsupportedOperationException {
    final boolean isNumber = hint == null || hint == Number.class;
    for(final String methodName: isNumber ? DEFAULT_VALUE_FNS_NUMBER : DEFAULT_VALUE_FNS_STRING) {
        final Object objMember = jsobj.getMember(methodName);
        if (objMember instanceof JSObject) {
            final JSObject member = (JSObject)objMember;
            if (member.isFunction()) {
                final Object value = member.call(jsobj);
                if (JSType.isPrimitive(value)) {
                    return value;
                }
            }
        }
    }
    throw new UnsupportedOperationException(isNumber ? "cannot.get.default.number" : "cannot.get.default.string");
}
 
Example 7
Source File: NativeArray.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean canLink(final Object self, final CallSiteDescriptor desc, final LinkRequest request) {
    final Object[] args = request.getArguments();

    if (args.length != 3) { //single argument check
        return false;
    }

    final ContinuousArrayData selfData = getContinuousArrayData(self);
    if (selfData == null) {
        return false;
    }

    final Object arg = args[2];
    // The generic version uses its own logic and ArrayLikeIterator to decide if an object should
    // be iterated over or added as single element. To avoid duplication of code and err on the safe side
    // we only use the specialized version if arg is either a continuous array or a JS primitive.
    if (arg instanceof NativeArray) {
        return (getContinuousArrayData(arg) != null);
    }

    return JSType.isPrimitive(arg);
}
 
Example 8
Source File: DefaultValueImpl.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
static Object getDefaultValue(final JSObject jsobj, final Class<?> hint) throws UnsupportedOperationException {
    final boolean isNumber = hint == null || hint == Number.class;
    for(final String methodName: isNumber ? DEFAULT_VALUE_FNS_NUMBER : DEFAULT_VALUE_FNS_STRING) {
        final Object objMember = jsobj.getMember(methodName);
        if (objMember instanceof JSObject) {
            final JSObject member = (JSObject)objMember;
            if (member.isFunction()) {
                final Object value = member.call(jsobj);
                if (JSType.isPrimitive(value)) {
                    return value;
                }
            }
        }
    }
    throw new UnsupportedOperationException(isNumber ? "cannot.get.default.number" : "cannot.get.default.string");
}
 
Example 9
Source File: AbstractIterator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ES6 7.4.1 GetIterator abstract operation
 *
 * @param iterable an object
 * @param global the global object
 * @return the iterator
 */
public static Object getIterator(final Object iterable, final Global global) {
    final Object object = Global.toObject(iterable);

    if (object instanceof ScriptObject) {
        // TODO we need to implement fast property access for Symbol keys in order to use InvokeByName here.
        final Object getter = ((ScriptObject) object).get(NativeSymbol.iterator);

        if (Bootstrap.isCallable(getter)) {
            try {
                final MethodHandle invoker = getIteratorInvoker(global);

                final Object value = invoker.invokeExact(getter, iterable);
                if (JSType.isPrimitive(value)) {
                    throw typeError("not.an.object", ScriptRuntime.safeToString(value));
                }
                return value;

            } catch (final Throwable t) {
                throw new RuntimeException(t);
            }
        }
        throw typeError("not.a.function", ScriptRuntime.safeToString(getter));
    }

    throw typeError("cannot.get.iterator", ScriptRuntime.safeToString(iterable));
}
 
Example 10
Source File: Bootstrap.java    From nashorn with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns if the given object is an instance of an interface annotated with
 * java.lang.FunctionalInterface
 * @param obj object to be checked
 * @return true if the obj is an instance of @FunctionalInterface interface
 */
public static boolean isFunctionalInterfaceObject(final Object obj) {
    return !JSType.isPrimitive(obj) && (NashornBottomLinker.getFunctionalInterfaceMethod(obj.getClass()) != null);
}
 
Example 11
Source File: Bootstrap.java    From jdk8u_nashorn with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns if the given object is an instance of an interface annotated with
 * java.lang.FunctionalInterface
 * @param obj object to be checked
 * @return true if the obj is an instance of @FunctionalInterface interface
 */
public static boolean isFunctionalInterfaceObject(final Object obj) {
    return !JSType.isPrimitive(obj) && (NashornBeansLinker.getFunctionalInterfaceMethodName(obj.getClass()) != null);
}
 
Example 12
Source File: Bootstrap.java    From openjdk-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns if the given object is an instance of an interface annotated with
 * java.lang.FunctionalInterface
 * @param obj object to be checked
 * @return true if the obj is an instance of @FunctionalInterface interface
 */
public static boolean isFunctionalInterfaceObject(final Object obj) {
    return !JSType.isPrimitive(obj) && (NashornBottomLinker.getFunctionalInterfaceMethod(obj.getClass()) != null);
}
 
Example 13
Source File: Bootstrap.java    From openjdk-8-source with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns if the given object is an instance of an interface annotated with
 * java.lang.FunctionalInterface
 * @param obj object to be checked
 * @return true if the obj is an instance of @FunctionalInterface interface
 */
public static boolean isFunctionalInterfaceObject(final Object obj) {
    return !JSType.isPrimitive(obj) && (NashornBottomLinker.getFunctionalInterfaceMethod(obj.getClass()) != null);
}
 
Example 14
Source File: Bootstrap.java    From hottub with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns if the given object is an instance of an interface annotated with
 * java.lang.FunctionalInterface
 * @param obj object to be checked
 * @return true if the obj is an instance of @FunctionalInterface interface
 */
public static boolean isFunctionalInterfaceObject(final Object obj) {
    return !JSType.isPrimitive(obj) && (NashornBeansLinker.getFunctionalInterfaceMethodName(obj.getClass()) != null);
}
 
Example 15
Source File: Bootstrap.java    From openjdk-jdk9 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns if the given object is an instance of an interface annotated with
 * java.lang.FunctionalInterface
 * @param obj object to be checked
 * @return true if the obj is an instance of @FunctionalInterface interface
 */
public static boolean isFunctionalInterfaceObject(final Object obj) {
    return !JSType.isPrimitive(obj) && (NashornBeansLinker.getFunctionalInterfaceMethodName(obj.getClass()) != null);
}
 
Example 16
Source File: Bootstrap.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns if the given object is an instance of an interface annotated with
 * java.lang.FunctionalInterface
 * @param obj object to be checked
 * @return true if the obj is an instance of @FunctionalInterface interface
 */
public static boolean isFunctionalInterfaceObject(final Object obj) {
    return !JSType.isPrimitive(obj) && (NashornBeansLinker.getFunctionalInterfaceMethodName(obj.getClass()) != null);
}
 
Example 17
Source File: Bootstrap.java    From openjdk-jdk8u with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns if the given object is an instance of an interface annotated with
 * java.lang.FunctionalInterface
 * @param obj object to be checked
 * @return true if the obj is an instance of @FunctionalInterface interface
 */
public static boolean isFunctionalInterfaceObject(final Object obj) {
    return !JSType.isPrimitive(obj) && (NashornBeansLinker.getFunctionalInterfaceMethodName(obj.getClass()) != null);
}
 
Example 18
Source File: Bootstrap.java    From jdk8u60 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns if the given object is an instance of an interface annotated with
 * java.lang.FunctionalInterface
 * @param obj object to be checked
 * @return true if the obj is an instance of @FunctionalInterface interface
 */
public static boolean isFunctionalInterfaceObject(final Object obj) {
    return !JSType.isPrimitive(obj) && (NashornBeansLinker.getFunctionalInterfaceMethod(obj.getClass()) != null);
}
 
Example 19
Source File: Bootstrap.java    From TencentKona-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns if the given object is an instance of an interface annotated with
 * java.lang.FunctionalInterface
 * @param obj object to be checked
 * @return true if the obj is an instance of @FunctionalInterface interface
 */
public static boolean isFunctionalInterfaceObject(final Object obj) {
    return !JSType.isPrimitive(obj) && (NashornBeansLinker.getFunctionalInterfaceMethodName(obj.getClass()) != null);
}