Skip to content

7 Abstract Operations

These operations are not a part of the ECMAScript language; they are defined here to solely to aid the specification of the semantics of the ECMAScript language. Other, more specialized abstract operations are defined throughout this specification.

7.1 Type Conversion

The ECMAScript language implicitly performs automatic type conversion as needed. To clarify the semantics of certain constructs it is useful to define a set of conversion abstract operations. The conversion abstract operations are polymorphic; they can accept a value of any ECMAScript language type. But no other specification types are used with these operations.

The BigInt type has no implicit conversions in the ECMAScript language; programmers must call BigInt explicitly to convert values from other types.

7.1.1 ToPrimitive ( input [ , PreferredType ] )

The abstract operation ToPrimitive takes an input argument and an optional argument PreferredType. The abstract operation ToPrimitive converts its input argument to a non-Object type. If an object is capable of converting to more than one primitive type, it may use the optional hint PreferredType to favour that type. Conversion occurs according to the following algorithm:

  1. Assert: input is an ECMAScript language value.
  2. If Type(input) is Object, then
    1. If PreferredType is not present, let hint be "default".
    2. Else if PreferredType is hint String, let hint be "string".
    3. Else,
      1. Assert: PreferredType is hint Number.
      2. Let hint be "number".
    4. Let exoticToPrim be ? GetMethod(input, @@toPrimitive).
    5. If exoticToPrim is not undefined, then
      1. Let result be ? Call(exoticToPrim, input, « hint »).
      2. If Type(result) is not Object, return result.
      3. Throw a TypeError exception.
    6. If hint is "default", set hint to "number".
    7. Return ? OrdinaryToPrimitive(input, hint).
  3. Return input.
Note

When ToPrimitive is called with no hint, then it generally behaves as if the hint were Number. However, objects may over-ride this behaviour by defining a @@toPrimitive method. Of the objects defined in this specification only Date objects (see 20.4.4.45) and Symbol objects (see 19.4.3.5) over-ride the default ToPrimitive behaviour. Date objects treat no hint as if the hint were String.

7.1.1.1 OrdinaryToPrimitive ( O, hint )

When the abstract operation OrdinaryToPrimitive is called with arguments O and hint, the following steps are taken:

  1. Assert: Type(O) is Object.
  2. Assert: Type(hint) is String and its value is either "string" or "number".
  3. If hint is "string", then
    1. Let methodNames be « "toString", "valueOf" ».
  4. Else,
    1. Let methodNames be « "valueOf", "toString" ».
  5. For each name in methodNames in List order, do
    1. Let method be ? Get(O, name).
    2. If IsCallable(method) is true, then
      1. Let result be ? Call(method, O).
      2. If Type(result) is not Object, return result.
  6. Throw a TypeError exception.

7.1.2 ToBoolean ( argument )

The abstract operation ToBoolean converts argument to a value of type Boolean according to Table 10:

Argument Type Result
Undefined Return false.
Null Return false.
Boolean Return argument.
Number If argument is +0, -0, or NaN, return false; otherwise return true.
String If argument is the empty String (its length is zero), return false; otherwise return true.
Symbol Return true.
BigInt If argument is 0n, return false; otherwise return true.
Object Return true.

7.1.3 ToNumeric ( value )

The abstract operation ToNumeric returns value converted to a numeric value of type Number or BigInt. This abstract operation functions as follows:

  1. Let primValue be ? ToPrimitive(value, hint Number).
  2. If Type(primValue) is BigInt, return primValue.
  3. Return ? ToNumber(primValue).

7.1.4 ToNumber ( argument )

The abstract operation ToNumber converts argument to a value of type Number according to Table 11:

Argument Type Result
Undefined Return NaN.
Null Return +0.
Boolean If argument is true, return 1. If argument is false, return +0.
Number Return argument (no conversion).
String See grammar and conversion algorithm below.
Symbol Throw a TypeError exception.
BigInt Throw a TypeError exception.
Object

Apply the following steps:

  1. Let primValue be ? ToPrimitive(argument, hint Number).
  2. Return ? ToNumber(primValue).

7.1.4.1 ToNumber Applied to the String Type

ToNumber applied to Strings applies the following grammar to the input String interpreted as a sequence of UTF-16 encoded code points (6.1.4). If the grammar cannot interpret the String as an expansion of StringNumericLiteral, then the result of ToNumber is NaN.

Note 1

The terminal symbols of this grammar are all composed of characters in the Unicode Basic Multilingual Plane (BMP). Therefore, the result of ToNumber will be NaN if the string contains any leading surrogate or trailing surrogate code units, whether paired or unpaired.

Syntax

StringNumericLiteral ::: StrWhiteSpaceopt StrWhiteSpaceopt StrNumericLiteral StrWhiteSpaceopt StrWhiteSpace ::: StrWhiteSpaceChar StrWhiteSpaceopt StrWhiteSpaceChar ::: WhiteSpace LineTerminator StrNumericLiteral ::: StrDecimalLiteral NonDecimalIntegerLiteral StrDecimalLiteral ::: StrUnsignedDecimalLiteral + StrUnsignedDecimalLiteral - StrUnsignedDecimalLiteral StrUnsignedDecimalLiteral ::: Infinity DecimalDigits . DecimalDigitsopt ExponentPartopt . DecimalDigits ExponentPartopt DecimalDigits ExponentPartopt

All grammar symbols not explicitly defined above have the definitions used in the Lexical Grammar for numeric literals (11.8.3)

Note 2

Some differences should be noted between the syntax of a StringNumericLiteral and a NumericLiteral:

7.1.4.1.1 Runtime Semantics: MV

The conversion of a String to a Number value is similar overall to the determination of the Number value for a numeric literal (see 11.8.3), but some of the details are different, so the process for converting a String numeric literal to a value of Number type is given here. This value is determined in two steps: first, a mathematical value (MV) is derived from the String numeric literal; second, this mathematical value is rounded as described below. The MV on any grammar symbol, not provided below, is the MV for that symbol defined in 11.8.3.1.

Once the exact MV for a String numeric literal has been determined, it is then rounded to a value of the Number type. If the MV is 0, then the rounded value is +0 unless the first non white space code point in the String numeric literal is -, in which case the rounded value is -0. Otherwise, the rounded value must be the Number value for the MV (in the sense defined in 6.1.6.1), unless the literal includes a StrUnsignedDecimalLiteral and the literal has more than 20 significant digits, in which case the Number value may be either the Number value for the MV of a literal produced by replacing each significant digit after the 20th with a 0 digit or the Number value for the MV of a literal produced by replacing each significant digit after the 20th with a 0 digit and then incrementing the literal at the 20th digit position. A digit is significant if it is not part of an ExponentPart and

  • it is not 0; or
  • there is a nonzero digit to its left and there is a nonzero digit, not in the ExponentPart, to its right.

7.1.5 ToInteger ( argument )

The abstract operation ToInteger converts argument to an integral Number value. This abstract operation functions as follows:

  1. Let number be ? ToNumber(argument).
  2. If number is NaN, +0, or -0, return +0.
  3. If number is +∞ or -∞, return number.
  4. Let integer be the Number value that is the same sign as number and whose magnitude is floor(abs(number)).
  5. If integer is -0, return +0.
  6. Return integer.

7.1.6 ToInt32 ( argument )

The abstract operation ToInt32 converts argument to one of 232 integer values in the range -231 through 231 - 1, inclusive. This abstract operation functions as follows:

  1. Let number be ? ToNumber(argument).
  2. If number is NaN, +0, -0, +∞, or -∞, return +0.
  3. Let int be the Number value that is the same sign as number and whose magnitude is floor(abs(number)).
  4. Let int32bit be int modulo 232.
  5. If int32bit ≥ 231, return int32bit - 232; otherwise return int32bit.
Note

Given the above definition of ToInt32:

  • The ToInt32 abstract operation is idempotent: if applied to a result that it produced, the second application leaves that value unchanged.
  • ToInt32(ToUint32(x)) is equal to ToInt32(x) for all values of x. (It is to preserve this latter property that +∞ and -∞ are mapped to +0.)
  • ToInt32 maps -0 to +0.

7.1.7 ToUint32 ( argument )

The abstract operation ToUint32 converts argument to one of 232 integer values in the range 0 through 232 - 1, inclusive. This abstract operation functions as follows:

  1. Let number be ? ToNumber(argument).
  2. If number is NaN, +0, -0, +∞, or -∞, return +0.
  3. Let int be the Number value that is the same sign as number and whose magnitude is floor(abs(number)).
  4. Let int32bit be int modulo 232.
  5. Return int32bit.
Note

Given the above definition of ToUint32:

  • Step 5 is the only difference between ToUint32 and ToInt32.
  • The ToUint32 abstract operation is idempotent: if applied to a result that it produced, the second application leaves that value unchanged.
  • ToUint32(ToInt32(x)) is equal to ToUint32(x) for all values of x. (It is to preserve this latter property that +∞ and -∞ are mapped to +0.)
  • ToUint32 maps -0 to +0.

7.1.8 ToInt16 ( argument )

The abstract operation ToInt16 converts argument to one of 216 integer values in the range -32768 through 32767, inclusive. This abstract operation functions as follows:

  1. Let number be ? ToNumber(argument).
  2. If number is NaN, +0, -0, +∞, or -∞, return +0.
  3. Let int be the Number value that is the same sign as number and whose magnitude is floor(abs(number)).
  4. Let int16bit be int modulo 216.
  5. If int16bit ≥ 215, return int16bit - 216; otherwise return int16bit.

7.1.9 ToUint16 ( argument )

The abstract operation ToUint16 converts argument to one of 216 integer values in the range 0 through 216 - 1, inclusive. This abstract operation functions as follows:

  1. Let number be ? ToNumber(argument).
  2. If number is NaN, +0, -0, +∞, or -∞, return +0.
  3. Let int be the Number value that is the same sign as number and whose magnitude is floor(abs(number)).
  4. Let int16bit be int modulo 216.
  5. Return int16bit.
Note

Given the above definition of ToUint16:

  • The substitution of 216 for 232 in step 4 is the only difference between ToUint32 and ToUint16.
  • ToUint16 maps -0 to +0.

7.1.10 ToInt8 ( argument )

The abstract operation ToInt8 converts argument to one of 28 integer values in the range -128 through 127, inclusive. This abstract operation functions as follows:

  1. Let number be ? ToNumber(argument).
  2. If number is NaN, +0, -0, +∞, or -∞, return +0.
  3. Let int be the Number value that is the same sign as number and whose magnitude is floor(abs(number)).
  4. Let int8bit be int modulo 28.
  5. If int8bit ≥ 27, return int8bit - 28; otherwise return int8bit.

7.1.11 ToUint8 ( argument )

The abstract operation ToUint8 converts argument to one of 28 integer values in the range 0 through 255, inclusive. This abstract operation functions as follows:

  1. Let number be ? ToNumber(argument).
  2. If number is NaN, +0, -0, +∞, or -∞, return +0.
  3. Let int be the Number value that is the same sign as number and whose magnitude is floor(abs(number)).
  4. Let int8bit be int modulo 28.
  5. Return int8bit.

7.1.12 ToUint8Clamp ( argument )

The abstract operation ToUint8Clamp converts argument to one of 28 integer values in the range 0 through 255, inclusive. This abstract operation functions as follows:

  1. Let number be ? ToNumber(argument).
  2. If number is NaN, return +0.
  3. If number ≤ 0, return +0.
  4. If number ≥ 255, return 255.
  5. Let f be floor(number).
  6. If f + 0.5 < number, return f + 1.
  7. If number < f + 0.5, return f.
  8. If f is odd, return f + 1.
  9. Return f.
Note

Unlike the other ECMAScript integer conversion abstract operation, ToUint8Clamp rounds rather than truncates non-integer values and does not convert +∞ to 0. ToUint8Clamp does “round half to even” tie-breaking. This differs from Math.round which does “round half up” tie-breaking.

7.1.13 ToBigInt ( argument )

The abstract operation ToBigInt converts its argument argument to a BigInt value, or throws if an implicit conversion from Number would be required.

  1. Let prim be ? ToPrimitive(argument, hint Number).
  2. Return the value that prim corresponds to in Table 12.
Argument Type Result
Undefined Throw a TypeError exception.
Null Throw a TypeError exception.
Boolean Return 1n if prim is true and 0n if prim is false.
BigInt Return prim.
Number Throw a TypeError exception.
String
  1. Let n be ! StringToBigInt(prim).
  2. If n is NaN, throw a SyntaxError exception.
  3. Return n.
Symbol Throw a TypeError exception.

7.1.14 StringToBigInt ( argument )

Apply the algorithm in 7.1.4.1 with the following changes:

  • Replace the StrUnsignedDecimalLiteral production with DecimalDigits to not allow Infinity, decimal points, or exponents.
  • If the MV is NaN, return NaN, otherwise return the BigInt which exactly corresponds to the MV, rather than rounding to a Number.

7.1.15 ToBigInt64 ( argument )

The abstract operation ToBigInt64 converts argument to one of 264 integer values in the range -263 through 263-1, inclusive. This abstract operation functions as follows:

  1. Let n be ? ToBigInt(argument).
  2. Let int64bit be n modulo 264.
  3. If int64bit ≥ 263, return int64bit - 264; otherwise return int64bit.

7.1.16 ToBigUint64 ( argument )

The abstract operation ToBigUint64 converts argument to one of 264 integer values in the range 0 through 264-1, inclusive. This abstract operation functions as follows:

  1. Let n be ? ToBigInt(argument).
  2. Let int64bit be n modulo 264.
  3. Return int64bit.

7.1.17 ToString ( argument )

The abstract operation ToString converts argument to a value of type String according to Table 13:

Argument Type Result
Undefined Return "undefined".
Null Return "null".
Boolean

If argument is true, return "true".

If argument is false, return "false".

Number Return ! Number::toString(argument).
String Return argument.
Symbol Throw a TypeError exception.
BigInt Return ! BigInt::toString(argument).
Object

Apply the following steps:

  1. Let primValue be ? ToPrimitive(argument, hint String).
  2. Return ? ToString(primValue).

7.1.18 ToObject ( argument )

The abstract operation ToObject converts argument to a value of type Object according to Table 14:

Argument Type Result
Undefined Throw a TypeError exception.
Null Throw a TypeError exception.
Boolean Return a new Boolean object whose [[BooleanData]] internal slot is set to argument. See 19.3 for a description of Boolean objects.
Number Return a new Number object whose [[NumberData]] internal slot is set to argument. See 20.1 for a description of Number objects.
String Return a new String object whose [[StringData]] internal slot is set to argument. See 21.1 for a description of String objects.
Symbol Return a new Symbol object whose [[SymbolData]] internal slot is set to argument. See 19.4 for a description of Symbol objects.
BigInt Return a new BigInt object whose [[BigIntData]] internal slot is set to argument. See 20.2 for a description of BigInt objects.
Object Return argument.

7.1.19 ToPropertyKey ( argument )

The abstract operation ToPropertyKey converts argument to a value that can be used as a property key by performing the following steps:

  1. Let key be ? ToPrimitive(argument, hint String).
  2. If Type(key) is Symbol, then
    1. Return key.
  3. Return ! ToString(key).

7.1.20 ToLength ( argument )

The abstract operation ToLength converts argument to an integer suitable for use as the length of an array-like object. It performs the following steps:

  1. Let len be ? ToInteger(argument).
  2. If len+0, return +0.
  3. Return min(len, 253 - 1).

7.1.21 CanonicalNumericIndexString ( argument )

The abstract operation CanonicalNumericIndexString returns argument converted to a Number value if it is a String representation of a Number that would be produced by ToString, or the string "-0". Otherwise, it returns undefined. This abstract operation functions as follows:

  1. Assert: Type(argument) is String.
  2. If argument is "-0", return -0.
  3. Let n be ! ToNumber(argument).
  4. If SameValue(! ToString(n), argument) is false, return undefined.
  5. Return n.

A canonical numeric string is any String value for which the CanonicalNumericIndexString abstract operation does not return undefined.

7.1.22 ToIndex ( value )

The abstract operation ToIndex returns value argument converted to a non-negative integer if it is a valid integer index value. This abstract operation functions as follows:

  1. If value is undefined, then
    1. Let index be 0.
  2. Else,
    1. Let integerIndex be ? ToInteger(value).
    2. If integerIndex < 0, throw a RangeError exception.
    3. Let index be ! ToLength(integerIndex).
    4. If ! SameValue(integerIndex, index) is false, throw a RangeError exception.
  3. Return index.

7.2 Testing and Comparison Operations

7.2.1 RequireObjectCoercible ( argument )

The abstract operation RequireObjectCoercible throws an error if argument is a value that cannot be converted to an Object using ToObject. It is defined by Table 15:

Argument Type Result
Undefined Throw a TypeError exception.
Null Throw a TypeError exception.
Boolean Return argument.
Number Return argument.
String Return argument.
Symbol Return argument.
BigInt Return argument.
Object Return argument.

7.2.2 IsArray ( argument )

The abstract operation IsArray takes one argument argument, and performs the following steps:

  1. If Type(argument) is not Object, return false.
  2. If argument is an Array exotic object, return true.
  3. If argument is a Proxy exotic object, then
    1. If argument.[[ProxyHandler]] is null, throw a TypeError exception.
    2. Let target be argument.[[ProxyTarget]].
    3. Return ? IsArray(target).
  4. Return false.

7.2.3 IsCallable ( argument )

The abstract operation IsCallable determines if argument, which must be an ECMAScript language value, is a callable function with a [[Call]] internal method.

  1. If Type(argument) is not Object, return false.
  2. If argument has a [[Call]] internal method, return true.
  3. Return false.

7.2.4 IsConstructor ( argument )

The abstract operation IsConstructor determines if argument, which must be an ECMAScript language value, is a function object with a [[Construct]] internal method.

  1. If Type(argument) is not Object, return false.
  2. If argument has a [[Construct]] internal method, return true.
  3. Return false.

7.2.5 IsExtensible ( O )

The abstract operation IsExtensible is used to determine whether additional properties can be added to the object that is O. A Boolean value is returned. This abstract operation performs the following steps:

  1. Assert: Type(O) is Object.
  2. Return ? O.[[IsExtensible]]().

7.2.6 IsInteger ( argument )

The abstract operation IsInteger determines if argument is a finite integer Number value.

  1. If Type(argument) is not Number, return false.
  2. If argument is NaN, +∞, or -∞, return false.
  3. If floor(abs(argument)) ≠ abs(argument), return false.
  4. Return true.

7.2.7 IsNonNegativeInteger ( argument )

The abstract operation IsNonNegativeInteger determines if argument is non-negative integer Number value.

  1. If ! IsInteger(argument) is true and argument ≥ 0, return true.
  2. Otherwise, return false.

7.2.8 IsPropertyKey ( argument )

The abstract operation IsPropertyKey determines if argument, which must be an ECMAScript language value, is a value that may be used as a property key.

  1. If Type(argument) is String, return true.
  2. If Type(argument) is Symbol, return true.
  3. Return false.

7.2.9 IsRegExp ( argument )

The abstract operation IsRegExp with argument argument performs the following steps:

  1. If Type(argument) is not Object, return false.
  2. Let matcher be ? Get(argument, @@match).
  3. If matcher is not undefined, return ! ToBoolean(matcher).
  4. If argument has a [[RegExpMatcher]] internal slot, return true.
  5. Return false.

7.2.10 IsStringPrefix ( p, q )

The abstract operation IsStringPrefix determines if String p is a prefix of String q.

  1. Assert: Type(p) is String.
  2. Assert: Type(q) is String.
  3. If q can be the string-concatenation of p and some other String r, return true. Otherwise, return false.
Note

Any String is a prefix of itself, because r may be the empty String.

7.2.11 SameValue ( x, y )

The internal comparison abstract operation SameValue(x, y), where x and y are ECMAScript language values, produces true or false. Such a comparison is performed as follows:

  1. If Type(x) is different from Type(y), return false.
  2. If Type(x) is Number or BigInt, then
    1. Return ! Type(x)::sameValue(x, y).
  3. Return ! SameValueNonNumeric(x, y).
Note

This algorithm differs from the Strict Equality Comparison Algorithm in its treatment of signed zeroes and NaNs.

7.2.12 SameValueZero ( x, y )

The internal comparison abstract operation SameValueZero(x, y), where x and y are ECMAScript language values, produces true or false. Such a comparison is performed as follows:

  1. If Type(x) is different from Type(y), return false.
  2. If Type(x) is Number or BigInt, then
    1. Return ! Type(x)::sameValueZero(x, y).
  3. Return ! SameValueNonNumeric(x, y).
Note

SameValueZero differs from SameValue only in its treatment of +0 and -0.

7.2.13 SameValueNonNumeric ( x, y )

The internal comparison abstract operation SameValueNonNumeric(x, y), where neither x nor y are numeric type values, produces true or false. Such a comparison is performed as follows:

  1. Assert: Type(x) is not Number or BigInt.
  2. Assert: Type(x) is the same as Type(y).
  3. If Type(x) is Undefined, return true.
  4. If Type(x) is Null, return true.
  5. If Type(x) is String, then
    1. If x and y are exactly the same sequence of code units (same length and same code units at corresponding indices), return true; otherwise, return false.
  6. If Type(x) is Boolean, then
    1. If x and y are both true or both false, return true; otherwise, return false.
  7. If Type(x) is Symbol, then
    1. If x and y are both the same Symbol value, return true; otherwise, return false.
  8. If x and y are the same Object value, return true. Otherwise, return false.

7.2.14 Abstract Relational Comparison

The comparison x < y, where x and y are values, produces true, false, or undefined (which indicates that at least one operand is NaN). In addition to x and y the algorithm takes a Boolean flag named LeftFirst as a parameter. The flag is used to control the order in which operations with potentially visible side-effects are performed upon x and y. It is necessary because ECMAScript specifies left to right evaluation of expressions. The default value of LeftFirst is true and indicates that the x parameter corresponds to an expression that occurs to the left of the y parameter's corresponding expression. If LeftFirst is false, the reverse is the case and operations must be performed upon y before x. Such a comparison is performed as follows:

  1. If the LeftFirst flag is true, then
    1. Let px be ? ToPrimitive(x, hint Number).
    2. Let py be ? ToPrimitive(y, hint Number).
  2. Else,
    1. NOTE: The order of evaluation needs to be reversed to preserve left to right evaluation.
    2. Let py be ? ToPrimitive(y, hint Number).
    3. Let px be ? ToPrimitive(x, hint Number).
  3. If Type(px) is String and Type(py) is String, then
    1. If IsStringPrefix(py, px) is true, return false.
    2. If IsStringPrefix(px, py) is true, return true.
    3. Let k be the smallest nonnegative integer such that the code unit at index k within px is different from the code unit at index k within py. (There must be such a k, for neither String is a prefix of the other.)
    4. Let m be the integer that is the numeric value of the code unit at index k within px.
    5. Let n be the integer that is the numeric value of the code unit at index k within py.
    6. If m < n, return true. Otherwise, return false.
  4. Else,
    1. If Type(px) is BigInt and Type(py) is String, then
      1. Let ny be ! StringToBigInt(py).
      2. If ny is NaN, return undefined.
      3. Return BigInt::lessThan(px, ny).
    2. If Type(px) is String and Type(py) is BigInt, then
      1. Let nx be ! StringToBigInt(px).
      2. If nx is NaN, return undefined.
      3. Return BigInt::lessThan(nx, py).
    3. NOTE: Because px and py are primitive values, evaluation order is not important.
    4. Let nx be ? ToNumeric(px).
    5. Let ny be ? ToNumeric(py).
    6. If Type(nx) is the same as Type(ny), return Type(nx)::lessThan(nx, ny).
    7. Assert: Type(nx) is BigInt and Type(ny) is Number, or Type(nx) is Number and Type(ny) is BigInt.
    8. If nx or ny is NaN, return undefined.
    9. If nx is -∞ or ny is +∞, return true.
    10. If nx is +∞ or ny is -∞, return false.
    11. If the mathematical value of nx is less than the mathematical value of ny, return true; otherwise return false.
Note 1

Step 3 differs from step 7 in the algorithm for the addition operator + (12.8.3) by using the logical-and operation instead of the logical-or operation.

Note 2

The comparison of Strings uses a simple lexicographic ordering on sequences of code unit values. There is no attempt to use the more complex, semantically oriented definitions of character or string equality and collating order defined in the Unicode specification. Therefore String values that are canonically equal according to the Unicode standard could test as unequal. In effect this algorithm assumes that both Strings are already in normalized form. Also, note that for strings containing supplementary characters, lexicographic ordering on sequences of UTF-16 code unit values differs from that on sequences of code point values.

7.2.15 Abstract Equality Comparison

The comparison x == y, where x and y are values, produces true or false. Such a comparison is performed as follows:

  1. If Type(x) is the same as Type(y), then
    1. Return the result of performing Strict Equality Comparison x === y.
  2. If x is null and y is undefined, return true.
  3. If x is undefined and y is null, return true.
  4. If Type(x) is Number and Type(y) is String, return the result of the comparison x == ! ToNumber(y).
  5. If Type(x) is String and Type(y) is Number, return the result of the comparison ! ToNumber(x) == y.
  6. If Type(x) is BigInt and Type(y) is String, then
    1. Let n be ! StringToBigInt(y).
    2. If n is NaN, return false.
    3. Return the result of the comparison x == n.
  7. If Type(x) is String and Type(y) is BigInt, return the result of the comparison y == x.
  8. If Type(x) is Boolean, return the result of the comparison ! ToNumber(x) == y.
  9. If Type(y) is Boolean, return the result of the comparison x == ! ToNumber(y).
  10. If Type(x) is either String, Number, BigInt, or Symbol and Type(y) is Object, return the result of the comparison x == ToPrimitive(y).
  11. If Type(x) is Object and Type(y) is either String, Number, BigInt, or Symbol, return the result of the comparison ToPrimitive(x) == y.
  12. If Type(x) is BigInt and Type(y) is Number, or if Type(x) is Number and Type(y) is BigInt, then
    1. If x or y are any of NaN, +∞, or -∞, return false.
    2. If the mathematical value of x is equal to the mathematical value of y, return true; otherwise return false.
  13. Return false.

7.2.16 Strict Equality Comparison

The comparison x === y, where x and y are values, produces true or false. Such a comparison is performed as follows:

  1. If Type(x) is different from Type(y), return false.
  2. If Type(x) is Number or BigInt, then
    1. Return ! Type(x)::equal(x, y).
  3. Return ! SameValueNonNumeric(x, y).
Note

This algorithm differs from the SameValue Algorithm in its treatment of signed zeroes and NaNs.

7.3 Operations on Objects

7.3.1 MakeBasicObject ( internalSlotsList )

The abstract operation MakeBasicObject is the source of all ECMAScript objects that are created algorithmically, including both ordinary objects and exotic objects. It factors out common steps used in creating all objects, and centralizes object creation.

  1. Assert: internalSlotsList is a List of internal slot names.
  2. Let obj be a newly created object with an internal slot for each name in internalSlotsList.
  3. Set obj's essential internal methods to the default ordinary object definitions specified in 9.1.
  4. Assert: If the caller will not be overriding both obj's [[GetPrototypeOf]] and [[SetPrototypeOf]] essential internal methods, then internalSlotsList contains [[Prototype]].
  5. Assert: If the caller will not be overriding all of obj's [[SetPrototypeOf]], [[IsExtensible]], and [[PreventExtensions]] essential internal methods, then internalSlotsList contains [[Extensible]].
  6. If internalSlotsList contains [[Extensible]], then set obj.[[Extensible]] to true.
  7. Return obj.
Note

Within this specification, exotic objects are created in abstract operations such as ArrayCreate and BoundFunctionCreate by first calling MakeBasicObject to obtain a basic, foundational object, and then overriding some or all of that object's internal methods. In order to encapsulate exotic object creation, the object's essential internal methods are never modified outside those operations.

7.3.2 Get ( O, P )

The abstract operation Get is used to retrieve the value of a specific property of an object. The operation is called with arguments O and P where O is the object and P is the property key. This abstract operation performs the following steps:

  1. Assert: Type(O) is Object.
  2. Assert: IsPropertyKey(P) is true.
  3. Return ? O.[[Get]](P, O).

7.3.3 GetV ( V, P )

The abstract operation GetV is used to retrieve the value of a specific property of an ECMAScript language value. If the value is not an object, the property lookup is performed using a wrapper object appropriate for the type of the value. The operation is called with arguments V and P where V is the value and P is the property key. This abstract operation performs the following steps:

  1. Assert: IsPropertyKey(P) is true.
  2. Let O be ? ToObject(V).
  3. Return ? O.[[Get]](P, V).

7.3.4 Set ( O, P, V, Throw )

The abstract operation Set is used to set the value of a specific property of an object. The operation is called with arguments O, P, V, and Throw where O is the object, P is the property key, V is the new value for the property and Throw is a Boolean flag. This abstract operation performs the following steps:

  1. Assert: Type(O) is Object.
  2. Assert: IsPropertyKey(P) is true.
  3. Assert: Type(Throw) is Boolean.
  4. Let success be ? O.[[Set]](P, V, O).
  5. If success is false and Throw is true, throw a TypeError exception.
  6. Return success.

7.3.5 CreateDataProperty ( O, P, V )

The abstract operation CreateDataProperty is used to create a new own property of an object. The operation is called with arguments O, P, and V where O is the object, P is the property key, and V is the value for the property. This abstract operation performs the following steps:

  1. Assert: Type(O) is Object.
  2. Assert: IsPropertyKey(P) is true.
  3. Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]: true, [[Enumerable]]: true, [[Configurable]]: true }.
  4. Return ? O.[[DefineOwnProperty]](P, newDesc).
Note

This abstract operation creates a property whose attributes are set to the same defaults used for properties created by the ECMAScript language assignment operator. Normally, the property will not already exist. If it does exist and is not configurable or if O is not extensible, [[DefineOwnProperty]] will return false.

7.3.6 CreateMethodProperty ( O, P, V )

The abstract operation CreateMethodProperty is used to create a new own property of an object. The operation is called with arguments O, P, and V where O is the object, P is the property key, and V is the value for the property. This abstract operation performs the following steps:

  1. Assert: Type(O) is Object.
  2. Assert: IsPropertyKey(P) is true.
  3. Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true }.
  4. Return ? O.[[DefineOwnProperty]](P, newDesc).
Note

This abstract operation creates a property whose attributes are set to the same defaults used for built-in methods and methods defined using class declaration syntax. Normally, the property will not already exist. If it does exist and is not configurable or if O is not extensible, [[DefineOwnProperty]] will return false.

7.3.7 CreateDataPropertyOrThrow ( O, P, V )

The abstract operation CreateDataPropertyOrThrow is used to create a new own property of an object. It throws a TypeError exception if the requested property update cannot be performed. The operation is called with arguments O, P, and V where O is the object, P is the property key, and V is the value for the property. This abstract operation performs the following steps:

  1. Assert: Type(O) is Object.
  2. Assert: IsPropertyKey(P) is true.
  3. Let success be ? CreateDataProperty(O, P, V).
  4. If success is false, throw a TypeError exception.
  5. Return success.
Note

This abstract operation creates a property whose attributes are set to the same defaults used for properties created by the ECMAScript language assignment operator. Normally, the property will not already exist. If it does exist and is not configurable or if O is not extensible, [[DefineOwnProperty]] will return false causing this operation to throw a TypeError exception.

7.3.8 DefinePropertyOrThrow ( O, P, desc )

The abstract operation DefinePropertyOrThrow is used to call the [[DefineOwnProperty]] internal method of an object in a manner that will throw a TypeError exception if the requested property update cannot be performed. The operation is called with arguments O, P, and desc where O is the object, P is the property key, and desc is the Property Descriptor for the property. This abstract operation performs the following steps:

  1. Assert: Type(O) is Object.
  2. Assert: IsPropertyKey(P) is true.
  3. Let success be ? O.[[DefineOwnProperty]](P, desc).
  4. If success is false, throw a TypeError exception.
  5. Return success.

7.3.9 DeletePropertyOrThrow ( O, P )

The abstract operation DeletePropertyOrThrow is used to remove a specific own property of an object. It throws an exception if the property is not configurable. The operation is called with arguments O and P where O is the object and P is the property key. This abstract operation performs the following steps:

  1. Assert: Type(O) is Object.
  2. Assert: IsPropertyKey(P) is true.
  3. Let success be ? O.[[Delete]](P).
  4. If success is false, throw a TypeError exception.
  5. Return success.

7.3.10 GetMethod ( V, P )

The abstract operation GetMethod is used to get the value of a specific property of an ECMAScript language value when the value of the property is expected to be a function. The operation is called with arguments V and P where V is the ECMAScript language value, P is the property key. This abstract operation performs the following steps:

  1. Assert: IsPropertyKey(P) is true.
  2. Let func be ? GetV(V, P).
  3. If func is either undefined or null, return undefined.
  4. If IsCallable(func) is false, throw a TypeError exception.
  5. Return func.

7.3.11 HasProperty ( O, P )

The abstract operation HasProperty is used to determine whether an object has a property with the specified property key. The property may be either an own or inherited. A Boolean value is returned. The operation is called with arguments O and P where O is the object and P is the property key. This abstract operation performs the following steps:

  1. Assert: Type(O) is Object.
  2. Assert: IsPropertyKey(P) is true.
  3. Return ? O.[[HasProperty]](P).

7.3.12 HasOwnProperty ( O, P )

The abstract operation HasOwnProperty is used to determine whether an object has an own property with the specified property key. A Boolean value is returned. The operation is called with arguments O and P where O is the object and P is the property key. This abstract operation performs the following steps:

  1. Assert: Type(O) is Object.
  2. Assert: IsPropertyKey(P) is true.
  3. Let desc be ? O.[[GetOwnProperty]](P).
  4. If desc is undefined, return false.
  5. Return true.

7.3.13 Call ( F, V [ , argumentsList ] )

The abstract operation Call is used to call the [[Call]] internal method of a function object. The operation is called with arguments F, V, and optionally argumentsList where F is the function object, V is an ECMAScript language value that is the this value of the [[Call]], and argumentsList is the value passed to the corresponding argument of the internal method. If argumentsList is not present, a new empty List is used as its value. This abstract operation performs the following steps:

  1. If argumentsList is not present, set argumentsList to a new empty List.
  2. If IsCallable(F) is false, throw a TypeError exception.
  3. Return ? F.[[Call]](V, argumentsList).

7.3.14 Construct ( F [ , argumentsList [ , newTarget ] ] )

The abstract operation Construct is used to call the [[Construct]] internal method of a function object. The operation is called with arguments F, and optionally argumentsList, and newTarget where F is the function object. argumentsList and newTarget are the values to be passed as the corresponding arguments of the internal method. If argumentsList is not present, a new empty List is used as its value. If newTarget is not present, F is used as its value. This abstract operation performs the following steps:

  1. If newTarget is not present, set newTarget to F.
  2. If argumentsList is not present, set argumentsList to a new empty List.
  3. Assert: IsConstructor(F) is true.
  4. Assert: IsConstructor(newTarget) is true.
  5. Return ? F.[[Construct]](argumentsList, newTarget).
Note

If newTarget is not present, this operation is equivalent to: new F(...argumentsList)

7.3.15 SetIntegrityLevel ( O, level )

The abstract operation SetIntegrityLevel is used to fix the set of own properties of an object. This abstract operation performs the following steps:

  1. Assert: Type(O) is Object.
  2. Assert: level is either sealed or frozen.
  3. Let status be ? O.[[PreventExtensions]]().
  4. If status is false, return false.
  5. Let keys be ? O.[[OwnPropertyKeys]]().
  6. If level is sealed, then
    1. For each element k of keys, do
      1. Perform ? DefinePropertyOrThrow(O, k, PropertyDescriptor { [[Configurable]]: false }).
  7. Else,
    1. Assert: level is frozen.
    2. For each element k of keys, do
      1. Let currentDesc be ? O.[[GetOwnProperty]](k).
      2. If currentDesc is not undefined, then
        1. If IsAccessorDescriptor(currentDesc) is true, then
          1. Let desc be the PropertyDescriptor { [[Configurable]]: false }.
        2. Else,
          1. Let desc be the PropertyDescriptor { [[Configurable]]: false, [[Writable]]: false }.
        3. Perform ? DefinePropertyOrThrow(O, k, desc).
  8. Return true.

7.3.16 TestIntegrityLevel ( O, level )

The abstract operation TestIntegrityLevel is used to determine if the set of own properties of an object are fixed. This abstract operation performs the following steps:

  1. Assert: Type(O) is Object.
  2. Assert: level is either sealed or frozen.
  3. Let extensible be ? IsExtensible(O).
  4. If extensible is true, return false.
  5. NOTE: If the object is extensible, none of its properties are examined.
  6. Let keys be ? O.[[OwnPropertyKeys]]().
  7. For each element k of keys, do
    1. Let currentDesc be ? O.[[GetOwnProperty]](k).
    2. If currentDesc is not undefined, then
      1. If currentDesc.[[Configurable]] is true, return false.
      2. If level is frozen and IsDataDescriptor(currentDesc) is true, then
        1. If currentDesc.[[Writable]] is true, return false.
  8. Return true.

7.3.17 CreateArrayFromList ( elements )

The abstract operation CreateArrayFromList is used to create an Array object whose elements are provided by a List. This abstract operation performs the following steps:

  1. Assert: elements is a List whose elements are all ECMAScript language values.
  2. Let array be ! ArrayCreate(0).
  3. Let n be 0.
  4. For each element e of elements, do
    1. Perform ! CreateDataPropertyOrThrow(array, ! ToString(n), e).
    2. Set n to n + 1.
  5. Return array.

7.3.18 LengthOfArrayLike ( obj )

The abstract operation LengthOfArrayLike returns the value of the "length" property of an array-like object.

  1. Assert: Type(obj) is Object.
  2. Return ? ToLength(? Get(obj, "length")).

An array-like object is any object for which this operation returns an integer rather than an abrupt completion.

Note 1
Typically, an array-like object would also have some properties with integer index names. However, that is not a requirement of this definition.
Note 2
Array objects and String objects are examples of array-like objects.

7.3.19 CreateListFromArrayLike ( obj [ , elementTypes ] )

The abstract operation CreateListFromArrayLike is used to create a List value whose elements are provided by the indexed properties of an array-like object, obj. The optional argument elementTypes is a List containing the names of ECMAScript Language Types that are allowed for element values of the List that is created. This abstract operation performs the following steps:

  1. If elementTypes is not present, set elementTypes to « Undefined, Null, Boolean, String, Symbol, Number, BigInt, Object ».
  2. If Type(obj) is not Object, throw a TypeError exception.
  3. Let len be ? LengthOfArrayLike(obj).
  4. Let list be a new empty List.
  5. Let index be 0.
  6. Repeat, while index < len
    1. Let indexName be ! ToString(index).
    2. Let next be ? Get(obj, indexName).
    3. If Type(next) is not an element of elementTypes, throw a TypeError exception.
    4. Append next as the last element of list.
    5. Set index to index + 1.
  7. Return list.

7.3.20 Invoke ( V, P [ , argumentsList ] )

The abstract operation Invoke is used to call a method property of an ECMAScript language value. The operation is called with arguments V, P, and optionally argumentsList where V serves as both the lookup point for the property and the this value of the call, P is the property key, and argumentsList is the list of arguments values passed to the method. If argumentsList is not present, a new empty List is used as its value. This abstract operation performs the following steps:

  1. Assert: IsPropertyKey(P) is true.
  2. If argumentsList is not present, set argumentsList to a new empty List.
  3. Let func be ? GetV(V, P).
  4. Return ? Call(func, V, argumentsList).

7.3.21 OrdinaryHasInstance ( C, O )

The abstract operation OrdinaryHasInstance implements the default algorithm for determining if an object O inherits from the instance object inheritance path provided by constructor C. This abstract operation performs the following steps:

  1. If IsCallable(C) is false, return false.
  2. If C has a [[BoundTargetFunction]] internal slot, then
    1. Let BC be C.[[BoundTargetFunction]].
    2. Return ? InstanceofOperator(O, BC).
  3. If Type(O) is not Object, return false.
  4. Let P be ? Get(C, "prototype").
  5. If Type(P) is not Object, throw a TypeError exception.
  6. Repeat,
    1. Set O to ? O.[[GetPrototypeOf]]().
    2. If O is null, return false.
    3. If SameValue(P, O) is true, return true.

7.3.22 SpeciesConstructor ( O, defaultConstructor )

The abstract operation SpeciesConstructor is used to retrieve the constructor that should be used to create new objects that are derived from the argument object O. The defaultConstructor argument is the constructor to use if a constructor @@species property cannot be found starting from O. This abstract operation performs the following steps:

  1. Assert: Type(O) is Object.
  2. Let C be ? Get(O, "constructor").
  3. If C is undefined, return defaultConstructor.
  4. If Type(C) is not Object, throw a TypeError exception.
  5. Let S be ? Get(C, @@species).
  6. If S is either undefined or null, return defaultConstructor.
  7. If IsConstructor(S) is true, return S.
  8. Throw a TypeError exception.

7.3.23 EnumerableOwnPropertyNames ( O, kind )

When the abstract operation EnumerableOwnPropertyNames is called with an Object O and kind which is one of (key, value, key+value), the following steps are taken:

  1. Assert: Type(O) is Object.
  2. Let ownKeys be ? O.[[OwnPropertyKeys]]().
  3. Let properties be a new empty List.
  4. For each element key of ownKeys in List order, do
    1. If Type(key) is String, then
      1. Let desc be ? O.[[GetOwnProperty]](key).
      2. If desc is not undefined and desc.[[Enumerable]] is true, then
        1. If kind is key, append key to properties.
        2. Else,
          1. Let value be ? Get(O, key).
          2. If kind is value, append value to properties.
          3. Else,
            1. Assert: kind is key+value.
            2. Let entry be ! CreateArrayFromListkey, value »).
            3. Append entry to properties.
  5. Return properties.

7.3.24 GetFunctionRealm ( obj )

The abstract operation GetFunctionRealm with argument obj performs the following steps:

  1. Assert: ! IsCallable(obj) is true.
  2. If obj has a [[Realm]] internal slot, then
    1. Return obj.[[Realm]].
  3. If obj is a bound function exotic object, then
    1. Let target be obj.[[BoundTargetFunction]].
    2. Return ? GetFunctionRealm(target).
  4. If obj is a Proxy exotic object, then
    1. If obj.[[ProxyHandler]] is null, throw a TypeError exception.
    2. Let proxyTarget be obj.[[ProxyTarget]].
    3. Return ? GetFunctionRealm(proxyTarget).
  5. Return the current Realm Record.
Note

Step 5 will only be reached if obj is a non-standard function exotic object that does not have a [[Realm]] internal slot.

7.3.25 CopyDataProperties ( target, source, excludedItems )

When the abstract operation CopyDataProperties is called with arguments target, source, and excludedItems, the following steps are taken:

  1. Assert: Type(target) is Object.
  2. Assert: excludedItems is a List of property keys.
  3. If source is undefined or null, return target.
  4. Let from be ! ToObject(source).
  5. Let keys be ? from.[[OwnPropertyKeys]]().
  6. For each element nextKey of keys in List order, do
    1. Let excluded be false.
    2. For each element e of excludedItems in List order, do
      1. If SameValue(e, nextKey) is true, then
        1. Set excluded to true.
    3. If excluded is false, then
      1. Let desc be ? from.[[GetOwnProperty]](nextKey).
      2. If desc is not undefined and desc.[[Enumerable]] is true, then
        1. Let propValue be ? Get(from, nextKey).
        2. Perform ! CreateDataPropertyOrThrow(target, nextKey, propValue).
  7. Return target.
Note

The target passed in here is always a newly created object which is not directly accessible in case of an error being thrown.

7.4 Operations on Iterator Objects

See Common Iteration Interfaces (25.1).

7.4.1 GetIterator ( obj [ , hint [ , method ] ] )

The abstract operation GetIterator with argument obj and optional arguments hint and method performs the following steps:

  1. If hint is not present, set hint to sync.
  2. Assert: hint is either sync or async.
  3. If method is not present, then
    1. If hint is async, then
      1. Set method to ? GetMethod(obj, @@asyncIterator).
      2. If method is undefined, then
        1. Let syncMethod be ? GetMethod(obj, @@iterator).
        2. Let syncIteratorRecord be ? GetIterator(obj, sync, syncMethod).
        3. Return ! CreateAsyncFromSyncIterator(syncIteratorRecord).
    2. Otherwise, set method to ? GetMethod(obj, @@iterator).
  4. Let iterator be ? Call(method, obj).
  5. If Type(iterator) is not Object, throw a TypeError exception.
  6. Let nextMethod be ? GetV(iterator, "next").
  7. Let iteratorRecord be the Record { [[Iterator]]: iterator, [[NextMethod]]: nextMethod, [[Done]]: false }.
  8. Return iteratorRecord.

7.4.2 IteratorNext ( iteratorRecord [ , value ] )

The abstract operation IteratorNext with argument iteratorRecord and optional argument value performs the following steps:

  1. If value is not present, then
    1. Let result be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]]).
  2. Else,
    1. Let result be ? Call(iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]], « value »).
  3. If Type(result) is not Object, throw a TypeError exception.
  4. Return result.

7.4.3 IteratorComplete ( iterResult )

The abstract operation IteratorComplete with argument iterResult performs the following steps:

  1. Assert: Type(iterResult) is Object.
  2. Return ! ToBoolean(? Get(iterResult, "done")).

7.4.4 IteratorValue ( iterResult )

The abstract operation IteratorValue with argument iterResult performs the following steps:

  1. Assert: Type(iterResult) is Object.
  2. Return ? Get(iterResult, "value").

7.4.5 IteratorStep ( iteratorRecord )

The abstract operation IteratorStep with argument iteratorRecord requests the next value from iteratorRecord.[[Iterator]] by calling iteratorRecord.[[NextMethod]] and returns either false indicating that the iterator has reached its end or the IteratorResult object if a next value is available. IteratorStep performs the following steps:

  1. Let result be ? IteratorNext(iteratorRecord).
  2. Let done be ? IteratorComplete(result).
  3. If done is true, return false.
  4. Return result.

7.4.6 IteratorClose ( iteratorRecord, completion )

The abstract operation IteratorClose with arguments iteratorRecord and completion is used to notify an iterator that it should perform any actions it would normally perform when it has reached its completed state:

  1. Assert: Type(iteratorRecord.[[Iterator]]) is Object.
  2. Assert: completion is a Completion Record.
  3. Let iterator be iteratorRecord.[[Iterator]].
  4. Let return be ? GetMethod(iterator, "return").
  5. If return is undefined, return Completion(completion).
  6. Let innerResult be Call(return, iterator).
  7. If completion.[[Type]] is throw, return Completion(completion).
  8. If innerResult.[[Type]] is throw, return Completion(innerResult).
  9. If Type(innerResult.[[Value]]) is not Object, throw a TypeError exception.
  10. Return Completion(completion).

7.4.7 AsyncIteratorClose ( iteratorRecord, completion )

The abstract operation AsyncIteratorClose with arguments iteratorRecord and completion is used to notify an async iterator that it should perform any actions it would normally perform when it has reached its completed state:

  1. Assert: Type(iteratorRecord.[[Iterator]]) is Object.
  2. Assert: completion is a Completion Record.
  3. Let iterator be iteratorRecord.[[Iterator]].
  4. Let return be ? GetMethod(iterator, "return").
  5. If return is undefined, return Completion(completion).
  6. Let innerResult be Call(return, iterator).
  7. If innerResult.[[Type]] is normal, set innerResult to Await(innerResult.[[Value]]).
  8. If completion.[[Type]] is throw, return Completion(completion).
  9. If innerResult.[[Type]] is throw, return Completion(innerResult).
  10. If Type(innerResult.[[Value]]) is not Object, throw a TypeError exception.
  11. Return Completion(completion).

7.4.8 CreateIterResultObject ( value, done )

The abstract operation CreateIterResultObject with arguments value and done creates an object that supports the IteratorResult interface by performing the following steps:

  1. Assert: Type(done) is Boolean.
  2. Let obj be OrdinaryObjectCreate(%Object.prototype%).
  3. Perform ! CreateDataPropertyOrThrow(obj, "value", value).
  4. Perform ! CreateDataPropertyOrThrow(obj, "done", done).
  5. Return obj.

7.4.9 CreateListIteratorRecord ( list )

The abstract operation CreateListIteratorRecord with argument list creates an Iterator (25.1.1.2) object record whose next method returns the successive elements of list. It performs the following steps:

  1. Let iterator be OrdinaryObjectCreate(%IteratorPrototype%, « [[IteratedList]], [[ListNextIndex]] »).
  2. Set iterator.[[IteratedList]] to list.
  3. Set iterator.[[ListNextIndex]] to 0.
  4. Let steps be the algorithm steps defined in ListIteratorNext Functions.
  5. Let next be ! CreateBuiltinFunction(steps, « »).
  6. Return Record { [[Iterator]]: iterator, [[NextMethod]]: next, [[Done]]: false }.
Note

The list iterator object is never directly accessible to ECMAScript code.

7.4.9.1 ListIteratorNext Functions

A ListIteratorNext function is an anonymous built-in function. When called with no arguments, it performs the following steps:

  1. Let O be the this value.
  2. Assert: Type(O) is Object.
  3. Assert: O has an [[IteratedList]] internal slot.
  4. Let list be O.[[IteratedList]].
  5. Let index be O.[[ListNextIndex]].
  6. Let len be the number of elements of list.
  7. If indexlen, then
    1. Return CreateIterResultObject(undefined, true).
  8. Set O.[[ListNextIndex]] to index + 1.
  9. Return CreateIterResultObject(list[index], false).

The "length" property of a ListIteratorNext function is 0.