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 type conversion as needed. To clarify the semantics of certain constructs it is useful to define a set of conversion
The BigInt type has no implicit conversions in the ECMAScript language; programmers must call BigInt explicitly to convert values from other types.
7.1.1 ToPrimitive ( input [ , preferredType ] )
The abstract operation ToPrimitive takes argument input (an
- 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 without a hint, then it generally behaves as if the hint were
7.1.1.1 OrdinaryToPrimitive ( O, hint )
The abstract operation OrdinaryToPrimitive takes arguments O (an Object) and hint (
- 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 and returns a Boolean. It converts argument to a value of type Boolean according to
| Argument Type | 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 and returns either a
- 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 and returns either a
| Argument Type | Result |
|---|---|
| Undefined |
Return |
| Null |
Return |
| Boolean |
If argument is |
| Number | Return argument (no conversion). |
| String |
Return ! |
| Symbol |
Throw a |
| BigInt |
Throw a |
| Object |
Apply the following steps:
|
7.1.4.1 ToNumber Applied to the String Type
The abstract operation
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 StringToNumber ( str )
The abstract operation StringToNumber takes argument str (a String) and returns a Number. It performs the following steps when called:
- Let text be
StringToCodePoints (str). - Let literal be
ParseText (text,StringNumericLiteral ). - If literal is a
List of errors, returnNaN . - Return
StringNumericValue of literal.
7.1.4.1.2 Runtime Semantics: StringNumericValue
The
The conversion of a
It is defined piecewise over the following productions:
- Return
+0 𝔽.
- Return StringNumericValue of
StrNumericLiteral .
- Return 𝔽(MV of
NonDecimalIntegerLiteral ).
- Let a be StringNumericValue of
StrUnsignedDecimalLiteral . - If a is
+0 𝔽, return-0 𝔽. - Return -a.
- Return
+∞ 𝔽.
- Let a be MV of the first
DecimalDigits . - If the second
DecimalDigits is present, then- Let b be MV of the second
DecimalDigits . - Let n be the number of code points in the second
DecimalDigits .
- Let b be MV of the second
- Else,
- Let b be 0.
- Let n be 0.
- If
ExponentPart is present, let e be MV ofExponentPart . Otherwise, let e be 0. - Return
RoundMVResult ((a + (b × 10-n)) × 10e).
- Let b be MV of
DecimalDigits . - If
ExponentPart is present, let e be MV ofExponentPart . Otherwise, let e be 0. - Let n be the number of code points in
DecimalDigits . - Return
RoundMVResult (b × 10e - n).
- Let a be MV of
DecimalDigits . - If
ExponentPart is present, let e be MV ofExponentPart . Otherwise, let e be 0. - Return
RoundMVResult (a × 10e).
7.1.4.1.3 RoundMVResult ( n )
The abstract operation RoundMVResult takes argument n (a
- If the decimal representation of n has 20 or fewer significant digits, return 𝔽(n).
- Let option1 be the
mathematical value denoted by the result of replacing each significant digit in the decimal representation of n after the 20th with a 0 digit. - Let option2 be the
mathematical value denoted by the result of replacing each significant digit in the decimal representation of n after the 20th with a 0 digit and then incrementing it at the 20th position (with carrying as necessary). - Let chosen be an
implementation-defined choice of either option1 or option2. - Return 𝔽(chosen).
7.1.5 ToIntegerOrInfinity ( argument )
The abstract operation ToIntegerOrInfinity takes argument argument (an
7.1.6 ToInt32 ( argument )
The abstract operation ToInt32 takes argument argument and returns either a
- Let number be ?
ToNumber (argument). - If number is
NaN ,+0 𝔽,-0 𝔽,+∞ 𝔽, or-∞ 𝔽, return+0 𝔽. - Let int be the
mathematical value whose sign is the sign of 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 and returns either a
- Let number be ?
ToNumber (argument). - If number is
NaN ,+0 𝔽,-0 𝔽,+∞ 𝔽, or-∞ 𝔽, return+0 𝔽. - Let int be the
mathematical value whose sign is the sign of 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 and returns either a
- Let number be ?
ToNumber (argument). - If number is
NaN ,+0 𝔽,-0 𝔽,+∞ 𝔽, or-∞ 𝔽, return+0 𝔽. - Let int be the
mathematical value whose sign is the sign of 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 and returns either a
- Let number be ?
ToNumber (argument). - If number is
NaN ,+0 𝔽,-0 𝔽,+∞ 𝔽, or-∞ 𝔽, return+0 𝔽. - Let int be the
mathematical value whose sign is the sign of 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 and returns either a
- Let number be ?
ToNumber (argument). - If number is
NaN ,+0 𝔽,-0 𝔽,+∞ 𝔽, or-∞ 𝔽, return+0 𝔽. - Let int be the
mathematical value whose sign is the sign of 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 and returns either a
- Let number be ?
ToNumber (argument). - If number is
NaN ,+0 𝔽,-0 𝔽,+∞ 𝔽, or-∞ 𝔽, return+0 𝔽. - Let int be the
mathematical value whose sign is the sign of 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 and returns either a
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 and returns either a
- Let prim be ?
ToPrimitive (argument,number ). - Return the value that prim corresponds to in
Table 14 .
| Argument Type | 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 ( str )
The abstract operation StringToBigInt takes argument str (a String) and returns a BigInt or
- Let text be
StringToCodePoints (str). - Let literal be
ParseText (text,StringIntegerLiteral ). - If literal is a
List of errors, returnundefined . - Let mv be the MV of literal.
Assert : mv is aninteger .- Return ℤ(mv).
7.1.14.1 StringIntegerLiteral Grammar
Syntax
7.1.14.2 Runtime Semantics: MV
-
The MV of
is 0.StringIntegerLiteral ::: StrWhiteSpace opt -
The MV of
is the MV ofStringIntegerLiteral ::: StrWhiteSpace opt StrIntegerLiteral StrWhiteSpace opt StrIntegerLiteral .
7.1.15 ToBigInt64 ( argument )
The abstract operation ToBigInt64 takes argument argument and returns either a
7.1.16 ToBigUint64 ( argument )
The abstract operation ToBigUint64 takes argument argument and returns either a
7.1.17 ToString ( argument )
The abstract operation ToString takes argument argument and returns either a
| Argument Type | 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 and returns either a
| Argument Type | 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 and returns either a
- 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 (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 (a String) and returns a Number or
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 (an
- If value is
undefined , then- Return 0.
- Else,
- Let integer be ?
ToIntegerOrInfinity (value). - Let clamped be !
ToLength (𝔽(integer)). - If
SameValue (𝔽(integer), clamped) isfalse , throw aRangeError exception. Assert : 0 ≤ integer ≤ 253 - 1.- Return integer.
- Let integer be ?
7.2 Testing and Comparison Operations
7.2.1 RequireObjectCoercible ( argument )
The abstract operation RequireObjectCoercible takes argument argument and returns either a
| Argument Type | 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 and returns either a
- 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 either a
- Return ?
O.[[IsExtensible]] ().
7.2.6 IsIntegralNumber ( argument )
The abstract operation IsIntegralNumber takes argument argument and returns a Boolean. 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 and returns either a
7.2.9 IsStringPrefix ( p, q )
The abstract operation IsStringPrefix takes arguments p (a String) and q (a String) and returns a Boolean. It determines if p is a prefix of q. It performs the following steps when called:
- If
StringIndexOf (q, p, 0) is 0, returntrue . - Else, return
false .
Any String is a prefix of itself.
7.2.10 Static Semantics: IsStringWellFormedUnicode ( string )
The abstract operation IsStringWellFormedUnicode takes argument string (a String) and returns a Boolean. It interprets string as a sequence of UTF-16 encoded code points, as described in
- Let strLen be the number of code units in string.
- Let k be 0.
- Repeat, while k ≠ strLen,
- Let cp be
CodePointAt (string, k). - If cp.[[IsUnpairedSurrogate]] is
true , returnfalse . - Set k to k + cp.[[CodeUnitCount]].
- Let cp be
- Return
true .
7.2.11 SameValue ( x, y )
The abstract operation SameValue takes arguments x (an
- If
Type (x) is different fromType (y), returnfalse . - If
Type (x) is Number, then- Return
Number::sameValue (x, y).
- Return
- If
Type (x) is BigInt, then- Return
BigInt::sameValue (x, y).
- Return
- Return
SameValueNonNumeric (x, y).
This algorithm differs from the
7.2.12 SameValueZero ( x, y )
The abstract operation SameValueZero takes arguments x (an
- If
Type (x) is different fromType (y), returnfalse . - If
Type (x) is Number, then- Return
Number::sameValueZero (x, y).
- Return
- If
Type (x) is BigInt, then- Return
BigInt::sameValueZero (x, y).
- Return
- Return
SameValueNonNumeric (x, y).
SameValueZero differs from
7.2.13 SameValueNonNumeric ( x, y )
The abstract operation SameValueNonNumeric takes arguments x (an
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 IsLessThan ( x, y, LeftFirst )
The abstract operation IsLessThan takes arguments x (an
- 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
undefined , 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
undefined , 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), then- If
Type (nx) is Number, then- Return
Number::lessThan (nx, ny).
- Return
- Else,
Assert :Type (nx) is BigInt.- Return
BigInt::lessThan (nx, ny).
- If
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.15 IsLooselyEqual ( x, y )
The abstract operation IsLooselyEqual takes arguments x (an
- If
Type (x) is the same asType (y), then- Return
IsStrictlyEqual (x, y).
- Return
- 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.6.2 . - If
Type (x) is Number andType (y) is String, return ! IsLooselyEqual(x, !ToNumber (y)). - If
Type (x) is String andType (y) is Number, return ! IsLooselyEqual(!ToNumber (x), y). - If
Type (x) is BigInt andType (y) is String, then- Let n be
StringToBigInt (y). - If n is
undefined , returnfalse . - Return ! IsLooselyEqual(x, n).
- Let n be
- If
Type (x) is String andType (y) is BigInt, return ! IsLooselyEqual(y, x). - If
Type (x) is Boolean, return ! IsLooselyEqual(!ToNumber (x), y). - If
Type (y) is Boolean, return ! IsLooselyEqual(x, !ToNumber (y)). - If
Type (x) is either String, Number, BigInt, or Symbol andType (y) is Object, return ! IsLooselyEqual(x, ?ToPrimitive (y)). - If
Type (x) is Object andType (y) is either String, Number, BigInt, or Symbol, return ! IsLooselyEqual(?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.16 IsStrictlyEqual ( x, y )
The abstract operation IsStrictlyEqual takes arguments x (an
- If
Type (x) is different fromType (y), returnfalse . - If
Type (x) is Number, then- Return
Number::equal (x, y).
- Return
- If
Type (x) is BigInt, then- Return
BigInt::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 (a
- Let obj be a newly created object with an internal slot for each name in internalSlotsList.
- Set obj's essential internal methods to the default
ordinary 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,
7.3.2 Get ( O, P )
The abstract operation Get takes arguments O (an Object) and P (a
- Return ?
O.[[Get]] (P, O).
7.3.3 GetV ( V, P )
The abstract operation GetV takes arguments V (an
- Let O be ?
ToObject (V). - Return ?
O.[[Get]] (P, V).
7.3.4 Set ( O, P, V, Throw )
The abstract operation Set takes arguments O (an Object), P (a
- Let success be ?
O.[[Set]] (P, V, O). - If success is
false and Throw istrue , throw aTypeError exception. - Return
unused .
7.3.5 CreateDataProperty ( O, P, V )
The abstract operation CreateDataProperty takes arguments O (an Object), P (a
- 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
Assert : O is an ordinary, extensible object with no non-configurable properties.- Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]:
true , [[Enumerable]]:false , [[Configurable]]:true }. - Perform ! O.[[DefineOwnProperty]](P, newDesc).
- Return
unused .
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
- 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 CreateNonEnumerableDataPropertyOrThrow ( O, P, V )
The abstract operation CreateNonEnumerableDataPropertyOrThrow takes arguments O (an Object), P (a
Assert : O is an ordinary, extensible object with no non-configurable properties.- Let newDesc be the PropertyDescriptor { [[Value]]: V, [[Writable]]:
true , [[Enumerable]]:false , [[Configurable]]:true }. - Perform !
DefinePropertyOrThrow (O, P, newDesc). - Return
unused .
This abstract operation creates a property whose attributes are set to the same defaults used for properties created by the ECMAScript language assignment operator except it is not enumerable. 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.9 DefinePropertyOrThrow ( O, P, desc )
The abstract operation DefinePropertyOrThrow takes arguments O (an Object), P (a
- Let success be ?
O.[[DefineOwnProperty]] (P, desc). - If success is
false , throw aTypeError exception. - Return
unused .
7.3.10 DeletePropertyOrThrow ( O, P )
The abstract operation DeletePropertyOrThrow takes arguments O (an Object) and P (a
- Let success be ?
O.[[Delete]] (P). - If success is
false , throw aTypeError exception. - Return
unused .
7.3.11 GetMethod ( V, P )
The abstract operation GetMethod takes arguments V (an
- Let func be ?
GetV (V, P). - If func is either
undefined ornull , returnundefined . - If
IsCallable (func) isfalse , throw aTypeError exception. - Return func.
7.3.12 HasProperty ( O, P )
The abstract operation HasProperty takes arguments O (an Object) and P (a
- Return ?
O.[[HasProperty]] (P).
7.3.13 HasOwnProperty ( O, P )
The abstract operation HasOwnProperty takes arguments O (an Object) and P (a
- Let desc be ?
O.[[GetOwnProperty]] (P). - If desc is
undefined , returnfalse . - Return
true .
7.3.14 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.15 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 . - Return ?
F.[[Construct]] (argumentsList, newTarget).
If newTarget is not present, this operation is equivalent to: new F(...argumentsList)
7.3.16 SetIntegrityLevel ( O, level )
The abstract operation SetIntegrityLevel takes arguments O (an Object) and level (
- 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
- Let currentDesc be ?
- Return
true .
7.3.17 TestIntegrityLevel ( O, level )
The abstract operation TestIntegrityLevel takes arguments O (an Object) and level (
- 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
- Let currentDesc be ?
- Return
true .
7.3.18 CreateArrayFromList ( elements )
The abstract operation CreateArrayFromList takes argument elements (a
- 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.19 LengthOfArrayLike ( obj )
The abstract operation LengthOfArrayLike takes argument obj (an Object) and returns either a
An array-like object is any object for which this operation returns a
7.3.20 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.21 Invoke ( V, P [ , argumentsList ] )
The abstract operation Invoke takes arguments V (an
7.3.22 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,
- Set O to ?
O.[[GetPrototypeOf]] (). - If O is
null , returnfalse . - If
SameValue (P, O) istrue , returntrue .
- Set O to ?
7.3.23 SpeciesConstructor ( O, defaultConstructor )
The abstract operation SpeciesConstructor takes arguments O (an Object) and defaultConstructor (a
- 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.24 EnumerableOwnPropertyNames ( O, kind )
The abstract operation EnumerableOwnPropertyNames takes arguments O (an Object) and kind (
- 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
- Let desc be ?
- If
- Return properties.
7.3.25 GetFunctionRealm ( obj )
The abstract operation GetFunctionRealm takes argument obj (a
- 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.26 CopyDataProperties ( target, source, excludedItems )
The abstract operation CopyDataProperties takes arguments target (an Object), source (an
- If source is
undefined ornull , returnunused . - 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
SameValue (e, nextKey) istrue , then- Set excluded to
true .
- Set excluded to
- If
- 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 desc be ?
- Let excluded be
- Return
unused .
The target passed in here is always a newly created object which is not directly accessible in case of an error being thrown.
7.3.27 PrivateElementFind ( O, P )
The abstract operation PrivateElementFind takes arguments O (an Object) and P (a
- If O.[[PrivateElements]] contains a
PrivateElement whose [[Key]] is P, then- Let entry be that
PrivateElement . - Return entry.
- Let entry be that
- Return
empty .
7.3.28 PrivateFieldAdd ( O, P, value )
The abstract operation PrivateFieldAdd takes arguments O (an Object), P (a
- Let entry be
PrivateElementFind (O, P). - If entry is not
empty , throw aTypeError exception. - Append
PrivateElement { [[Key]]: P, [[Kind]]:field , [[Value]]: value } to O.[[PrivateElements]]. - Return
unused .
7.3.29 PrivateMethodOrAccessorAdd ( O, method )
The abstract operation PrivateMethodOrAccessorAdd takes arguments O (an Object) and method (a
Assert : method.[[Kind]] is eithermethod oraccessor .- Let entry be
PrivateElementFind (O, method.[[Key]]). - If entry is not
empty , throw aTypeError exception. - Append method to O.[[PrivateElements]].
- Return
unused .
The values for private methods and accessors are shared across instances. This operation does not create a new copy of the method or accessor.
7.3.30 PrivateGet ( O, P )
The abstract operation PrivateGet takes arguments O (an Object) and P (a
- Let entry be
PrivateElementFind (O, P). - If entry is
empty , throw aTypeError exception. - If entry.[[Kind]] is
field ormethod , then- Return entry.[[Value]].
Assert : entry.[[Kind]] isaccessor .- If entry.[[Get]] is
undefined , throw aTypeError exception. - Let getter be entry.[[Get]].
- Return ?
Call (getter, O).
7.3.31 PrivateSet ( O, P, value )
The abstract operation PrivateSet takes arguments O (an Object), P (a
- Let entry be
PrivateElementFind (O, P). - If entry is
empty , throw aTypeError exception. - If entry.[[Kind]] is
field , then- Set entry.[[Value]] to value.
- Else if entry.[[Kind]] is
method , then- Throw a
TypeError exception.
- Throw a
- Else,
- Return
unused .
7.3.32 DefineField ( receiver, fieldRecord )
The abstract operation DefineField takes arguments receiver (an Object) and fieldRecord (a
- Let fieldName be fieldRecord.[[Name]].
- Let initializer be fieldRecord.[[Initializer]].
- If initializer is not
empty , then- Let initValue be ?
Call (initializer, receiver).
- Let initValue be ?
- Else, let initValue be
undefined . - If fieldName is a
Private Name , then- Perform ?
PrivateFieldAdd (receiver, fieldName, initValue).
- Perform ?
- Else,
Assert :IsPropertyKey (fieldName) istrue .- Perform ?
CreateDataPropertyOrThrow (receiver, fieldName, initValue).
- Return
unused .
7.3.33 InitializeInstanceElements ( O, constructor )
The abstract operation InitializeInstanceElements takes arguments O (an Object) and constructor (an ECMAScript
- Let methods be the value of constructor.[[PrivateMethods]].
- For each
PrivateElement method of methods, do- Perform ?
PrivateMethodOrAccessorAdd (O, method).
- Perform ?
- Let fields be the value of constructor.[[Fields]].
- For each element fieldRecord of fields, do
- Perform ?
DefineField (O, fieldRecord).
- Perform ?
- Return
unused .
7.4 Operations on Iterator Objects
See Common Iteration Interfaces (
7.4.1 Iterator Records
An Iterator Record is a next method.
Iterator Records have the fields listed in
| Field Name | Value | Meaning |
|---|---|---|
| [[Iterator]] | an Object | An object that conforms to the Iterator or AsyncIterator interface. |
| [[NextMethod]] |
a |
The next method of the [[Iterator]] object.
|
| [[Done]] | a Boolean | Whether the iterator has been closed. |
7.4.2 GetIterator ( obj [ , hint [ , method ] ] )
The abstract operation GetIterator takes argument obj (an
- If hint is not present, set hint to
sync . - If method is not present, then
- If hint is
async , then- Set 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 ?
- Set method to ?
- 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
Iterator Record { [[Iterator]]: iterator, [[NextMethod]]: nextMethod, [[Done]]:false }. - Return iteratorRecord.
7.4.3 IteratorNext ( iteratorRecord [ , value ] )
The abstract operation IteratorNext takes argument iteratorRecord (an
7.4.4 IteratorComplete ( iterResult )
The abstract operation IteratorComplete takes argument iterResult (an Object) and returns either a
7.4.5 IteratorValue ( iterResult )
The abstract operation IteratorValue takes argument iterResult (an Object) and returns either a
- Return ?
Get (iterResult,"value" ).
7.4.6 IteratorStep ( iteratorRecord )
The abstract operation IteratorStep takes argument iteratorRecord (an
- Let result be ?
IteratorNext (iteratorRecord). - Let done be ?
IteratorComplete (result). - If done is
true , returnfalse . - Return result.
7.4.7 IteratorClose ( iteratorRecord, completion )
The abstract operation IteratorClose takes arguments iteratorRecord (an
Assert :Type (iteratorRecord.[[Iterator]]) is Object.- Let iterator be iteratorRecord.[[Iterator]].
- Let innerResult be
Completion (GetMethod (iterator,"return" )). - If innerResult.[[Type]] is
normal , then- Let return be innerResult.[[Value]].
- If return is
undefined , return ? completion. - Set innerResult to
Completion (Call (return, iterator)).
- If completion.[[Type]] is
throw , return ? completion. - If innerResult.[[Type]] is
throw , return ? innerResult. - If
Type (innerResult.[[Value]]) is not Object, throw aTypeError exception. - Return ? completion.
7.4.8 IfAbruptCloseIterator ( value, iteratorRecord )
IfAbruptCloseIterator is a shorthand for a sequence of algorithm steps that use an
- IfAbruptCloseIterator(value, iteratorRecord).
means the same thing as:
- If value is an
abrupt completion , return ?IteratorClose (iteratorRecord, value). - Else if value is a
Completion Record , set value to value.[[Value]].
7.4.9 AsyncIteratorClose ( iteratorRecord, completion )
The abstract operation AsyncIteratorClose takes arguments iteratorRecord (an
Assert :Type (iteratorRecord.[[Iterator]]) is Object.- Let iterator be iteratorRecord.[[Iterator]].
- Let innerResult be
Completion (GetMethod (iterator,"return" )). - If innerResult.[[Type]] is
normal , then- Let return be innerResult.[[Value]].
- If return is
undefined , return ? completion. - Set innerResult to
Completion (Call (return, iterator)). - If innerResult.[[Type]] is
normal , set innerResult toCompletion (Await (innerResult.[[Value]])).
- If completion.[[Type]] is
throw , return ? completion. - If innerResult.[[Type]] is
throw , return ? innerResult. - If
Type (innerResult.[[Value]]) is not Object, throw aTypeError exception. - Return ? completion.
7.4.10 CreateIterResultObject ( value, done )
The abstract operation CreateIterResultObject takes arguments value (an
- Let obj be
OrdinaryObjectCreate (%Object.prototype% ). - Perform !
CreateDataPropertyOrThrow (obj,"value" , value). - Perform !
CreateDataPropertyOrThrow (obj,"done" , done). - Return obj.
7.4.11 CreateListIteratorRecord ( list )
The abstract operation CreateListIteratorRecord takes argument list (a next method returns the successive elements of list. It performs the following steps when called:
- 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 ?
GeneratorYield (CreateIterResultObject (E,false )).
- Perform ?
- Return
undefined .
- For each element E of list, do
- Let iterator be
CreateIteratorFromClosure (closure,empty ,%IteratorPrototype% ). - Return the
Iterator Record { [[Iterator]]: iterator, [[NextMethod]]:%GeneratorFunction.prototype.prototype.next% , [[Done]]:false }.
The list iterator object is never directly accessible to ECMAScript code.
7.4.12 IterableToList ( items [ , method ] )
The abstract operation IterableToList takes argument items (an
- 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 ?
- Set next to ?
- Return values.