本文整理汇总了Java中jdk.nashorn.internal.runtime.JSType.isPrimitive方法的典型用法代码示例。如果您正苦于以下问题:Java JSType.isPrimitive方法的具体用法?Java JSType.isPrimitive怎么用?Java JSType.isPrimitive使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.nashorn.internal.runtime.JSType
的用法示例。
在下文中一共展示了JSType.isPrimitive方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDefaultValue
import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
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");
}
示例2: canLink
import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
@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);
}
示例3: getIterator
import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
* 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));
}
示例4: isFunctionalInterfaceObject
import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
* 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);
}
示例5: isFunctionalInterfaceObject
import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
* 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);
}