Java Code Examples for jdk.nashorn.internal.runtime.ScriptObject#setArray()

The following examples show how to use jdk.nashorn.internal.runtime.ScriptObject#setArray() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NativeArray.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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));
    }
}
 
Example 2
Source File: NativeArray.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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));
    }
}
 
Example 3
Source File: JSONParser.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 4
Source File: NativeArray.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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));
    }
}
 
Example 5
Source File: NativeArray.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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));
    }
}
 
Example 6
Source File: NativeArray.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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));
    }
}
 
Example 7
Source File: JSONParser.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 8
Source File: NativeArray.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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));
    }
}
 
Example 9
Source File: JSONParser.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example 10
Source File: NativeObject.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 11
Source File: NativeArray.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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));
    }
}
 
Example 12
Source File: NativeArray.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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));
    }
}
 
Example 13
Source File: NativeObject.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 14
Source File: NativeObject.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 15
Source File: NativeArray.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);
}
 
Example 16
Source File: NativeArray.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example 17
Source File: NativeArray.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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, true);
            } else {
                sobj.delete(to, true);
            }
        }

        for (int j = 0; j < items.length; j++) {
             sobj.set(j, items[j], true);
        }
    }

    final long newLength = len + items.length;
    sobj.set("length", newLength, true);

    return newLength;
}
 
Example 18
Source File: NativeArray.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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, true);
            } else {
                sobj.delete(to, true);
            }
        }

        for (int j = 0; j < items.length; j++) {
             sobj.set(j, items[j], true);
        }
    }

    final long newLength = len + items.length;
    sobj.set("length", newLength, true);

    return newLength;
}
 
Example 19
Source File: NativeArray.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);
}
 
Example 20
Source File: NativeArray.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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);
}