本文整理汇总了Java中jdk.nashorn.internal.runtime.ScriptObject.getArray方法的典型用法代码示例。如果您正苦于以下问题:Java ScriptObject.getArray方法的具体用法?Java ScriptObject.getArray怎么用?Java ScriptObject.getArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.nashorn.internal.runtime.ScriptObject
的用法示例。
在下文中一共展示了ScriptObject.getArray方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: push
import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
/**
* ECMA 15.4.4.7 Array.prototype.push (args...) specialized for single object argument
*
* @param self self reference
* @param arg argument to push
* @return array after pushes
*/
@SpecializedFunction
public static long push(final Object self, final Object arg) {
try {
final ScriptObject sobj = (ScriptObject)self;
final ArrayData arrayData = sobj.getArray();
final long length = arrayData.length();
if (bulkable(sobj) && length < JSType.MAX_UINT) {
sobj.setArray(arrayData.push(true, arg));
return length + 1;
}
long len = JSType.toUint32(sobj.getLength());
sobj.set(len++, arg, CALLSITE_STRICT);
sobj.set("length", len, CALLSITE_STRICT);
return len;
} catch (final ClassCastException | NullPointerException e) {
throw typeError("not.an.object", ScriptRuntime.safeToString(self));
}
}
示例2: push
import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
/**
* ECMA 15.4.4.7 Array.prototype.push (args...) specialized for single object argument
*
* @param self self reference
* @param arg argument to push
* @return array after pushes
*/
@SpecializedFunction
public static double push(final Object self, final Object arg) {
try {
final ScriptObject sobj = (ScriptObject)self;
final ArrayData arrayData = sobj.getArray();
final long length = arrayData.length();
if (bulkable(sobj) && length < JSType.MAX_UINT) {
sobj.setArray(arrayData.push(true, arg));
return length + 1;
}
long len = JSType.toUint32(sobj.getLength());
sobj.set(len++, arg, CALLSITE_STRICT);
sobj.set("length", len, CALLSITE_STRICT);
return len;
} catch (final ClassCastException | NullPointerException e) {
throw typeError("not.an.object", ScriptRuntime.safeToString(self));
}
}
示例3: sort
import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
/**
* ECMA 15.4.4.11 Array.prototype.sort ( comparefn )
*
* @param self self reference
* @param comparefn element comparison function
* @return sorted array
*/
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static ScriptObject sort(final Object self, final Object comparefn) {
try {
final ScriptObject sobj = (ScriptObject) self;
final long len = JSType.toUint32(sobj.getLength());
ArrayData array = sobj.getArray();
if (len > 1) {
// Get only non-missing elements. Missing elements go at the end
// of the sorted array. So, just don't copy these to sort input.
final ArrayList<Object> src = new ArrayList<>();
for (final Iterator<Long> iter = array.indexIterator(); iter.hasNext(); ) {
final long index = iter.next();
if (index >= len) {
break;
}
src.add(array.getObject((int)index));
}
final Object[] sorted = sort(src.toArray(), comparefn);
for (int i = 0; i < sorted.length; i++) {
array = array.set(i, sorted[i], true);
}
// delete missing elements - which are at the end of sorted array
if (sorted.length != len) {
array = array.delete(sorted.length, len - 1);
}
sobj.setArray(array);
}
return sobj;
} catch (final ClassCastException | NullPointerException e) {
throw typeError("not.an.object", ScriptRuntime.safeToString(self));
}
}