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 or of a Completion Record value. But no other specification types are used with these operations.

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 Table 9:

Table 9 — ToPrimitive Conversions
Input Type Result
Completion Record If input is an abrupt completion, return input. Otherwise return ToPrimitive(input.[[value]]) also passing the optional hint PreferredType.
Undefined Return input.
Null Return input.
Boolean Return input.
Number Return input.
String Return input.
Symbol Return input.
Object Perform the steps following this table.

When Type(input) is Object, the following steps are taken:

  1. If PreferredType was not passed, let hint be "default".
  2. Else if PreferredType is hint String, let hint be "string".
  3. Else PreferredType is hint Number, let hint be "number".
  4. Let exoticToPrim be GetMethod(input, @@toPrimitive).
  5. ReturnIfAbrupt(exoticToPrim).
  6. If exoticToPrim is not undefined, then
    1. Let result be Call(exoticToPrim, input, «hint»).
    2. ReturnIfAbrupt(result).
    3. If Type(result) is not Object, return result.
    4. Throw a TypeError exception.
  7. If hint is "default", let hint be "number".
  8. Return OrdinaryToPrimitive(input,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. ReturnIfAbrupt(method).
    3. If IsCallable(method) is true, then
      1. Let result be Call(method, O).
      2. ReturnIfAbrupt(result).
      3. If Type(result) is not Object, return result.
  6. Throw a TypeError exception.

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.3.4.45) and Symbol objects (see 19.4.3.4) over-ride the default ToPrimitive behaviour. Date objects treat no hint as if the hint were String.

7.1.2 ToBoolean ( argument )

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

Table 10 — ToBoolean Conversions
Argument Type Result
Completion Record If argument is an abrupt completion, return argument. Otherwise return ToBoolean(argument.[[value]]).
Undefined Return false.
Null Return false.
Boolean Return argument.
Number Return false if argument is +0, −0, or NaN; otherwise return true.
String Return false if argument is the empty String (its length is zero); otherwise return true.
Symbol Return true.
Object Return true.

7.1.3 ToNumber ( argument )

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

Table 11 — ToNumber Conversions
Argument Type Result
Completion Record If argument is an abrupt completion, return argument. Otherwise return ToNumber(argument.[[value]]).
Undefined Return NaN.
Null Return +0.
Boolean Return 1 if argument is true. Return +0 if argument is false.
Number Return argument (no conversion).
String See grammar and conversion algorithm below.
Symbol Throw a TypeError exception.
Object

Apply the following steps:

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

7.1.3.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 Unicode BMP code points so the result will be NaN if the string contains the UTF-16 encoding of any supplementary code points or any unpaired surrogate code points.

Syntax

StringNumericLiteral :::
StrWhiteSpaceopt
StrWhiteSpaceopt StrNumericLiteral StrWhiteSpaceopt
StrWhiteSpace :::
StrWhiteSpaceChar StrWhiteSpaceopt
StrWhiteSpaceChar :::
WhiteSpace
LineTerminator
StrNumericLiteral :::
StrDecimalLiteral
BinaryIntegerLiteral
OctalIntegerLiteral
HexIntegerLiteral
StrDecimalLiteral :::
StrUnsignedDecimalLiteral
+ StrUnsignedDecimalLiteral
- StrUnsignedDecimalLiteral
StrUnsignedDecimalLiteral :::
Infinity
DecimalDigits . DecimalDigitsopt ExponentPartopt
. DecimalDigits ExponentPartopt
DecimalDigits ExponentPartopt
DecimalDigits :::
DecimalDigit
DecimalDigits DecimalDigit
DecimalDigit ::: one of
0 1 2 3 4 5 6 7 8 9
ExponentPart :::
ExponentIndicator SignedInteger
ExponentIndicator ::: one of
e E
SignedInteger :::
DecimalDigits
+ DecimalDigits
- DecimalDigits

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 (see 11.8.3):

  • A StringNumericLiteral may include leading and/or trailing white space and/or line terminators.

  • A StringNumericLiteral that is decimal may have any number of leading 0 digits.

  • A StringNumericLiteral that is decimal may include a + or - to indicate its sign.

  • A StringNumericLiteral that is empty or contains only white space is converted to +0.

  • Infinity and –Infinity are recognized as a StringNumericLiteral but not as a NumericLiteral.

7.1.3.1.1 Runtime Semantics: MV’s

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.

  • The MV of StringNumericLiteral ::: [empty] is 0.

  • The MV of StringNumericLiteral ::: StrWhiteSpace is 0.

  • The MV of StringNumericLiteral ::: StrWhiteSpaceopt StrNumericLiteral StrWhiteSpaceopt is the MV of StrNumericLiteral, no matter whether white space is present or not.

  • The MV of StrNumericLiteral ::: StrDecimalLiteral is the MV of StrDecimalLiteral.

  • The MV of StrNumericLiteral ::: BinaryIntegerLiteral is the MV of BinaryIntegerLiteral.

  • The MV of StrNumericLiteral ::: OctalIntegerLiteral is the MV of OctalIntegerLiteral.

  • The MV of StrNumericLiteral ::: HexIntegerLiteral is the MV of HexIntegerLiteral.

  • The MV of StrDecimalLiteral ::: StrUnsignedDecimalLiteral is the MV of StrUnsignedDecimalLiteral.

  • The MV of StrDecimalLiteral ::: + StrUnsignedDecimalLiteral is the MV of StrUnsignedDecimalLiteral.

  • The MV of StrDecimalLiteral ::: - StrUnsignedDecimalLiteral is the negative of the MV of StrUnsignedDecimalLiteral. (Note that if the MV of StrUnsignedDecimalLiteral is 0, the negative of this MV is also 0. The rounding rule described below handles the conversion of this signless mathematical zero to a floating-point +0 or −0 as appropriate.)

  • The MV of StrUnsignedDecimalLiteral ::: Infinity is 1010000 (a value so large that it will round to +∞).

  • The MV of StrUnsignedDecimalLiteral ::: DecimalDigits . is the MV of DecimalDigits.

  • The MV of StrUnsignedDecimalLiteral ::: DecimalDigits . DecimalDigits is the MV of the first DecimalDigits plus (the MV of the second DecimalDigits times 10n), where n is the number of code points in the second DecimalDigits.

  • The MV of StrUnsignedDecimalLiteral ::: DecimalDigits . ExponentPart is the MV of DecimalDigits times 10e, where e is the MV of ExponentPart.

  • The MV of StrUnsignedDecimalLiteral ::: DecimalDigits . DecimalDigits ExponentPart is (the MV of the first DecimalDigits plus (the MV of the second DecimalDigits times 10n)) times 10e, where n is the number of code points in the second DecimalDigits and e is the MV of ExponentPart.

  • The MV of StrUnsignedDecimalLiteral ::: . DecimalDigits is the MV of DecimalDigits times 10n, where n is the number of code points in DecimalDigits.

  • The MV of StrUnsignedDecimalLiteral ::: . DecimalDigits ExponentPart is the MV of DecimalDigits times 10en, where n is the number of code points in DecimalDigits and e is the MV of ExponentPart.

  • The MV of StrUnsignedDecimalLiteral ::: DecimalDigits is the MV of DecimalDigits.

  • The MV of StrUnsignedDecimalLiteral ::: DecimalDigits ExponentPart is the MV of DecimalDigits times 10e, where e is the MV of ExponentPart.

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), 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.4 ToInteger ( argument )

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

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

7.1.5 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. ReturnIfAbrupt(number).
  3. If number is NaN, +0, −0, +∞, or −∞, return +0.
  4. Let int be the mathematical value that is the same sign as number and whose magnitude is floor(abs(number)).
  5. Let int32bit be int modulo 232.
  6. 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.6 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. ReturnIfAbrupt(number).
  3. If number is NaN, +0, −0, +∞, or −∞, return +0.
  4. Let int be the mathematical value that is the same sign as number and whose magnitude is floor(abs(number)).
  5. Let int32bit be int modulo 232.
  6. Return int32bit.

NOTE Given the above definition of ToUint32:

  • Step 6 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.7 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. ReturnIfAbrupt(number).
  3. If number is NaN, +0, −0, +∞, or −∞, return +0.
  4. Let int be the mathematical value that is the same sign as number and whose magnitude is floor(abs(number)).
  5. Let int16bit be int modulo 216.
  6. If int16bit ≥ 215, return int16bit − 216, otherwise return int16bit.

7.1.8 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. ReturnIfAbrupt(number).
  3. If number is NaN, +0, −0, +∞, or −∞, return +0.
  4. Let int be the mathematical value that is the same sign as number and whose magnitude is floor(abs(number)).
  5. Let int16bit be int modulo 216.
  6. Return int16bit.

NOTE Given the above definition of ToUint16:

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

7.1.9 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. ReturnIfAbrupt(number).
  3. If number is NaN, +0, −0, +∞, or −∞, return +0.
  4. Let int be the mathematical value that is the same sign as number and whose magnitude is floor(abs(number)).
  5. Let int8bit be int modulo 28.
  6. If int8bit ≥ 27, return int8bit − 28, otherwise return int8bit.

7.1.10 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. ReturnIfAbrupt(number).
  3. If number is NaN, +0, −0, +∞, or −∞, return +0.
  4. Let int be the mathematical value that is the same sign as number and whose magnitude is floor(abs(number)).
  5. Let int8bit be int modulo 28.
  6. Return int8bit.

7.1.11 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. ReturnIfAbrupt(number).
  3. If number is NaN, return +0.
  4. If number ≤ 0, return +0.
  5. If number ≥ 255, return 255.
  6. Let f be floor(number).
  7. If f + 0.5 < number, return f + 1.
  8. If number < f + 0.5, return f.
  9. If f is odd, return f + 1.
  10. 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.12 ToString ( argument )

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

Table 12 — ToString Conversions
Argument Type Result
Completion Record If argument is an abrupt completion, return argument. Otherwise return ToString(argument.[[value]]).
Undefined Return "undefined".
Null Return "null".
Boolean

If argument is true, return "true".

If argument is false, return "false".

Number See 7.1.12.1.
String Return argument.
Symbol Throw a TypeError exception.
Object

Apply the following steps:

1. Let primValue be ToPrimitive(argument, hint String).

2. Return ToString(primValue).

7.1.12.1 ToString Applied to the Number Type

The abstract operation ToString converts a Number m to String format as follows:

  1. If m is NaN, return the String "NaN".
  2. If m is +0 or −0, return the String "0".
  3. If m is less than zero, return the String concatenation of the String "-" and ToString(−m).
  4. If m is +∞, return the String "Infinity".
  5. Otherwise, let n, k, and s be integers such that k ≥ 1, 10k−1s < 10k, the Number value for s × 10n−k is m, and k is as small as possible. Note that k is the number of digits in the decimal representation of s, that s is not divisible by 10, and that the least significant digit of s is not necessarily uniquely determined by these criteria.
  6. If kn ≤ 21, return the String consisting of the code units of the k digits of the decimal representation of s (in order, with no leading zeroes), followed by n−k occurrences of the code unit 0x0030 (DIGIT ZERO).
  7. If 0 < n ≤ 21, return the String consisting of the code units of the most significant n digits of the decimal representation of s, followed by the code unit 0x002E (FULL STOP), followed by the code units of the remaining k−n digits of the decimal representation of s.
  8. If −6 < n ≤ 0, return the String consisting of the code unit 0x0030 (DIGIT ZERO), followed by the code unit 0x002E (FULL STOP), followed by −n occurrences of the code unit 0x0030 (DIGIT ZERO), followed by the code units of the k digits of the decimal representation of s.
  9. Otherwise, if k = 1, return the String consisting of the code unit of the single digit of s, followed by code unit 0x0065 (LATIN SMALL LETTER E), followed by the code unit 0x002B (PLUS SIGN) or the code unit 0x002D (HYPHEN-MINUS) according to whether n−1 is positive or negative, followed by the code units of the decimal representation of the integer abs(n−1) (with no leading zeroes).
  10. Return the String consisting of the code units of the most significant digit of the decimal representation of s, followed by code unit 0x002E (FULL STOP), followed by the code units of the remaining k−1 digits of the decimal representation of s, followed by code unit 0x0065 (LATIN SMALL LETTER E), followed by code unit 0x002B (PLUS SIGN) or the code unit 0x002D (HYPHEN-MINUS) according to whether n−1 is positive or negative, followed by the code units of the decimal representation of the integer abs(n−1) (with no leading zeroes).

NOTE 1 The following observations may be useful as guidelines for implementations, but are not part of the normative requirements of this Standard:

  • If x is any Number value other than −0, then ToNumber(ToString(x)) is exactly the same Number value as x.

  • The least significant digit of s is not always uniquely determined by the requirements listed in step 5.

NOTE 2 For implementations that provide more accurate conversions than required by the rules above, it is recommended that the following alternative version of step 5 be used as a guideline:

5. Otherwise, let n, k, and s be integers such that k ≥ 1, 10k−1s < 10k, the Number value for s × 10nk is m, and k is as small as possible. If there are multiple possibilities for s, choose the value of s for which s × 10nk is closest in value to m. If there are two such possible values of s, choose the one that is even. Note that k is the number of digits in the decimal representation of s and that s is not divisible by 10.

NOTE 3 Implementers of ECMAScript may find useful the paper and code written by David M. Gay for binary-to-decimal conversion of floating-point numbers:

Gay, David M. Correctly Rounded Binary-Decimal and Decimal-Binary Conversions. Numerical Analysis, Manuscript 90-10. AT&T Bell Laboratories (Murray Hill, New Jersey). November 30, 1990. Available as
http://cm.bell-labs.com/cm/cs/doc/90/4-10.ps.gz. Associated code available as
http://netlib.sandia.gov/fp/dtoa.c and as
http://netlib.sandia.gov/fp/g_fmt.c and may also be found at the various netlib mirror sites.

7.1.13 ToObject ( argument )

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

Table 13 — ToObject Conversions
Argument Type Result
Completion Record If argument is an abrupt completion, return argument. Otherwise return ToObject(argument.[[value]]).
Undefined Throw a TypeError exception.
Null Throw a TypeError exception.
Boolean Return a new Boolean object whose [[BooleanData]] internal slot is set to the value of argument. See 19.3 for a description of Boolean objects.
Number Return a new Number object whose [[NumberData]] internal slot is set to the value of argument. See 20.1 for a description of Number objects.
String Return a new String object whose [[StringData]] internal slot is set to the value of argument. See 21.1 for a description of String objects.
Symbol Return a new Symbol object whose [[SymbolData]] internal slot is set to the value of argument. See 19.4 for a description of Symbol objects.
Object Return argument.

7.1.14 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. ReturnIfAbrupt(key).
  3. If Type(key) is Symbol, then
    1. Return key.
  4. Return ToString(key).

7.1.15 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. ReturnIfAbrupt(argument).
  2. Let len be ToInteger(argument).
  3. ReturnIfAbrupt(len).
  4. If len ≤ +0, return +0.
  5. If len is +∞, return 253-1.
  6. Return min(len, 253-1).

7.1.16 CanonicalNumericIndexString ( argument )

The abstract operation CanonicalNumericIndexString returns argument converted to a numeric 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.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 14:

Table 14 — RequireObjectCoercible Results
Argument Type Result
Completion Record If argument is an abrupt completion, return argument. Otherwise return RequireObjectCoercible(argument.[[value]]).
Undefined Throw a TypeError exception.
Null Throw a TypeError exception.
Boolean Return argument.
Number Return argument.
String Return argument.
Symbol 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 the value of the [[ProxyHandler]] internal slot of argument is null, throw a TypeError exception.
    2. Let target be the value of the [[ProxyTarget]] internal slot of argument.
    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 or a Completion Record, is a callable function with a [[Call]] internal method.

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

7.2.4 IsConstructor ( argument )

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

  1. ReturnIfAbrupt(argument).
  2. If Type(argument) is not Object, return false.
  3. If argument has a [[Construct]] internal method, return true.
  4. 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 numeric value.

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

7.2.7 IsPropertyKey ( argument )

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

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

7.2.8 IsRegExp ( argument )

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

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

7.2.9 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. ReturnIfAbrupt(x).
  2. ReturnIfAbrupt(y).
  3. If Type(x) is different from Type(y), return false.
  4. If Type(x) is Undefined, return true.
  5. If Type(x) is Null, return true.
  6. If Type(x) is Number, then
    1. If x is NaN and y is NaN, return true.
    2. If x is +0 and y is −0, return false.
    3. If x is −0 and y is +0, return false.
    4. If x is the same Number value as y, return true.
    5. Return false.
  7. 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.
  8. If Type(x) is Boolean, then
    1. If x and y are both true or both false, return true; otherwise, return false.
  9. If Type(x) is Symbol, then
    1. If x and y are both the same Symbol value, return true; otherwise, return false.
  10. Return true if x and y are the same Object value. Otherwise, return false.

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

7.2.10 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. ReturnIfAbrupt(x).
  2. ReturnIfAbrupt(y).
  3. If Type(x) is different from Type(y), return false.
  4. If Type(x) is Undefined, return true.
  5. If Type(x) is Null, return true.
  6. If Type(x) is Number, then
    1. If x is NaN and y is NaN, return true.
    2. If x is +0 and y is −0, return true.
    3. If x is −0 and y is +0, return true.
    4. If x is the same Number value as y, return true.
    5. Return false.
  7. 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.
  8. If Type(x) is Boolean, then
    1. If x and y are both true or both false, return true; otherwise, return false.
  9. If Type(x) is Symbol, then
    1. If x and y are both the same Symbol value, return true; otherwise, return false.
  10. Return true if x and y are the same Object value. Otherwise, return false.

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

7.2.11 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. ReturnIfAbrupt(x).
  2. ReturnIfAbrupt(y).
  3. If the LeftFirst flag is true, then
    1. Let px be ToPrimitive(x, hint Number).
    2. ReturnIfAbrupt(px).
    3. Let py be ToPrimitive(y, hint Number).
    4. ReturnIfAbrupt(py).
  4. Else the order of evaluation needs to be reversed to preserve left to right evaluation
    1. Let py be ToPrimitive(y, hint Number).
    2. ReturnIfAbrupt(py).
    3. Let px be ToPrimitive(x, hint Number).
    4. ReturnIfAbrupt(px).
  5. If both px and py are Strings, then
    1. If py is a prefix of px, return false. (A String value p is a prefix of String value q if q can be the result of concatenating p and some other String r. Note that any String is a prefix of itself, because r may be the empty String.)
    2. If px is a prefix of py, 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 code unit value at index k within px.
    5. Let n be the integer that is the code unit value at index k within py.
    6. If m < n, return true. Otherwise, return false.
  6. Else,
    1. Let nx be ToNumber(px). Because px and py are primitive values evaluation order is not important.
    2. ReturnIfAbrupt(nx).
    3. Let ny be ToNumber(py).
    4. ReturnIfAbrupt(ny).
    5. If nx is NaN, return undefined.
    6. If ny is NaN, return undefined.
    7. If nx and ny are the same Number value, return false.
    8. If nx is +0 and ny is −0, return false.
    9. If nx is −0 and ny is +0, return false.
    10. If nx is +∞, return false.
    11. If ny is +∞, return true.
    12. If ny is −∞, return false.
    13. If nx is −∞, return true.
    14. If the mathematical value of nx is less than the mathematical value of ny —note that these mathematical values are both finite and not both zero—return true. Otherwise, return false.

NOTE 1 Step 5 differs from step 11 in the algorithm for the addition operator + (12.7.3) in using “and” instead of “or”.

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.12 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. ReturnIfAbrupt(x).
  2. ReturnIfAbrupt(y).
  3. If Type(x) is the same as Type(y), then
    1. Return the result of performing Strict Equality Comparison x === y.
  4. If x is null and y is undefined, return true.
  5. If x is undefined and y is null, return true.
  6. If Type(x) is Number and Type(y) is String,
    return the result of the comparison x == ToNumber(y).
  7. If Type(x) is String and Type(y) is Number,
    return the result of the comparison ToNumber(x) == y.
  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, or Symbol and Type(y) is Object, then
    return the result of the comparison x == ToPrimitive(y).
  11. If Type(x) is Object and Type(y) is either String, Number, or Symbol, then
    return the result of the comparison ToPrimitive(x) == y.
  12. Return false.

7.2.13 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 Undefined, return true.
  3. If Type(x) is Null, return true.
  4. If Type(x) is Number, then
    1. If x is NaN, return false.
    2. If y is NaN, return false.
    3. If x is the same Number value as y, return true.
    4. If x is +0 and y is −0, return true.
    5. If x is −0 and y is +0, return true.
    6. Return false.
  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.
    2. Else, return false.
  6. If Type(x) is Boolean, then
    1. If x and y are both true or both false, return true.
    2. Else, return false.
  7. If x and y are the same Symbol value, return true.
  8. If x and y are the same Object value, return true.
  9. Return false.

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

7.3 Operations on Objects

7.3.1 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.2 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. ReturnIfAbrupt(O).
  4. Return O.[[Get]](P, V).

7.3.3 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. ReturnIfAbrupt(success).
  6. If success is false and Throw is true, throw a TypeError exception.
  7. Return success.

7.3.4 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.5 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.6 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. ReturnIfAbrupt(success).
  5. If success is false, throw a TypeError exception.
  6. 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.7 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. ReturnIfAbrupt(success).
  5. If success is false, throw a TypeError exception.
  6. Return success.

7.3.8 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. ReturnIfAbrupt(success).
  5. If success is false, throw a TypeError exception.
  6. Return success.

7.3.9 GetMethod (O, P)

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

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

7.3.10 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.11 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. ReturnIfAbrupt(desc).
  5. If desc is undefined, return false.
  6. Return true.

7.3.12 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, an empty List is used as its value. This abstract operation performs the following steps:

  1. ReturnIfAbrupt(F).
  2. If argumentsList was not passed, let argumentsList be a new empty List.
  3. If IsCallable(F) is false, throw a TypeError exception.
  4. Return F.[[Call]](V, argumentsList).

7.3.13 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, an 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 was not passed, let newTarget be F.
  2. If argumentsList was not passed, let argumentsList be 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 passed, this operation is equivalent to: new F(...argumentsList)

7.3.14 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. ReturnIfAbrupt(status).
  5. If status is false, return false.
  6. Let keys be O.[[OwnPropertyKeys]]().
  7. ReturnIfAbrupt(keys).
  8. If level is "sealed", then
    1. Repeat for each element k of keys,
      1. Let status be DefinePropertyOrThrow(O, k, PropertyDescriptor{ [[Configurable]]: false}).
      2. ReturnIfAbrupt(status).
  9. Else level is "frozen",
    1. Repeat for each element k of keys,
      1. Let currentDesc be O.[[GetOwnProperty]](k).
      2. ReturnIfAbrupt(currentDesc).
      3. 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. Let status be DefinePropertyOrThrow(O, k, desc).
        4. ReturnIfAbrupt(status).
  10. Return true.

7.3.15 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 status be IsExtensible(O).
  4. ReturnIfAbrupt(status).
  5. If status is true, return false
  6. NOTE If the object is extensible, none of its properties are examined.
  7. Let keys be O.[[OwnPropertyKeys]]().
  8. ReturnIfAbrupt(keys).
  9. Repeat for each element k of keys,
    1. Let currentDesc be O.[[GetOwnProperty]](k).
    2. ReturnIfAbrupt(currentDesc).
    3. 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.
  10. Return true.

7.3.16 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) (see 9.4.2.2).
  3. Let n be 0.
  4. For each element e of elements
    1. Let status be CreateDataProperty(array, ToString(n), e).
    2. Assert: status is true.
    3. Increment n by 1.
  5. Return array.

7.3.17 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. ReturnIfAbrupt(obj).
  2. If elementTypes was not passed, let elementTypes be (Undefined, Null, Boolean, String, Symbol, Number, Object).
  3. If Type(obj) is not Object, throw a TypeError exception.
  4. Let len be ToLength(Get(obj, "length")).
  5. ReturnIfAbrupt(len).
  6. Let list be an empty List.
  7. Let index be 0.
  8. Repeat while index < len
    1. Let indexName be ToString(index).
    2. Let next be Get(obj, indexName).
    3. ReturnIfAbrupt(next).
    4. If Type(next) is not an element of elementTypes, throw a TypeError exception.
    5. Append next as the last element of list.
    6. Set index to index + 1.
  9. Return list.

7.3.18 Invoke(O,P, [argumentsList])

The abstract operation Invoke is used to call a method property of an object. The operation is called with arguments O, P , and optionally argumentsList where O 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, an empty List is used as its value. This abstract operation performs the following steps:

  1. Assert: IsPropertyKey(P) is true.
  2. If argumentsList was not passed, let argumentsList be a new empty List.
  3. Let func be GetV(O, P).
  4. Return Call(func, O, argumentsList).

7.3.19 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 the value of C’s [[BoundTargetFunction]] internal slot.
    2. Return InstanceofOperator(O,BC) (see 12.9.4).
  3. If Type(O) is not Object, return false.
  4. Let P be Get(C, "prototype").
  5. ReturnIfAbrupt(P).
  6. If Type(P) is not Object, throw a TypeError exception.
  7. Repeat
    1. Let O be O.[[GetPrototypeOf]]().
    2. ReturnIfAbrupt(O).
    3. If O is null, return false.
    4. If SameValue(P, O) is true, return true.

7.3.20 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. ReturnIfAbrupt(C).
  4. If C is undefined, return defaultConstructor.
  5. If Type(C) is not Object, throw a TypeError exception.
  6. Let S be Get(C, @@species).
  7. ReturnIfAbrupt(S).
  8. If S is either undefined or null, return defaultConstructor.
  9. If IsConstructor(S) is true, return S.
  10. Throw a TypeError exception.

7.3.21 EnumerableOwnNames (O)

When the abstract operation EnumerableOwnNames is called with Object O the following steps are taken:

  1. Assert: Type(O) is Object.
  2. Let ownKeys be O.[[OwnPropertyKeys]]().
  3. ReturnIfAbrupt(ownKeys).
  4. Let names be a new empty List.
  5. Repeat, for each element key of ownKeys in List order
    1. If Type(key) is String, then
      1. Let desc be O.[[GetOwnProperty]](key).
      2. ReturnIfAbrupt(desc).
      3. If desc is not undefined, then
        1. If desc.[[Enumerable]] is true, append key to names.
  6. Order the elements of names so they are in the same relative order as would be produced by the Iterator that would be returned if the [[Enumerate]] internal method was invoked on O.
  7. Return names.

NOTE The order of elements in the returned list is the same as the enumeration order that is used by a for-in statement.

7.3.22 GetFunctionRealm ( obj )

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

  1. Assert: obj is a callable object.
  2. If obj has a [[Realm]] internal slot, then
    1. Return obj's [[Realm]] internal slot.
  3. If obj is a Bound Function exotic object, then
    1. Let target be obj's [[BoundTargetFunction]] internal slot.
    2. Return GetFunctionRealm(target).
  4. If obj is a Proxy exotic object, then
    1. If the value of the [[ProxyHandler]] internal slot of obj is null, throw a TypeError exception.
    2. Let proxyTarget be the value of obj's [[ProxyTarget]] internal slot.
    3. Return GetFunctionRealm(proxyTarget).
  5. Return the running execution context's Realm.

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

7.4 Operations on Iterator Objects

See Common Iteration Interfaces (25.1).

7.4.1 GetIterator ( obj, method )

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

  1. ReturnIfAbrupt(obj).
  2. If method was not passed, then
    1. Let method be GetMethod(obj, @@iterator).
    2. ReturnIfAbrupt(method).
  3. Let iterator be Call(method,obj).
  4. ReturnIfAbrupt(iterator).
  5. If Type(iterator) is not Object, throw a TypeError exception.
  6. Return iterator.

7.4.2 IteratorNext ( iterator, value )

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

  1. If value was not passed, then
    1. Let result be Invoke(iterator, "next", «‍ »).
  2. Else,
    1. Let result be Invoke(iterator, "next", «‍value»).
  3. ReturnIfAbrupt(result).
  4. If Type(result) is not Object, throw a TypeError exception.
  5. 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 ( iterator )

The abstract operation IteratorStep with argument iterator requests the next value from iterator 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(iterator).
  2. ReturnIfAbrupt(result).
  3. Let done be IteratorComplete(result).
  4. ReturnIfAbrupt(done).
  5. If done is true, return false.
  6. Return result.

7.4.6 IteratorClose( iterator, completion )

The abstract operation IteratorClose with arguments iterator 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(iterator) is Object.
  2. Assert: completion is a Completion Record.
  3. Let return be GetMethod(iterator, "return").
  4. ReturnIfAbrupt(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 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 ObjectCreate(%ObjectPrototype%).
  3. Perform CreateDataProperty(obj, "value", value).
  4. Perform CreateDataProperty(obj, "done", done).
  5. Return obj.

7.4.8 CreateListIterator ( list )

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

  1. Let iterator be ObjectCreate(%IteratorPrototype%, «[[IteratorNext]], [[IteratedList]], [[ListIteratorNextIndex]]»).
  2. Set iterator’s [[IteratedList]] internal slot to list.
  3. Set iterator’s [[ListIteratorNextIndex]] internal slot to 0.
  4. Let next be a new built-in function object as defined in ListIterator next (7.4.8.1).
  5. Set iterator’s [[IteratorNext]] internal slot to next.
  6. Perform CreateMethodProperty(iterator, "next", next).
  7. Return iterator.

7.4.8.1 ListIterator next( )

The ListIterator next method is a standard built-in function object (clause 17) that performs the following steps:

  1. Let O be the this value.
  2. Let f be the active function object.
  3. If O does not have a [[IteratorNext]] internal slot, throw a TypeError exception.
  4. Let next be the value of the [[IteratorNext]] internal slot of O.
  5. If SameValue(f, next) is false, throw a TypeError exception.
  6. If O does not have a [[IteratedList]] internal slot, throw a TypeError exception.
  7. Let list be the value of the [[IteratedList]] internal slot of O.
  8. Let index be the value of the [[ListIteratorNextIndex]] internal slot of O.
  9. Let len be the number of elements of list.
  10. If indexlen, then
    1. Return CreateIterResultObject(undefined, true).
  11. Set the value of the [[ListIteratorNextIndex]] internal slot of O to index+1.
  12. Return CreateIterResultObject(list[index], false).

NOTE A ListIterator next method will throw an exception if applied to any object other than the one with which it was originally associated.