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
7.1 Type Conversion
The ECMAScript language implicitly performs automatic
The BigInt
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
Assert : input is anECMAScript language value .- If
Type (input) is Object, then- If PreferredType is not present, let hint be
"default" . - Else if PreferredType is hint String, let hint be
"string" . - Else,
Assert : PreferredType is hint Number.- Let hint be
"number" .
- Let exoticToPrim be ?
GetMethod (input, @@toPrimitive). - If exoticToPrim is not
undefined , then - If hint is
"default" , set hint to"number" . - Return ?
OrdinaryToPrimitive (input, hint).
- If PreferredType is not present, let hint be
- Return input.
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
7.1.1.1 OrdinaryToPrimitive ( O, hint )
When the abstract operation OrdinaryToPrimitive is called with arguments O and hint, the following steps are taken:
Assert :Type (O) is Object.Assert :Type (hint) is String and its value is either"string" or"number" .- If hint is
"string" , then- Let methodNames be «
"toString" ,"valueOf" ».
- Let methodNames be «
- Else,
- Let methodNames be «
"valueOf" ,"toString" ».
- Let methodNames be «
- For each name in methodNames in
List order, do- Let method be ?
Get (O, name). - If
IsCallable (method) istrue , then
- Let method be ?
- Throw a
TypeError exception.
7.1.2 ToBoolean ( argument )
The abstract operation ToBoolean converts argument to a value of
|
Argument |
Result |
|---|---|
| Undefined |
Return |
| Null |
Return |
| Boolean | Return argument. |
| Number |
If argument is |
| String |
If argument is the empty String (its length is zero), return |
| Symbol |
Return |
| BigInt |
If argument is |
| Object |
Return |
7.1.3 ToNumeric ( value )
The abstract operation ToNumeric returns value converted to a numeric value of
- Let primValue be ?
ToPrimitive (value, hint Number). - If
Type (primValue) is BigInt, return primValue. - Return ?
ToNumber (primValue).
7.1.4 ToNumber ( argument )
The abstract operation ToNumber converts argument to a value of
|
Argument |
Result |
|---|---|
| Undefined |
Return |
| Null |
Return |
| Boolean |
If argument is |
| Number | Return argument (no conversion). |
| String | See grammar and conversion algorithm below. |
| Symbol |
Throw a |
| BigInt |
Throw a |
| Object |
Apply the following steps:
|
7.1.4.1 ToNumber Applied to the String Type
The terminal symbols of this grammar are all composed of characters in the Unicode Basic Multilingual Plane (BMP). Therefore, the result of
Syntax
All grammar symbols not explicitly defined above have the definitions used in the Lexical Grammar for numeric literals (
Some differences should be noted between the syntax of a
-
A
StringNumericLiteral may include leading and/or trailing white space and/or line terminators. -
A
StringNumericLiteral that is decimal may have any number of leading0digits. -
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 . -
Infinityand-Infinityare recognized as aStringNumericLiteral but not as aNumericLiteral . -
A
StringNumericLiteral cannot include aBigIntLiteralSuffix .
7.1.4.1.1 Runtime Semantics: MV
The conversion of a String to a
-
The MV of
is 0ℝ.StringNumericLiteral ::: [empty] -
The MV of
is 0ℝ.StringNumericLiteral ::: StrWhiteSpace -
The MV of
is the MV ofStringNumericLiteral ::: StrWhiteSpace opt StrNumericLiteral StrWhiteSpace opt StrNumericLiteral , no matter whether white space is present or not. -
The MV of
is the MV ofStrNumericLiteral ::: StrDecimalLiteral StrDecimalLiteral . -
The MV of
is the MV ofStrNumericLiteral ::: NonDecimalIntegerLiteral NonDecimalIntegerLiteral . -
The MV of
is the MV ofStrDecimalLiteral ::: StrUnsignedDecimalLiteral StrUnsignedDecimalLiteral . -
The MV of
is the MV ofStrDecimalLiteral ::: + StrUnsignedDecimalLiteral StrUnsignedDecimalLiteral . -
The MV of
is the negative of the MV ofStrDecimalLiteral ::: - StrUnsignedDecimalLiteral StrUnsignedDecimalLiteral . (Note that if the MV ofStrUnsignedDecimalLiteral 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
is 10ℝ10000ℝ (a value so large that it will round toStrUnsignedDecimalLiteral ::: Infinity +∞ ). -
The MV of
is the MV ofStrUnsignedDecimalLiteral ::: DecimalDigits . DecimalDigits . -
The MV of
is the MV of the firstStrUnsignedDecimalLiteral ::: DecimalDigits . DecimalDigits DecimalDigits plus (the MV of the secondDecimalDigits times 10ℝ-ℝn), where n is themathematical value of the number of code points in the secondDecimalDigits . -
The MV of
is the MV ofStrUnsignedDecimalLiteral ::: DecimalDigits . ExponentPart DecimalDigits times 10ℝe, where e is the MV ofExponentPart . -
The MV of
is (the MV of the firstStrUnsignedDecimalLiteral ::: DecimalDigits . DecimalDigits ExponentPart DecimalDigits plus (the MV of the secondDecimalDigits times 10ℝ-ℝn)) times 10ℝe, where n is themathematical value of the number of code points in the secondDecimalDigits and e is the MV ofExponentPart . -
The MV of
is the MV ofStrUnsignedDecimalLiteral ::: . DecimalDigits DecimalDigits times 10ℝ-ℝn, where n is themathematical value of the number of code points inDecimalDigits . -
The MV of
is the MV ofStrUnsignedDecimalLiteral ::: . DecimalDigits ExponentPart DecimalDigits times 10ℝe -ℝ n, where n is themathematical value of the number of code points inDecimalDigits and e is the MV ofExponentPart . -
The MV of
is the MV ofStrUnsignedDecimalLiteral ::: DecimalDigits DecimalDigits . -
The MV of
is the MV ofStrUnsignedDecimalLiteral ::: DecimalDigits ExponentPart DecimalDigits times 10ℝe, where e is the MV ofExponentPart .
Once the exact MV for a String numeric literal has been determined, it is then rounded to a value of the Number -, in which case the rounded value is
-
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
- Let number be ?
ToNumber (argument). - If number is
NaN ,+0 , or-0 , return+0 . - If number is
+∞ or-∞ , return number. - Let integer be the
Number value that is the same sign as number and whose magnitude isfloor (abs (number)). - If integer is
-0 , return+0 . - Return integer.
7.1.6 ToInt32 ( argument )
The abstract operation ToInt32 converts argument to one of 232
- Let number be ?
ToNumber (argument). - If number is
NaN ,+0 ,-0 ,+∞ , or-∞ , return+0 . - Let int be the
Number value that is the same sign as number and whose magnitude isfloor (abs (number)). - Let int32bit be int
modulo 232. - If int32bit ≥ 231, return int32bit - 232; otherwise return int32bit.
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
- Let number be ?
ToNumber (argument). - If number is
NaN ,+0 ,-0 ,+∞ , or-∞ , return+0 . - Let int be the
Number value that is the same sign as number and whose magnitude isfloor (abs (number)). - Let int32bit be int
modulo 232. - Return int32bit.
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
- Let number be ?
ToNumber (argument). - If number is
NaN ,+0 ,-0 ,+∞ , or-∞ , return+0 . - Let int be the
Number value that is the same sign as number and whose magnitude isfloor (abs (number)). - Let int16bit be int
modulo 216. - If int16bit ≥ 215, return int16bit - 216; otherwise return int16bit.
7.1.9 ToUint16 ( argument )
The abstract operation ToUint16 converts argument to one of 216
- Let number be ?
ToNumber (argument). - If number is
NaN ,+0 ,-0 ,+∞ , or-∞ , return+0 . - Let int be the
Number value that is the same sign as number and whose magnitude isfloor (abs (number)). - Let int16bit be int
modulo 216. - Return int16bit.
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
- Let number be ?
ToNumber (argument). - If number is
NaN ,+0 ,-0 ,+∞ , or-∞ , return+0 . - Let int be the
Number value that is the same sign as number and whose magnitude isfloor (abs (number)). - Let int8bit be int
modulo 28. - If int8bit ≥ 27, return int8bit - 28; otherwise return int8bit.
7.1.11 ToUint8 ( argument )
The abstract operation ToUint8 converts argument to one of 28
- Let number be ?
ToNumber (argument). - If number is
NaN ,+0 ,-0 ,+∞ , or-∞ , return+0 . - Let int be the
Number value that is the same sign as number and whose magnitude isfloor (abs (number)). - Let int8bit be int
modulo 28. - Return int8bit.
7.1.12 ToUint8Clamp ( argument )
The abstract operation ToUint8Clamp converts argument to one of 28
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.
- Let prim be ?
ToPrimitive (argument, hint Number). - Return the value that prim corresponds to in
Table 12 .
|
Argument |
Result |
|---|---|
| Undefined |
Throw a |
| Null |
Throw a |
| Boolean |
Return 1n if prim is 0n if prim is |
| BigInt | Return prim. |
| Number |
Throw a |
| String |
|
| Symbol |
Throw a |
7.1.14 StringToBigInt ( argument )
Apply the algorithm in
- Replace the
StrUnsignedDecimalLiteral production withDecimalDigits to not allowInfinity , decimal points, or exponents. - If the MV is
NaN , returnNaN , otherwise return the BigInt which exactly corresponds to the MV, rather than rounding to a Number.
7.1.15 ToBigInt64 ( argument )
7.1.16 ToBigUint64 ( argument )
7.1.17 ToString ( argument )
The abstract operation ToString converts argument to a value of
|
Argument |
Result |
|---|---|
| Undefined |
Return |
| Null |
Return |
| Boolean |
If argument is If argument is |
| Number |
Return ! |
| String | Return argument. |
| Symbol |
Throw a |
| BigInt |
Return ! |
| Object |
Apply the following steps:
|
7.1.18 ToObject ( argument )
The abstract operation ToObject converts argument to a value of
|
Argument |
Result |
|---|---|
| Undefined |
Throw a |
| Null |
Throw a |
| Boolean |
Return a new Boolean object whose [[BooleanData]] internal slot is set to argument. See |
| Number |
Return a new Number object whose [[NumberData]] internal slot is set to argument. See |
| String |
Return a new String object whose [[StringData]] internal slot is set to argument. See |
| Symbol |
Return a new Symbol object whose [[SymbolData]] internal slot is set to argument. See |
| BigInt |
Return a new BigInt object whose [[BigIntData]] internal slot is set to argument. See |
| 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:
- Let key be ?
ToPrimitive (argument, hint String). - If
Type (key) is Symbol, then- Return key.
- Return !
ToString (key).
7.1.20 ToLength ( argument )
The abstract operation ToLength converts argument to an
7.1.21 CanonicalNumericIndexString ( argument )
The abstract operation CanonicalNumericIndexString returns argument converted to a
A canonical numeric string is any String value for which the CanonicalNumericIndexString abstract operation does not return
7.1.22 ToIndex ( value )
The abstract operation ToIndex returns value argument converted to a non-negative
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
|
Argument |
Result |
|---|---|
| Undefined |
Throw a |
| Null |
Throw a |
| 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:
- If
Type (argument) is not Object, returnfalse . - If argument is an
Array exotic object , returntrue . - If argument is a
Proxy exotic object , then- If argument.[[ProxyHandler]] is
null , throw aTypeError exception. - Let target be argument.[[ProxyTarget]].
- Return ? IsArray(target).
- If argument.[[ProxyHandler]] is
- Return
false .
7.2.3 IsCallable ( argument )
The abstract operation IsCallable determines if argument, which must be an
- If
Type (argument) is not Object, returnfalse . - If argument has a [[Call]] internal method, return
true . - Return
false .
7.2.4 IsConstructor ( argument )
The abstract operation IsConstructor determines if argument, which must be an
- If
Type (argument) is not Object, returnfalse . - If argument has a [[Construct]] internal method, return
true . - Return
false .
7.2.5 IsExtensible ( O )
7.2.6 IsInteger ( argument )
7.2.7 IsNonNegativeInteger ( argument )
The abstract operation IsNonNegativeInteger determines if argument is non-negative
- If !
IsInteger (argument) istrue and argument ≥ 0, returntrue . - Otherwise, return
false .
7.2.8 IsPropertyKey ( argument )
The abstract operation IsPropertyKey determines if argument, which must be an
7.2.9 IsRegExp ( argument )
The abstract operation IsRegExp with argument argument performs the following steps:
7.2.10 IsStringPrefix ( p, q )
The abstract operation IsStringPrefix determines if String p is a prefix of String q.
Assert :Type (p) is String.Assert :Type (q) is String.- If q can be the
string-concatenation of p and some other String r, returntrue . Otherwise, returnfalse .
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
- If
Type (x) is different fromType (y), returnfalse . - If
Type (x) is Number or BigInt, then- Return !
Type (x)::sameValue(x, y).
- Return !
- Return !
SameValueNonNumeric (x, y).
This algorithm differs from the
7.2.12 SameValueZero ( x, y )
The internal comparison abstract operation SameValueZero(x, y), where x and y are ECMAScript language values, produces
- If
Type (x) is different fromType (y), returnfalse . - If
Type (x) is Number or BigInt, then- Return !
Type (x)::sameValueZero(x, y).
- Return !
- Return !
SameValueNonNumeric (x, y).
SameValueZero differs from
7.2.13 SameValueNonNumeric ( x, y )
The internal comparison abstract operation SameValueNonNumeric(x, y), where neither x nor y are numeric
Assert :Type (x) is not Number or BigInt.Assert :Type (x) is the same asType (y).- If
Type (x) is Undefined, returntrue . - If
Type (x) is Null, returntrue . - If
Type (x) is String, then- If x and y are exactly the same sequence of code units (same length and same code units at corresponding indices), return
true ; otherwise, returnfalse .
- If x and y are exactly the same sequence of code units (same length and same code units at corresponding indices), return
- If
Type (x) is Boolean, then- If x and y are both
true or bothfalse , returntrue ; otherwise, returnfalse .
- If x and y are both
- If
Type (x) is Symbol, then- If x and y are both the same Symbol value, return
true ; otherwise, returnfalse .
- If x and y are both the same Symbol value, return
- If x and y are the same Object value, return
true . Otherwise, returnfalse .
7.2.14 Abstract Relational Comparison
The comparison x < y, where x and y are values, produces
- If the LeftFirst flag is
true , then- Let px be ?
ToPrimitive (x, hint Number). - Let py be ?
ToPrimitive (y, hint Number).
- Let px be ?
- Else,
- NOTE: The order of evaluation needs to be reversed to preserve left to right evaluation.
- Let py be ?
ToPrimitive (y, hint Number). - Let px be ?
ToPrimitive (x, hint Number).
- If
Type (px) is String andType (py) is String, then- If
IsStringPrefix (py, px) istrue , returnfalse . - If
IsStringPrefix (px, py) istrue , returntrue . - 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.) - Let m be the
integer that is the numeric value of the code unit at index k within px. - Let n be the
integer that is the numeric value of the code unit at index k within py. - If m < n, return
true . Otherwise, returnfalse .
- If
- Else,
- If
Type (px) is BigInt andType (py) is String, then- Let ny be !
StringToBigInt (py). - If ny is
NaN , returnundefined . - Return BigInt::lessThan(px, ny).
- Let ny be !
- If
Type (px) is String andType (py) is BigInt, then- Let nx be !
StringToBigInt (px). - If nx is
NaN , returnundefined . - Return BigInt::lessThan(nx, py).
- Let nx be !
- NOTE: Because px and py are primitive values, evaluation order is not important.
- Let nx be ?
ToNumeric (px). - Let ny be ?
ToNumeric (py). - If
Type (nx) is the same asType (ny), returnType (nx)::lessThan(nx, ny). Assert :Type (nx) is BigInt andType (ny) is Number, orType (nx) is Number andType (ny) is BigInt.- If nx or ny is
NaN , returnundefined . - If nx is
-∞ or ny is+∞ , returntrue . - If nx is
+∞ or ny is-∞ , returnfalse . - If the
mathematical value of nx is less than themathematical value of ny, returntrue ; otherwise returnfalse .
- If
Step 3 differs from step 7 in the algorithm for the addition operator + (
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
- If
Type (x) is the same asType (y), then- Return the result of performing
Strict Equality Comparison x === y.
- Return the result of performing
- If x is
null and y isundefined , returntrue . - If x is
undefined and y isnull , returntrue . - If
Type (x) is Number andType (y) is String, return the result of the comparison x == !ToNumber (y). - If
Type (x) is String andType (y) is Number, return the result of the comparison !ToNumber (x) == y. - If
Type (x) is BigInt andType (y) is String, then- Let n be !
StringToBigInt (y). - If n is
NaN , returnfalse . - Return the result of the comparison x == n.
- Let n be !
- If
Type (x) is String andType (y) is BigInt, return the result of the comparison y == x. - If
Type (x) is Boolean, return the result of the comparison !ToNumber (x) == y. - If
Type (y) is Boolean, return the result of the comparison x == !ToNumber (y). - If
Type (x) is either String, Number, BigInt, or Symbol andType (y) is Object, return the result of the comparison x ==ToPrimitive (y). - If
Type (x) is Object andType (y) is either String, Number, BigInt, or Symbol, return the result of the comparisonToPrimitive (x) == y. - If
Type (x) is BigInt andType (y) is Number, or ifType (x) is Number andType (y) is BigInt, then- If x or y are any of
NaN ,+∞ , or-∞ , returnfalse . - If the
mathematical value of x is equal to themathematical value of y, returntrue ; otherwise returnfalse .
- If x or y are any of
- Return
false .
7.2.16 Strict Equality Comparison
The comparison x === y, where x and y are values, produces
- If
Type (x) is different fromType (y), returnfalse . - If
Type (x) is Number or BigInt, then- Return !
Type (x)::equal(x, y).
- Return !
- Return !
SameValueNonNumeric (x, y).
This algorithm differs from the
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.
Assert : internalSlotsList is aList of internal slot names.- Let obj be a newly created object with an internal slot for each name in internalSlotsList.
Set obj's essential internal methods to the defaultordinary object definitions specified in9.1 .Assert : If the caller will not be overriding both obj's [[GetPrototypeOf]] and [[SetPrototypeOf]] essential internal methods, then internalSlotsList contains [[Prototype]].Assert : If the caller will not be overriding all of obj's [[SetPrototypeOf]], [[IsExtensible]], and [[PreventExtensions]] essential internal methods, then internalSlotsList contains [[Extensible]].- If internalSlotsList contains [[Extensible]], then set obj.[[Extensible]] to
true . - Return obj.
Within this specification, exotic objects are created in
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:
Assert :Type (O) is Object.Assert :IsPropertyKey (P) istrue .- 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
Assert :IsPropertyKey (P) istrue .- Let O be ?
ToObject (V). - Return ? O.[[Get]](P, V).
7.3.4 Set ( O, P, V, Throw )
The abstract operation
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:
Assert :Type (O) is Object.Assert :IsPropertyKey (P) istrue .- Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]:
true , [[Enumerable]]:true , [[Configurable]]:true }. - Return ? O.[[DefineOwnProperty]](P, newDesc).
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
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:
Assert :Type (O) is Object.Assert :IsPropertyKey (P) istrue .- Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]:
true , [[Enumerable]]:false , [[Configurable]]:true }. - Return ? O.[[DefineOwnProperty]](P, newDesc).
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
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
Assert :Type (O) is Object.Assert :IsPropertyKey (P) istrue .- Let success be ?
CreateDataProperty (O, P, V). - If success is
false , throw aTypeError exception. - Return success.
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
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
Assert :Type (O) is Object.Assert :IsPropertyKey (P) istrue .- Let success be ? O.[[DefineOwnProperty]](P, desc).
- If success is
false , throw aTypeError exception. - 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:
Assert :Type (O) is Object.Assert :IsPropertyKey (P) istrue .- Let success be ? O.[[Delete]](P).
- If success is
false , throw aTypeError exception. - Return success.
7.3.10 GetMethod ( V, P )
The abstract operation GetMethod is used to get the value of a specific property of an
Assert :IsPropertyKey (P) istrue .- Let func be ?
GetV (V, P). - If func is either
undefined ornull , returnundefined . - If
IsCallable (func) isfalse , throw aTypeError exception. - 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:
Assert :Type (O) is Object.Assert :IsPropertyKey (P) istrue .- 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:
Assert :Type (O) is Object.Assert :IsPropertyKey (P) istrue .- Let desc be ? O.[[GetOwnProperty]](P).
- If desc is
undefined , returnfalse . - Return
true .
7.3.13 Call ( F, V [ , argumentsList ] )
The abstract operation Call is used to call the [[Call]] internal method of a
- If argumentsList is not present, set argumentsList to a new empty
List . - If
IsCallable (F) isfalse , throw aTypeError exception. - 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
- If newTarget is not present, set newTarget to F.
- If argumentsList is not present, set argumentsList to a new empty
List . Assert :IsConstructor (F) istrue .Assert :IsConstructor (newTarget) istrue .- Return ? F.[[Construct]](argumentsList, newTarget).
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:
Assert :Type (O) is Object.Assert : level is eithersealed orfrozen .- Let status be ? O.[[PreventExtensions]]().
- If status is
false , returnfalse . - Let keys be ? O.[[OwnPropertyKeys]]().
- If level is
sealed , then- For each element k of keys, do
- Perform ?
DefinePropertyOrThrow (O, k, PropertyDescriptor { [[Configurable]]:false }).
- Perform ?
- For each element k of keys, do
- Else,
Assert : level isfrozen .- For each element k of keys, do
- Let currentDesc be ? O.[[GetOwnProperty]](k).
- If currentDesc is not
undefined , then- If
IsAccessorDescriptor (currentDesc) istrue , then- Let desc be the PropertyDescriptor { [[Configurable]]:
false }.
- Let desc be the PropertyDescriptor { [[Configurable]]:
- Else,
- Let desc be the PropertyDescriptor { [[Configurable]]:
false , [[Writable]]:false }.
- Let desc be the PropertyDescriptor { [[Configurable]]:
- Perform ?
DefinePropertyOrThrow (O, k, desc).
- If
- 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:
Assert :Type (O) is Object.Assert : level is eithersealed orfrozen .- Let extensible be ?
IsExtensible (O). - If extensible is
true , returnfalse . - NOTE: If the object is extensible, none of its properties are examined.
- Let keys be ? O.[[OwnPropertyKeys]]().
- For each element k of keys, do
- Let currentDesc be ? O.[[GetOwnProperty]](k).
- If currentDesc is not
undefined , then- If currentDesc.[[Configurable]] is
true , returnfalse . - If level is
frozen andIsDataDescriptor (currentDesc) istrue , then- If currentDesc.[[Writable]] is
true , returnfalse .
- If currentDesc.[[Writable]] is
- If currentDesc.[[Configurable]] is
- Return
true .
7.3.17 CreateArrayFromList ( elements )
The abstract operation CreateArrayFromList is used to create an Array object whose elements are provided by a
Assert : elements is aList whose elements are all ECMAScript language values.- Let array be !
ArrayCreate (0). - Let n be 0.
- For each element e of elements, do
- Perform !
CreateDataPropertyOrThrow (array, !ToString (n), e). Set n to n + 1.
- Perform !
- Return array.
7.3.18 LengthOfArrayLike ( obj )
The abstract operation LengthOfArrayLike returns the value of the
An array-like object is any object for which this operation returns an
7.3.19 CreateListFromArrayLike ( obj [ , elementTypes ] )
The abstract operation CreateListFromArrayLike is used to create a
- If elementTypes is not present, set elementTypes to « Undefined, Null, Boolean, String, Symbol, Number, BigInt, Object ».
- If
Type (obj) is not Object, throw aTypeError exception. - Let len be ?
LengthOfArrayLike (obj). - Let list be a new empty
List . - Let index be 0.
- Repeat, while index < len
- Return list.
7.3.20 Invoke ( V, P [ , argumentsList ] )
The abstract operation Invoke is used to call a method property of an
Assert :IsPropertyKey (P) istrue .- If argumentsList is not present, set argumentsList to a new empty
List . - Let func be ?
GetV (V, P). - 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
- If
IsCallable (C) isfalse , returnfalse . - If C has a [[BoundTargetFunction]] internal slot, then
- Let BC be C.[[BoundTargetFunction]].
- Return ?
InstanceofOperator (O, BC).
- If
Type (O) is not Object, returnfalse . - Let P be ?
Get (C,"prototype" ). - If
Type (P) is not Object, throw aTypeError exception. - Repeat,
7.3.22 SpeciesConstructor ( O, defaultConstructor )
The abstract operation SpeciesConstructor is used to retrieve the
Assert :Type (O) is Object.- Let C be ?
Get (O,"constructor" ). - If C is
undefined , return defaultConstructor. - If
Type (C) is not Object, throw aTypeError exception. - Let S be ?
Get (C, @@species). - If S is either
undefined ornull , return defaultConstructor. - If
IsConstructor (S) istrue , return S. - 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 (
Assert :Type (O) is Object.- Let ownKeys be ? O.[[OwnPropertyKeys]]().
- Let properties be a new empty
List . - For each element key of ownKeys in
List order, do- If
Type (key) is String, then- Let desc be ? O.[[GetOwnProperty]](key).
- If desc is not
undefined and desc.[[Enumerable]] istrue , then- If kind is
key , append key to properties. - Else,
- Let value be ?
Get (O, key). - If kind is
value , append value to properties. - Else,
Assert : kind iskey+value .- Let entry be !
CreateArrayFromList (« key, value »). - Append entry to properties.
- Let value be ?
- If kind is
- If
- Return properties.
7.3.24 GetFunctionRealm ( obj )
The abstract operation GetFunctionRealm with argument obj performs the following steps:
Assert : !IsCallable (obj) istrue .- If obj has a [[Realm]] internal slot, then
- Return obj.[[Realm]].
- If obj is a
bound function exotic object , then- Let target be obj.[[BoundTargetFunction]].
- Return ? GetFunctionRealm(target).
- If obj is a
Proxy exotic object , then- If obj.[[ProxyHandler]] is
null , throw aTypeError exception. - Let proxyTarget be obj.[[ProxyTarget]].
- Return ? GetFunctionRealm(proxyTarget).
- If obj.[[ProxyHandler]] is
- Return
the current Realm Record .
Step 5 will only be reached if obj is a non-standard function
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:
Assert :Type (target) is Object.Assert : excludedItems is aList of property keys.- If source is
undefined ornull , return target. - Let from be !
ToObject (source). - Let keys be ? from.[[OwnPropertyKeys]]().
- For each element nextKey of keys in
List order, do- Let excluded be
false . - For each element e of excludedItems in
List order, do - If excluded is
false , then- Let desc be ? from.[[GetOwnProperty]](nextKey).
- If desc is not
undefined and desc.[[Enumerable]] istrue , then- Let propValue be ?
Get (from, nextKey). - Perform !
CreateDataPropertyOrThrow (target, nextKey, propValue).
- Let propValue be ?
- Let excluded be
- Return target.
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 (
7.4.1 GetIterator ( obj [ , hint [ , method ] ] )
The abstract operation GetIterator with argument obj and optional arguments hint and method performs the following steps:
- If hint is not present, set hint to
sync . Assert : hint is eithersync orasync .- If method is not present, then
- If hint is
async , thenSet method to ?GetMethod (obj, @@asyncIterator).- If method is
undefined , then- Let syncMethod be ?
GetMethod (obj, @@iterator). - Let syncIteratorRecord be ? GetIterator(obj,
sync , syncMethod). - Return !
CreateAsyncFromSyncIterator (syncIteratorRecord).
- Let syncMethod be ?
- Otherwise, set method to ?
GetMethod (obj, @@iterator).
- If hint is
- Let iterator be ?
Call (method, obj). - If
Type (iterator) is not Object, throw aTypeError exception. - Let nextMethod be ?
GetV (iterator,"next" ). - Let iteratorRecord be the
Record { [[Iterator]]: iterator, [[NextMethod]]: nextMethod, [[Done]]:false }. - Return iteratorRecord.
7.4.2 IteratorNext ( iteratorRecord [ , value ] )
The abstract operation IteratorNext with argument iteratorRecord and optional argument value performs the following steps:
7.4.3 IteratorComplete ( iterResult )
7.4.4 IteratorValue ( iterResult )
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
- Let result be ?
IteratorNext (iteratorRecord). - Let done be ?
IteratorComplete (result). - If done is
true , returnfalse . - 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:
Assert :Type (iteratorRecord.[[Iterator]]) is Object.Assert : completion is aCompletion Record .- Let iterator be iteratorRecord.[[Iterator]].
- Let return be ?
GetMethod (iterator,"return" ). - If return is
undefined , returnCompletion (completion). - Let innerResult be
Call (return, iterator). - If completion.[[Type]] is
throw , returnCompletion (completion). - If innerResult.[[Type]] is
throw , returnCompletion (innerResult). - If
Type (innerResult.[[Value]]) is not Object, throw aTypeError exception. - 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:
Assert :Type (iteratorRecord.[[Iterator]]) is Object.Assert : completion is aCompletion Record .- Let iterator be iteratorRecord.[[Iterator]].
- Let return be ?
GetMethod (iterator,"return" ). - If return is
undefined , returnCompletion (completion). - Let innerResult be
Call (return, iterator). - If innerResult.[[Type]] is
normal , set innerResult toAwait (innerResult.[[Value]]). - If completion.[[Type]] is
throw , returnCompletion (completion). - If innerResult.[[Type]] is
throw , returnCompletion (innerResult). - If
Type (innerResult.[[Value]]) is not Object, throw aTypeError exception. - 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:
Assert :Type (done) is Boolean.- Let obj be
OrdinaryObjectCreate (%Object.prototype% ). - Perform !
CreateDataPropertyOrThrow (obj,"value" , value). - Perform !
CreateDataPropertyOrThrow (obj,"done" , done). - Return obj.
7.4.9 CreateListIteratorRecord ( list )
The abstract operation CreateListIteratorRecord with argument list creates an Iterator (
- Let iterator be
OrdinaryObjectCreate (%IteratorPrototype% , « [[IteratedList]], [[ListNextIndex]] »). Set iterator.[[IteratedList]] to list.Set iterator.[[ListNextIndex]] to 0.- Let steps be the algorithm steps defined in
ListIteratorNext Functions . - Let next be !
CreateBuiltinFunction (steps, « »). - Return
Record { [[Iterator]]: iterator, [[NextMethod]]: next, [[Done]]:false }.
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:
- Let O be the
this value. Assert :Type (O) is Object.Assert : O has an [[IteratedList]] internal slot.- Let list be O.[[IteratedList]].
- Let index be O.[[ListNextIndex]].
- Let len be the number of elements of list.
- If index ≥ len, then
- Return
CreateIterResultObject (undefined ,true ).
- Return
Set O.[[ListNextIndex]] to index + 1.- Return
CreateIterResultObject (list[index],false ).
The