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

The following examples show how to use jdk.nashorn.internal.runtime.ScriptObject#delete() . 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 openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.4.4.6 Array.prototype.pop ()
 *
 * @param self self reference
 * @return array after pop
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object pop(final Object self) {
    try {
        final ScriptObject sobj = (ScriptObject)self;

        if (bulkable(sobj)) {
            return sobj.getArray().pop();
        }

        final long len = JSType.toUint32(sobj.getLength());

        if (len == 0) {
            sobj.set("length", 0, true);
            return ScriptRuntime.UNDEFINED;
        }

        final long   index   = len - 1;
        final Object element = sobj.get(index);

        sobj.delete(index, true);
        sobj.set("length", index, true);

        return element;
    } catch (final ClassCastException | NullPointerException e) {
        throw typeError("not.an.object", ScriptRuntime.safeToString(self));
    }
}
 
Example 2
Source File: NativeArray.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.4.4.8 Array.prototype.reverse ()
 *
 * @param self self reference
 * @return reversed array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object reverse(final Object self) {
    try {
        final ScriptObject sobj   = (ScriptObject)self;
        final long         len    = JSType.toUint32(sobj.getLength());
        final long         middle = len / 2;

        for (long lower = 0; lower != middle; lower++) {
            final long    upper       = len - lower - 1;
            final Object  lowerValue  = sobj.get(lower);
            final Object  upperValue  = sobj.get(upper);
            final boolean lowerExists = sobj.has(lower);
            final boolean upperExists = sobj.has(upper);

            if (lowerExists && upperExists) {
                sobj.set(lower, upperValue, CALLSITE_STRICT);
                sobj.set(upper, lowerValue, CALLSITE_STRICT);
            } else if (!lowerExists && upperExists) {
                sobj.set(lower, upperValue, CALLSITE_STRICT);
                sobj.delete(upper, true);
            } else if (lowerExists && !upperExists) {
                sobj.delete(lower, true);
                sobj.set(upper, lowerValue, CALLSITE_STRICT);
            }
        }
        return sobj;
    } catch (final ClassCastException | NullPointerException e) {
        throw typeError("not.an.object", ScriptRuntime.safeToString(self));
    }
}
 
Example 3
Source File: NativeError.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Nashorn extension: Error.captureStackTrace. Capture stack trace at the point of call into the Error object provided.
 *
 * @param self self reference
 * @param errorObj the error object
 * @return undefined
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object captureStackTrace(final Object self, final Object errorObj) {
    final ScriptObject sobj = Global.checkObject(errorObj);
    initException(sobj);
    sobj.delete(STACK, false);
    if (! sobj.has("stack")) {
        final ScriptFunction getStack = ScriptFunctionImpl.makeFunction("getStack", GET_STACK);
        final ScriptFunction setStack = ScriptFunctionImpl.makeFunction("setStack", SET_STACK);
        sobj.addOwnProperty("stack", Attribute.NOT_ENUMERABLE, getStack, setStack);
    }
    return UNDEFINED;
}
 
Example 4
Source File: NativeArray.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.4.4.6 Array.prototype.pop ()
 *
 * @param self self reference
 * @return array after pop
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object pop(final Object self) {
    try {
        final ScriptObject sobj = (ScriptObject)self;

        if (bulkable(sobj)) {
            return sobj.getArray().pop();
        }

        final long len = JSType.toUint32(sobj.getLength());

        if (len == 0) {
            sobj.set("length", 0, CALLSITE_STRICT);
            return ScriptRuntime.UNDEFINED;
        }

        final long   index   = len - 1;
        final Object element = sobj.get(index);

        sobj.delete(index, true);
        sobj.set("length", index, CALLSITE_STRICT);

        return element;
    } catch (final ClassCastException | NullPointerException e) {
        throw typeError("not.an.object", ScriptRuntime.safeToString(self));
    }
}
 
Example 5
Source File: NativeArray.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.4.4.8 Array.prototype.reverse ()
 *
 * @param self self reference
 * @return reversed array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object reverse(final Object self) {
    try {
        final ScriptObject sobj   = (ScriptObject)self;
        final long         len    = JSType.toUint32(sobj.getLength());
        final long         middle = len / 2;

        for (long lower = 0; lower != middle; lower++) {
            final long    upper       = len - lower - 1;
            final Object  lowerValue  = sobj.get(lower);
            final Object  upperValue  = sobj.get(upper);
            final boolean lowerExists = sobj.has(lower);
            final boolean upperExists = sobj.has(upper);

            if (lowerExists && upperExists) {
                sobj.set(lower, upperValue, CALLSITE_STRICT);
                sobj.set(upper, lowerValue, CALLSITE_STRICT);
            } else if (!lowerExists && upperExists) {
                sobj.set(lower, upperValue, CALLSITE_STRICT);
                sobj.delete(upper, true);
            } else if (lowerExists && !upperExists) {
                sobj.delete(lower, true);
                sobj.set(upper, lowerValue, CALLSITE_STRICT);
            }
        }
        return sobj;
    } catch (final ClassCastException | NullPointerException e) {
        throw typeError("not.an.object", ScriptRuntime.safeToString(self));
    }
}
 
Example 6
Source File: NativeArray.java    From nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.4.4.8 Array.prototype.reverse ()
 *
 * @param self self reference
 * @return reversed array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object reverse(final Object self) {
    try {
        final ScriptObject sobj   = (ScriptObject)self;
        final long         len    = JSType.toUint32(sobj.getLength());
        final long         middle = len / 2;

        for (long lower = 0; lower != middle; lower++) {
            final long    upper       = len - lower - 1;
            final Object  lowerValue  = sobj.get(lower);
            final Object  upperValue  = sobj.get(upper);
            final boolean lowerExists = sobj.has(lower);
            final boolean upperExists = sobj.has(upper);

            if (lowerExists && upperExists) {
                sobj.set(lower, upperValue, true);
                sobj.set(upper, lowerValue, true);
            } else if (!lowerExists && upperExists) {
                sobj.set(lower, upperValue, true);
                sobj.delete(upper, true);
            } else if (lowerExists && !upperExists) {
                sobj.delete(lower, true);
                sobj.set(upper, lowerValue, true);
            }
        }
        return sobj;
    } catch (final ClassCastException | NullPointerException e) {
        throw typeError("not.an.object", ScriptRuntime.safeToString(self));
    }
}
 
Example 7
Source File: NativeArray.java    From jdk8u_nashorn with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.4.4.6 Array.prototype.pop ()
 *
 * @param self self reference
 * @return array after pop
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object pop(final Object self) {
    try {
        final ScriptObject sobj = (ScriptObject)self;

        if (bulkable(sobj)) {
            return sobj.getArray().pop();
        }

        final long len = JSType.toUint32(sobj.getLength());

        if (len == 0) {
            sobj.set("length", 0, CALLSITE_STRICT);
            return ScriptRuntime.UNDEFINED;
        }

        final long   index   = len - 1;
        final Object element = sobj.get(index);

        sobj.delete(index, true);
        sobj.set("length", index, CALLSITE_STRICT);

        return element;
    } catch (final ClassCastException | NullPointerException e) {
        throw typeError("not.an.object", ScriptRuntime.safeToString(self));
    }
}
 
Example 8
Source File: NativeError.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Nashorn extension: Error.captureStackTrace. Capture stack trace at the point of call into the Error object provided.
 *
 * @param self self reference
 * @param errorObj the error object
 * @return undefined
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object captureStackTrace(final Object self, final Object errorObj) {
    final ScriptObject sobj = Global.checkObject(errorObj);
    initException(sobj);
    sobj.delete(STACK, false);
    if (! sobj.has("stack")) {
        final ScriptFunction getStack = ScriptFunction.createBuiltin("getStack", GET_STACK);
        final ScriptFunction setStack = ScriptFunction.createBuiltin("setStack", SET_STACK);
        sobj.addOwnProperty("stack", Attribute.NOT_ENUMERABLE, getStack, setStack);
    }
    return UNDEFINED;
}
 
Example 9
Source File: NativeArray.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * ECMA 15.4.4.6 Array.prototype.pop ()
 *
 * @param self self reference
 * @return array after pop
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object pop(final Object self) {
    try {
        final ScriptObject sobj = (ScriptObject)self;

        if (bulkable(sobj)) {
            return sobj.getArray().pop();
        }

        final long len = JSType.toUint32(sobj.getLength());

        if (len == 0) {
            sobj.set("length", 0, CALLSITE_STRICT);
            return ScriptRuntime.UNDEFINED;
        }

        final long   index   = len - 1;
        final Object element = sobj.get(index);

        sobj.delete(index, true);
        sobj.set("length", index, CALLSITE_STRICT);

        return element;
    } catch (final ClassCastException | NullPointerException e) {
        throw typeError("not.an.object", ScriptRuntime.safeToString(self));
    }
}
 
Example 10
Source File: NativeError.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Nashorn extension: Error.captureStackTrace. Capture stack trace at the point of call into the Error object provided.
 *
 * @param self self reference
 * @param errorObj the error object
 * @return undefined
 */
@Function(attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR)
public static Object captureStackTrace(final Object self, final Object errorObj) {
    final ScriptObject sobj = Global.checkObject(errorObj);
    initException(sobj);
    sobj.delete(STACK, false);
    if (! sobj.has("stack")) {
        final ScriptFunction getStack = ScriptFunction.createBuiltin("getStack", GET_STACK);
        final ScriptFunction setStack = ScriptFunction.createBuiltin("setStack", SET_STACK);
        sobj.addOwnProperty("stack", Attribute.NOT_ENUMERABLE, getStack, setStack);
    }
    return UNDEFINED;
}
 
Example 11
Source File: NativeArray.java    From jdk8u_nashorn with GNU General Public License v2.0 4 votes vote down vote up
/**
 * ECMA 15.4.4.9 Array.prototype.shift ()
 *
 * @param self self reference
 * @return shifted array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object shift(final Object self) {
    final Object obj = Global.toObject(self);

    Object first = ScriptRuntime.UNDEFINED;

    if (!(obj instanceof ScriptObject)) {
        return first;
    }

    final ScriptObject sobj   = (ScriptObject) obj;

    long len = JSType.toUint32(sobj.getLength());

    if (len > 0) {
        first = sobj.get(0);

        if (bulkable(sobj)) {
            sobj.getArray().shiftLeft(1);
        } else {
            boolean hasPrevious = true;
            for (long k = 1; k < len; k++) {
                final boolean hasCurrent = sobj.has(k);
                if (hasCurrent) {
                    sobj.set(k - 1, sobj.get(k), CALLSITE_STRICT);
                } else if (hasPrevious) {
                    sobj.delete(k - 1, true);
                }
                hasPrevious = hasCurrent;
            }
        }
        sobj.delete(--len, true);
    } else {
        len = 0;
    }

    sobj.set("length", len, CALLSITE_STRICT);

    return first;
}
 
Example 12
Source File: NativeArray.java    From openjdk-jdk8u-backup 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 13
Source File: NativeArray.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * ECMA 15.4.4.9 Array.prototype.shift ()
 *
 * @param self self reference
 * @return shifted array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object shift(final Object self) {
    final Object obj = Global.toObject(self);

    Object first = ScriptRuntime.UNDEFINED;

    if (!(obj instanceof ScriptObject)) {
        return first;
    }

    final ScriptObject sobj   = (ScriptObject) obj;

    long len = JSType.toUint32(sobj.getLength());

    if (len > 0) {
        first = sobj.get(0);

        if (bulkable(sobj)) {
            sobj.getArray().shiftLeft(1);
        } else {
            boolean hasPrevious = true;
            for (long k = 1; k < len; k++) {
                final boolean hasCurrent = sobj.has(k);
                if (hasCurrent) {
                    sobj.set(k - 1, sobj.get(k), CALLSITE_STRICT);
                } else if (hasPrevious) {
                    sobj.delete(k - 1, true);
                }
                hasPrevious = hasCurrent;
            }
        }
        sobj.delete(--len, true);
    } else {
        len = 0;
    }

    sobj.set("length", len, CALLSITE_STRICT);

    return first;
}
 
Example 14
Source File: NativeArray.java    From 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, 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 15
Source File: NativeArray.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * ECMA 15.4.4.9 Array.prototype.shift ()
 *
 * @param self self reference
 * @return shifted array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object shift(final Object self) {
    final Object obj = Global.toObject(self);

    Object first = ScriptRuntime.UNDEFINED;

    if (!(obj instanceof ScriptObject)) {
        return first;
    }

    final ScriptObject sobj   = (ScriptObject) obj;

    long len = JSType.toUint32(sobj.getLength());

    if (len > 0) {
        first = sobj.get(0);

        if (bulkable(sobj)) {
            sobj.getArray().shiftLeft(1);
        } else {
            boolean hasPrevious = true;
            for (long k = 1; k < len; k++) {
                final boolean hasCurrent = sobj.has(k);
                if (hasCurrent) {
                    sobj.set(k - 1, sobj.get(k), CALLSITE_STRICT);
                } else if (hasPrevious) {
                    sobj.delete(k - 1, true);
                }
                hasPrevious = hasCurrent;
            }
        }
        sobj.delete(--len, true);
    } else {
        len = 0;
    }

    sobj.set("length", len, CALLSITE_STRICT);

    return first;
}
 
Example 16
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.9 Array.prototype.shift ()
 *
 * @param self self reference
 * @return shifted array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object shift(final Object self) {
    final Object obj = Global.toObject(self);

    Object first = ScriptRuntime.UNDEFINED;

    if (!(obj instanceof ScriptObject)) {
        return first;
    }

    final ScriptObject sobj   = (ScriptObject) obj;

    long len = JSType.toUint32(sobj.getLength());

    if (len > 0) {
        first = sobj.get(0);

        if (bulkable(sobj)) {
            sobj.getArray().shiftLeft(1);
        } else {
            boolean hasPrevious = true;
            for (long k = 1; k < len; k++) {
                boolean hasCurrent = sobj.has(k);
                if (hasCurrent) {
                    sobj.set(k - 1, sobj.get(k), true);
                } else if (hasPrevious) {
                    sobj.delete(k - 1, true);
                }
                hasPrevious = hasCurrent;
            }
        }
        sobj.delete(--len, true);
    } else {
        len = 0;
    }

    sobj.set("length", len, true);

    return first;
}
 
Example 17
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 18
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);
}
 
Example 19
Source File: NativeArray.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * ECMA 15.4.4.9 Array.prototype.shift ()
 *
 * @param self self reference
 * @return shifted array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object shift(final Object self) {
    final Object obj = Global.toObject(self);

    Object first = ScriptRuntime.UNDEFINED;

    if (!(obj instanceof ScriptObject)) {
        return first;
    }

    final ScriptObject sobj   = (ScriptObject) obj;

    long len = JSType.toUint32(sobj.getLength());

    if (len > 0) {
        first = sobj.get(0);

        if (bulkable(sobj)) {
            sobj.getArray().shiftLeft(1);
        } else {
            boolean hasPrevious = true;
            for (long k = 1; k < len; k++) {
                final boolean hasCurrent = sobj.has(k);
                if (hasCurrent) {
                    sobj.set(k - 1, sobj.get(k), CALLSITE_STRICT);
                } else if (hasPrevious) {
                    sobj.delete(k - 1, true);
                }
                hasPrevious = hasCurrent;
            }
        }
        sobj.delete(--len, true);
    } else {
        len = 0;
    }

    sobj.set("length", len, CALLSITE_STRICT);

    return first;
}
 
Example 20
Source File: NativeArray.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * ECMA 15.4.4.9 Array.prototype.shift ()
 *
 * @param self self reference
 * @return shifted array
 */
@Function(attributes = Attribute.NOT_ENUMERABLE)
public static Object shift(final Object self) {
    final Object obj = Global.toObject(self);

    Object first = ScriptRuntime.UNDEFINED;

    if (!(obj instanceof ScriptObject)) {
        return first;
    }

    final ScriptObject sobj   = (ScriptObject) obj;

    long len = JSType.toUint32(sobj.getLength());

    if (len > 0) {
        first = sobj.get(0);

        if (bulkable(sobj)) {
            sobj.getArray().shiftLeft(1);
        } else {
            boolean hasPrevious = true;
            for (long k = 1; k < len; k++) {
                final boolean hasCurrent = sobj.has(k);
                if (hasCurrent) {
                    sobj.set(k - 1, sobj.get(k), CALLSITE_STRICT);
                } else if (hasPrevious) {
                    sobj.delete(k - 1, true);
                }
                hasPrevious = hasCurrent;
            }
        }
        sobj.delete(--len, true);
    } else {
        len = 0;
    }

    sobj.set("length", len, CALLSITE_STRICT);

    return first;
}