本文整理汇总了Java中jdk.nashorn.internal.runtime.JSType.toScriptObject方法的典型用法代码示例。如果您正苦于以下问题:Java JSType.toScriptObject方法的具体用法?Java JSType.toScriptObject怎么用?Java JSType.toScriptObject使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.nashorn.internal.runtime.JSType
的用法示例。
在下文中一共展示了JSType.toScriptObject方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toLocaleString
import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
* ECMA 15.2.4.3 Object.prototype.toLocaleString ( )
*
* @param self self reference
* @return localized ToString
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object toLocaleString(final Object self) {
final Object obj = JSType.toScriptObject(self);
if (obj instanceof ScriptObject) {
final InvokeByName toStringInvoker = getTO_STRING();
final ScriptObject sobj = (ScriptObject)self;
try {
final Object toString = toStringInvoker.getGetter().invokeExact(sobj);
if (Bootstrap.isCallable(toString)) {
return toStringInvoker.getInvoker().invokeExact(toString, sobj);
}
} catch (final RuntimeException | Error e) {
throw e;
} catch (final Throwable t) {
throw new RuntimeException(t);
}
throw typeError("not.a.function", "toString");
}
return ScriptRuntime.builtinObjectToString(self);
}
示例2: toLocaleString
import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
* ECMA 15.2.4.3 Object.prototype.toLocaleString ( )
*
* @param self self reference
* @return localized ToString
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object toLocaleString(final Object self) {
final Object obj = JSType.toScriptObject(self);
if (obj instanceof ScriptObject) {
final InvokeByName toStringInvoker = getTO_STRING();
final ScriptObject sobj = (ScriptObject)obj;
try {
final Object toString = toStringInvoker.getGetter().invokeExact(sobj);
if (Bootstrap.isCallable(toString)) {
return toStringInvoker.getInvoker().invokeExact(toString, sobj);
}
} catch (final RuntimeException | Error e) {
throw e;
} catch (final Throwable t) {
throw new RuntimeException(t);
}
throw typeError("not.a.function", "toString");
}
return ScriptRuntime.builtinObjectToString(self);
}
示例3: arrayLikeIterator
import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
* ArrayLikeIterator factory
* @param object object over which to do reverse element iteration
* @param includeUndefined should undefined elements be included in the iteration
* @return iterator
*/
public static ArrayLikeIterator<Object> arrayLikeIterator(final Object object, final boolean includeUndefined) {
Object obj = object;
if (ScriptObject.isArray(obj)) {
return new ScriptArrayIterator((ScriptObject) obj, includeUndefined);
}
obj = JSType.toScriptObject(obj);
if (obj instanceof ScriptObject) {
return new ScriptObjectIterator((ScriptObject)obj, includeUndefined);
}
if (obj instanceof JSObject) {
return new JSObjectIterator((JSObject)obj, includeUndefined);
}
if (obj instanceof List) {
return new JavaListIterator((List<?>)obj, includeUndefined);
}
if (obj != null && obj.getClass().isArray()) {
return new JavaArrayIterator(obj, includeUndefined);
}
return new EmptyArrayLikeIterator();
}
示例4: reverseArrayLikeIterator
import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
* ArrayLikeIterator factory (reverse order)
* @param object object over which to do reverse element iteration
* @param includeUndefined should undefined elements be included in the iteration
* @return iterator
*/
public static ArrayLikeIterator<Object> reverseArrayLikeIterator(final Object object, final boolean includeUndefined) {
Object obj = object;
if (ScriptObject.isArray(obj)) {
return new ReverseScriptArrayIterator((ScriptObject) obj, includeUndefined);
}
obj = JSType.toScriptObject(obj);
if (obj instanceof ScriptObject) {
return new ReverseScriptObjectIterator((ScriptObject)obj, includeUndefined);
}
if (obj instanceof JSObject) {
return new ReverseJSObjectIterator((JSObject)obj, includeUndefined);
}
if (obj instanceof List) {
return new ReverseJavaListIterator((List<?>)obj, includeUndefined);
}
if (obj != null && obj.getClass().isArray()) {
return new ReverseJavaArrayIterator(obj, includeUndefined);
}
return new EmptyArrayLikeIterator();
}