本文整理汇总了Java中jdk.nashorn.internal.runtime.JSType.toNarrowestNumber方法的典型用法代码示例。如果您正苦于以下问题:Java JSType.toNarrowestNumber方法的具体用法?Java JSType.toNarrowestNumber怎么用?Java JSType.toNarrowestNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.nashorn.internal.runtime.JSType
的用法示例。
在下文中一共展示了JSType.toNarrowestNumber方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: push
import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
* ECMA 15.4.4.7 Array.prototype.push (args...)
*
* @param self self reference
* @param args arguments to push
* @return array length after pushes
*/
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object push(final Object self, final Object... args) {
try {
final ScriptObject sobj = (ScriptObject)self;
if (bulkable(sobj) && sobj.getArray().length() + args.length <= JSType.MAX_UINT) {
final ArrayData newData = sobj.getArray().push(true, args);
sobj.setArray(newData);
return JSType.toNarrowestNumber(newData.length());
}
long len = JSType.toUint32(sobj.getLength());
for (final Object element : args) {
sobj.set(len++, element, CALLSITE_STRICT);
}
sobj.set("length", len, CALLSITE_STRICT);
return JSType.toNarrowestNumber(len);
} catch (final ClassCastException | NullPointerException e) {
throw typeError(Context.getGlobal(), e, "not.an.object", ScriptRuntime.safeToString(self));
}
}
示例2: unshift
import jdk.nashorn.internal.runtime.JSType; //导入方法依赖的package包/类
/**
* ECMA 15.4.4.13 Array.prototype.unshift ( [ item1 [ , item2 [ , ... ] ] ] )
*
* @param self self reference
* @param items items for unshift
* @return unshifted array
*/
@Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1)
public static Object unshift(final Object self, final Object... items) {
final Object obj = Global.toObject(self);
if (!(obj instanceof ScriptObject)) {
return ScriptRuntime.UNDEFINED;
}
final ScriptObject sobj = (ScriptObject)obj;
final long len = JSType.toUint32(sobj.getLength());
if (items == null) {
return ScriptRuntime.UNDEFINED;
}
if (bulkable(sobj)) {
sobj.getArray().shiftRight(items.length);
for (int j = 0; j < items.length; j++) {
sobj.setArray(sobj.getArray().set(j, items[j], true));
}
} else {
for (long k = len; k > 0; k--) {
final long from = k - 1;
final long to = k + items.length - 1;
if (sobj.has(from)) {
final Object fromValue = sobj.get(from);
sobj.set(to, fromValue, CALLSITE_STRICT);
} else {
sobj.delete(to, true);
}
}
for (int j = 0; j < items.length; j++) {
sobj.set(j, items[j], CALLSITE_STRICT);
}
}
final long newLength = len + items.length;
sobj.set("length", newLength, CALLSITE_STRICT);
return JSType.toNarrowestNumber(newLength);
}