2.1.71 [ECMA-262-1999] Section 15.4.4.9, Array.prototype.shift ()

V0108:

The first element of the array is removed from the array and returned.

(The bulleted steps are added before step 1)

  • __Let O be the result of calling ToObject with the this value as the argument.__

  • __If O is a host object, throw a TypeError exception.__

  • __If JScript 5.7 and if false is the result of calling the [[HasProperty]] method of O with name "length", return undefined.__

  1. Call the [[Get]] method of __O__ #this object# with argument "length".

  2. Call ToUint32(Result(1)).

  3. If Result(2) is not zero, go to step 6.

  4. Call the [[Put]] method of __O__ #this object# with arguments "length" and Result(2).

  5. Return undefined.

  6. Call the [[Get]] method of __O__ #this object# with argument 0.

  7. Let k be 1.

  8. If k equals Result(2), go to step 18.

    1. __If k > 2147483647, then let biasSrc = 4294967296; else let biasSrc = 0.__

    2. __If k-1 > 2147483647, then let biasDst = 4294967296; else let biasDst = 0.__

  9. Call ToString(k__-biasSrc__).

  10. Call ToString(k-__1-biasDst__).

  11. If __O__ #this object# has a property named by Result(9), go to step 12; but if __O__ #this object# has no property named by Result(9), then go to step 15.

  12. Call the [[Get]] method of __O__ #this object# with argument Result(9).

  13. Call the [[Put]] method of __O__ #this object# with arguments Result(10) and Result(12).

  14. Go to step 16.

  15. Call the [[Delete]] method of __O__ #this object# with argument Result(10).

  16. Increase k by 1.

  17. Go to step 8.

  18. If JScript 5.8 call the [[Delete]] method of __O__ #this object# with argument ToString(Result(2)-1).

  19. Call the [[Put]] method of __O__ #this object# with arguments "length" and (Result(2)-1).

  20. Return Result(6).

V0109:

NOTE

The shift function is intentionally generic; it does not require that its this value be an Array object. Therefore it can be transferred to other kinds of objects for use as a method. Whether the shift function can be applied successfully to a host object is implementation-dependent. __Jscript 5.x does not allow the shift function to be applied to a host object.__

In Jscript 5.x the shift function handles array index property names with numeric values greater than 231-1 differently from numerically smaller array index property names. As this behavior differs from the base specification and from probable user intent, the use of this function on objects containing such properties should be avoided.