7 Abstract Operations
These operations are not a part of the ECMAScript language; they are defined here 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 argument input and optional argument preferredType. It converts its input argument to a non-Object
Assert : input is anECMAScript language value .- If
Type (input) is Object, then- Let exoticToPrim be ?
GetMethod (input, @@toPrimitive). - If exoticToPrim is not
undefined , then - If preferredType is not present, let preferredType be
number . - Return ?
OrdinaryToPrimitive (input, preferredType).
- Let exoticToPrim be ?
- Return input.
When ToPrimitive is called with no hint, then it generally behaves as if the hint were
7.1.1.1 OrdinaryToPrimitive ( O, hint )
The abstract operation OrdinaryToPrimitive takes arguments O and hint. It performs the following steps when called:
Assert :Type (O) is Object.Assert : hint is eitherstring ornumber .- If hint is
string , then- Let methodNames be «
"toString" ,"valueOf" ».
- Let methodNames be «
- Else,
- Let methodNames be «
"valueOf" ,"toString" ».
- Let methodNames be «
- For each element name of methodNames, 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 takes argument argument. It 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 0), return |
| Symbol |
Return |
| BigInt |
If argument is |
| Object |
Return An alternate algorithm related to the [[IsHTMLDDA]] internal slot is mandated in section |
7.1.3 ToNumeric ( value )
The abstract operation ToNumeric takes argument value. It returns value converted to a Number or a BigInt. It performs the following steps when called:
- Let primValue be ?
ToPrimitive (value,number ). - If
Type (primValue) is BigInt, return primValue. - Return ?
ToNumber (primValue).
7.1.4 ToNumber ( argument )
The abstract operation ToNumber takes argument argument. It 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 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 1010000 (a value so large that it will round toStrUnsignedDecimalLiteral ::: Infinity +∞ 𝔽). -
The MV of
is the MV of the firstStrUnsignedDecimalLiteral ::: DecimalDigits . DecimalDigits DecimalDigits plus (the MV of the secondDecimalDigits times 10-n), where n is the number of code points in the secondDecimalDigits . -
The MV of
is the MV ofStrUnsignedDecimalLiteral ::: DecimalDigits . ExponentPart DecimalDigits times 10e, 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 10e, where n is 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 the number of code points inDecimalDigits . -
The MV of
is the MV ofStrUnsignedDecimalLiteral ::: . DecimalDigits ExponentPart DecimalDigits times 10e - n, where n is the number of code points inDecimalDigits and e is the MV ofExponentPart . -
The MV of
is the MV ofStrUnsignedDecimalLiteral ::: DecimalDigits ExponentPart DecimalDigits times 10e, 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 non-zero digit to its left and there is a non-zero digit, not in the
ExponentPart , to its right.
7.1.5 ToIntegerOrInfinity ( argument )
The abstract operation ToIntegerOrInfinity takes argument argument. It converts argument to an
7.1.6 ToInt32 ( argument )
The abstract operation ToInt32 takes argument argument. It converts argument to one of 232
- Let number be ?
ToNumber (argument). - If number is
NaN ,+0 𝔽,-0 𝔽,+∞ 𝔽, or-∞ 𝔽, return+0 𝔽. - Let int be the
mathematical 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 the same value as 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 takes argument argument. It converts argument to one of 232
- Let number be ?
ToNumber (argument). - If number is
NaN ,+0 𝔽,-0 𝔽,+∞ 𝔽, or-∞ 𝔽, return+0 𝔽. - Let int be the
mathematical 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 andToInt32 . - 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 the same value as 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 takes argument argument. It converts argument to one of 216
- Let number be ?
ToNumber (argument). - If number is
NaN ,+0 𝔽,-0 𝔽,+∞ 𝔽, or-∞ 𝔽, return+0 𝔽. - Let int be the
mathematical 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 takes argument argument. It converts argument to one of 216
- Let number be ?
ToNumber (argument). - If number is
NaN ,+0 𝔽,-0 𝔽,+∞ 𝔽, or-∞ 𝔽, return+0 𝔽. - Let int be the
mathematical value that is the same sign as number and whose magnitude isfloor (abs (ℝ(number))). - Let int16bit be int
modulo 216. - Return 𝔽(int16bit).
7.1.10 ToInt8 ( argument )
The abstract operation ToInt8 takes argument argument. It converts argument to one of 28
- Let number be ?
ToNumber (argument). - If number is
NaN ,+0 𝔽,-0 𝔽,+∞ 𝔽, or-∞ 𝔽, return+0 𝔽. - Let int be the
mathematical 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 takes argument argument. It converts argument to one of 28
- Let number be ?
ToNumber (argument). - If number is
NaN ,+0 𝔽,-0 𝔽,+∞ 𝔽, or-∞ 𝔽, return+0 𝔽. - Let int be the
mathematical 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 takes argument argument. It converts argument to one of 28
Unlike the other ECMAScript Math.round which does “round half up” tie-breaking.
7.1.13 ToBigInt ( argument )
The abstract operation ToBigInt takes argument argument. It converts argument to a BigInt value, or throws if an implicit conversion from Number would be required. It performs the following steps when called:
- Let prim be ?
ToPrimitive (argument,number ). - Return the value that prim corresponds to in
Table 13 .
|
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 )
The abstract operation ToBigInt64 takes argument argument. It converts argument to one of 264 BigInt values in the range ℤ(-263) through ℤ(263-1), inclusive. It performs the following steps when called:
7.1.16 ToBigUint64 ( argument )
The abstract operation ToBigUint64 takes argument argument. It converts argument to one of 264 BigInt values in the range
7.1.17 ToString ( argument )
The abstract operation ToString takes argument argument. It 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 takes argument argument. It 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 takes argument argument. It converts argument to a value that can be used as a property key. It performs the following steps when called:
- Let key be ?
ToPrimitive (argument,string ). - If
Type (key) is Symbol, then- Return key.
- Return !
ToString (key).
7.1.20 ToLength ( argument )
The abstract operation ToLength takes argument argument. It converts argument to an
- Let len be ?
ToIntegerOrInfinity (argument). - If len ≤ 0, return
+0 𝔽. - Return 𝔽(
min (len, 253 - 1)).
7.1.21 CanonicalNumericIndexString ( argument )
The abstract operation CanonicalNumericIndexString takes argument argument. It 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 takes argument value. It returns value argument converted to a non-negative
- If value is
undefined , then- Return 0.
- Else,
- Let integerIndex be 𝔽(?
ToIntegerOrInfinity (value)). - If integerIndex <
+0 𝔽, throw aRangeError exception. - Let index be !
ToLength (integerIndex). - If !
SameValue (integerIndex, index) isfalse , throw aRangeError exception. - Return ℝ(index).
- Let integerIndex be 𝔽(?
7.2 Testing and Comparison Operations
7.2.1 RequireObjectCoercible ( argument )
The abstract operation RequireObjectCoercible takes argument argument. It 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 argument argument. It performs the following steps when called:
- 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 takes argument argument (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 takes argument argument (an
- If
Type (argument) is not Object, returnfalse . - If argument has a [[Construct]] internal method, return
true . - Return
false .
7.2.5 IsExtensible ( O )
The abstract operation IsExtensible takes argument O (an Object) and returns a completion record which, if its [[Type]] is
7.2.6 IsIntegralNumber ( argument )
The abstract operation IsIntegralNumber takes argument argument. It determines if argument is a finite
7.2.7 IsPropertyKey ( argument )
The abstract operation IsPropertyKey takes argument argument (an
7.2.8 IsRegExp ( argument )
The abstract operation IsRegExp takes argument argument. It performs the following steps when called:
7.2.9 IsStringPrefix ( p, q )
The abstract operation IsStringPrefix takes arguments p (a String) and q (a String). It determines if p is a prefix of q. It performs the following steps when called:
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.10 SameValue ( x, y )
The abstract operation SameValue takes arguments x (an
- 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.11 SameValueZero ( x, y )
The abstract operation SameValueZero takes arguments x (an
- 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.12 SameValueNonNumeric ( x, y )
The abstract operation SameValueNonNumeric takes arguments x (an
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.13 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,number ). - Let py be ?
ToPrimitive (y,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,number ). - Let px be ?
ToPrimitive (x,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 non-negative
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 ℝ(nx) < ℝ(ny), return
true ; otherwise returnfalse .
- If
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.14 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 . - NOTE: This step is replaced in section
B.3.7.2 . - 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 comparison ?ToPrimitive (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 ℝ(x) = ℝ(y), return
true ; otherwise returnfalse .
- If x or y are any of
- Return
false .
7.2.15 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 takes argument internalSlotsList. It 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. It performs the following steps when called:
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 in10.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]], 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 takes arguments O (an Object) and P (a property key). It is used to retrieve the value of a specific property of an object. It performs the following steps when called:
Assert :Type (O) is Object.Assert :IsPropertyKey (P) istrue .- Return ? O.[[Get]](P, O).
7.3.3 GetV ( V, P )
The abstract operation GetV takes arguments V (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 takes arguments O (an Object), P (a property key), and V (an
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 takes arguments O (an Object), P (a property key), and V (an
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 takes arguments O (an Object), P (a property key), and V (an
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 takes arguments O (an Object), P (a property key), and desc (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 takes arguments O (an Object) and P (a property key). It is used to remove a specific own property of an object. It throws an exception if the property is not configurable. It performs the following steps when called:
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 takes arguments V (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 takes arguments O (an Object) and P (a property key) and returns a completion record which, if its [[Type]] is
Assert :Type (O) is Object.Assert :IsPropertyKey (P) istrue .- Return ? O.[[HasProperty]](P).
7.3.12 HasOwnProperty ( O, P )
The abstract operation HasOwnProperty takes arguments O (an Object) and P (a property key) and returns a completion record which, if its [[Type]] is
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 takes arguments F (an
- 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 takes argument F (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 takes arguments O and level. It is used to fix the set of own properties of an object. It performs the following steps when called:
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 takes arguments O and level. It is used to determine if the set of own properties of an object are fixed. It performs the following steps when called:
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 takes argument elements (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 takes argument obj. It 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 takes argument obj and optional argument elementTypes (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 takes arguments V (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 takes arguments C (an
- 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 takes arguments O (an Object) and defaultConstructor (a
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 )
The abstract operation EnumerableOwnPropertyNames takes arguments O (an Object) and kind (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, 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 takes argument obj. It performs the following steps when called:
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
7.3.25 CopyDataProperties ( target, source, excludedItems )
The abstract operation CopyDataProperties takes arguments target, source, and excludedItems. It performs the following steps when called:
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, do
- Let excluded be
false . - For each element e of excludedItems, 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 takes argument obj and optional arguments hint and method. It performs the following steps when called:
- 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 takes argument iteratorRecord and optional argument value. It performs the following steps when called:
7.4.3 IteratorComplete ( iterResult )
7.4.4 IteratorValue ( iterResult )
7.4.5 IteratorStep ( iteratorRecord )
The abstract operation IteratorStep takes argument iteratorRecord. It 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 takes arguments iteratorRecord and completion. It is used to notify an iterator that it should perform any actions it would normally perform when it has reached its completed state. It performs the following steps when called:
Assert :Type (iteratorRecord.[[Iterator]]) is Object.Assert : completion is aCompletion Record .- Let iterator be iteratorRecord.[[Iterator]].
- Let innerResult be
GetMethod (iterator,"return" ). - If innerResult.[[Type]] is
normal , then- Let return be innerResult.[[Value]].
- If return is
undefined , returnCompletion (completion). Set innerResult toCall (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 takes arguments iteratorRecord and completion. It is used to notify an async iterator that it should perform any actions it would normally perform when it has reached its completed state. It performs the following steps when called:
Assert :Type (iteratorRecord.[[Iterator]]) is Object.Assert : completion is aCompletion Record .- Let iterator be iteratorRecord.[[Iterator]].
- Let innerResult be
GetMethod (iterator,"return" ). - If innerResult.[[Type]] is
normal , then- Let return be innerResult.[[Value]].
- If return is
undefined , returnCompletion (completion). Set innerResult toCall (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 takes arguments value and done. It creates an object that supports the IteratorResult interface. It performs the following steps when called:
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 takes argument list. It creates an Iterator (
- Let closure be a new
Abstract Closure with no parameters that captures list and performs the following steps when called:- For each element E of list, do
- Perform ?
Yield (E).
- Perform ?
- Return
undefined .
- For each element E of list, do
- Let iterator be !
CreateIteratorFromClosure (closure,empty ,%IteratorPrototype% ). - Return
Record { [[Iterator]]: iterator, [[NextMethod]]:%GeneratorFunction.prototype.prototype.next% , [[Done]]:false }.
The list iterator object is never directly accessible to ECMAScript code.
7.4.10 IterableToList ( items [ , method ] )
The abstract operation IterableToList takes argument items and optional argument method. It performs the following steps when called:
- If method is present, then
- Let iteratorRecord be ?
GetIterator (items,sync , method).
- Let iteratorRecord be ?
- Else,
- Let iteratorRecord be ?
GetIterator (items,sync ).
- Let iteratorRecord be ?
- Let values be a new empty
List . - Let next be
true . - Repeat, while next is not
false ,Set next to ?IteratorStep (iteratorRecord).- If next is not
false , then- Let nextValue be ?
IteratorValue (next). - Append nextValue to the end of the
List values.
- Let nextValue be ?
- Return values.