本文整理汇总了Java中jdk.nashorn.internal.runtime.ScriptObject.setArray方法的典型用法代码示例。如果您正苦于以下问题:Java ScriptObject.setArray方法的具体用法?Java ScriptObject.setArray怎么用?Java ScriptObject.setArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.nashorn.internal.runtime.ScriptObject
的用法示例。
在下文中一共展示了ScriptObject.setArray方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: push
import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的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 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 len;
} catch (final ClassCastException | NullPointerException e) {
throw typeError(Context.getGlobal(), e, "not.an.object", ScriptRuntime.safeToString(self));
}
}
示例2: createObject
import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
private Object createObject(final PropertyMap propertyMap, final List<Object> values, final ArrayData arrayData) {
final long[] primitiveSpill = dualFields ? new long[values.size()] : null;
final Object[] objectSpill = new Object[values.size()];
for (final Property property : propertyMap.getProperties()) {
if (!dualFields || property.getType() == Object.class) {
objectSpill[property.getSlot()] = values.get(property.getSlot());
} else {
primitiveSpill[property.getSlot()] = ObjectClassGenerator.pack((Number) values.get(property.getSlot()));
}
}
final ScriptObject object = dualFields ?
new JD(propertyMap, primitiveSpill, objectSpill) : new JO(propertyMap, null, objectSpill);
object.setInitialProto(global.getObjectPrototype());
object.setArray(arrayData);
return object;
}
示例3: push
import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的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));
}
}
示例4: 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));
}
}
示例5: setIndexedPropertiesToExternalArrayData
import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的package包/类
/**
* Nashorn extension: setIndexedPropertiesToExternalArrayData
*
* @param self self reference
* @param obj object whose index properties are backed by buffer
* @param buf external buffer - should be a nio ByteBuffer
* @return the 'obj' object
*/
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static ScriptObject setIndexedPropertiesToExternalArrayData(final Object self, final Object obj, final Object buf) {
Global.checkObject(obj);
final ScriptObject sobj = (ScriptObject)obj;
if (buf instanceof ByteBuffer) {
sobj.setArray(ArrayData.allocate((ByteBuffer)buf));
} else {
throw typeError("not.a.bytebuffer", "setIndexedPropertiesToExternalArrayData's buf argument");
}
return sobj;
}
示例6: unshift
import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的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 newLength;
}
示例7: unshift
import jdk.nashorn.internal.runtime.ScriptObject; //导入方法依赖的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);
}