티스토리 수익 글 보기
- Toggle shortcuts help
? - Toggle “can call user code” annotations
u - Navigate to/from multipage
m - Jump to search box
/ - Toggle pinning of the current clause
p - Jump to the nth pin
1-9 - Jump to the 10th pin
0 - Jump to the most recent link target
`
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
7.1.1 ToPrimitive ( input [ , preferredType ] )
The abstract operation ToPrimitive takes argument input (an
- If input
is an Object , then- Let exoticToPrim be ?
GetMethod (input,%Symbol.toPrimitive% ). - If exoticToPrim is not
undefined , then- If preferredType is not present, then
- Let hint be
“default” .
- Let hint be
- Else if preferredType is
string , then- Let hint be
“string” .
- Let hint be
- Else,
Assert : preferredType isnumber .- Let hint be
“number” .
- Let result be ?
Call (exoticToPrim, input, « hint »). - If result
is not an Object , return result. - Throw a
TypeError exception.
- If preferredType is not present, 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 result be ?
Call (method, O). - If result
is not an Object , return result.
- Let result be ?
- Let method be ?
- Throw a
TypeError exception.
7.1.2 ToBoolean ( argument )
The abstract operation ToBoolean takes argument argument (an
- If argument
is a Boolean , return argument. - If argument is one of
undefined ,null ,+0 𝔽,-0 𝔽,NaN ,0 ℤ, or the empty String, returnfalse . - If the
host is a web browser or otherwise supportsThe [[IsHTMLDDA]] Internal Slot , then- If argument
is an Object and argument has an [[IsHTMLDDA]] internal slot, returnfalse .
- If argument
- Return
true .
7.1.3 ToNumeric ( value )
The abstract operation ToNumeric takes argument value (an
- Let primValue be ?
ToPrimitive (value,number ). - If primValue
is a BigInt , return primValue. - Return ?
ToNumber (primValue).
7.1.4 ToNumber ( argument )
The abstract operation ToNumber takes argument argument (an
- If argument
is a Number , return argument. - If argument is either a Symbol or a BigInt, throw a
TypeError exception. - If argument is
undefined , returnNaN . - If argument is either
null orfalse , return+0 𝔽. - If argument is
true , return1 𝔽. - If argument
is a String , returnStringToNumber (argument). Assert : argumentis an Object .- Let primValue be ?
ToPrimitive (argument,number ). Assert : primValueis not an Object .- Return ?
ToNumber (primValue).
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 . -
A
StringNumericLiteral cannot include aNumericLiteralSeparator .
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 literal be
ParseText (str,StringNumericLiteral ). - If literal is a
List of errors, returnNaN . - Return the
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 the
StringNumericValue ofStrNumericLiteral .
- Return
𝔽 (MV ofNonDecimalIntegerLiteral ).
- Let a be the
StringNumericValue ofStrUnsignedDecimalLiteral . - If a is
+0 𝔽, return-0 𝔽. - Return –a.
- Return
+∞ 𝔽.
- Let a be the MV of the first
DecimalDigits . - If the second
DecimalDigits is present, then- Let b be the MV of the second
DecimalDigits . - Let n be the number of code points in the second
DecimalDigits .
- Let b be the MV of the second
- Else,
- Let b be 0.
- Let n be 0.
- If
ExponentPart is present, let e be the MV ofExponentPart ; otherwise let e be 0. - Return
RoundMVResult ((a + (b × 10–n)) × 10e).
- Let b be the MV of
DecimalDigits . - If
ExponentPart is present, let e be the 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 the MV of
DecimalDigits . - If
ExponentPart is present, let e be the 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 (an
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 (an
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 (an
7.1.9 ToUint16 ( argument )
The abstract operation ToUint16 takes argument argument (an
7.1.10 ToInt8 ( argument )
The abstract operation ToInt8 takes argument argument (an
7.1.11 ToUint8 ( argument )
The abstract operation ToUint8 takes argument argument (an
7.1.12 ToUint8Clamp ( argument )
The abstract operation ToUint8Clamp takes argument argument (an
- Let number be ?
ToNumber (argument). - If number is
NaN , return+0 𝔽. - Let mv be the
extended mathematical value of number. - Let clamped be the result of
clamping mv between 0 and 255. - Let f be
floor (clamped). - If clamped < f + 0.5, return
𝔽 (f). - If clamped > f + 0.5, return
𝔽 (f + 1). - If f is even, return
𝔽 (f); otherwise return𝔽 (f + 1).
Unlike most other ECMAScript Math.round
7.1.13 ToBigInt ( argument )
The abstract operation ToBigInt takes argument argument (an
- Let prim be ?
ToPrimitive (argument,number ). - Return the value that prim corresponds to in
Table 12 .
| 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
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 (an
7.1.16 ToBigUint64 ( argument )
The abstract operation ToBigUint64 takes argument argument (an
7.1.17 ToString ( argument )
The abstract operation ToString takes argument argument (an
- If argument
is a String , return argument. - If argument
is a Symbol , throw aTypeError exception. - If argument is
undefined , return“undefined” . - If argument is
null , return“null” . - If argument is
true , return“true” . - If argument is
false , return“false” . - If argument
is a Number , returnNumber::toString (argument, 10). - If argument
is a BigInt , returnBigInt::toString (argument, 10). Assert : argumentis an Object .- Let primValue be ?
ToPrimitive (argument,string ). Assert : primValueis not an Object .- Return ?
ToString (primValue).
7.1.18 ToObject ( argument )
The abstract operation ToObject takes argument argument (an
- If argument is either
undefined ornull , throw aTypeError exception. - If argument
is a Boolean , return a new Boolean object whose [[BooleanData]] internal slot is set to argument. See20.3 for a description of Boolean objects. - If argument
is a Number , return a new Number object whose [[NumberData]] internal slot is set to argument. See21.1 for a description of Number objects. - If argument
is a String , return a new String object whose [[StringData]] internal slot is set to argument. See22.1 for a description of String objects. - If argument
is a Symbol , return a new Symbol object whose [[SymbolData]] internal slot is set to argument. See20.4 for a description of Symbol objects. - If argument
is a BigInt , return a new BigInt object whose [[BigIntData]] internal slot is set to argument. See21.2 for a description of BigInt objects. Assert : argumentis an Object .- Return argument.
7.1.19 ToPropertyKey ( argument )
The abstract operation ToPropertyKey takes argument argument (an
- Let key be ?
ToPrimitive (argument,string ). - If key
is a 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 for which the CanonicalNumericIndexString abstract operation does not return
7.1.22 ToIndex ( value )
The abstract operation ToIndex takes argument value (an
- Let integer be ?
ToIntegerOrInfinity (value). - If integer is not in the
inclusive interval from 0 to 253 – 1, throw aRangeError exception. - Return integer.
7.2 Testing and Comparison Operations
7.2.1 RequireObjectCoercible ( argument )
The abstract operation RequireObjectCoercible takes argument argument (an
- If argument is either
undefined ornull , throw aTypeError exception. - Return
unused .
7.2.2 IsArray ( argument )
The abstract operation IsArray takes argument argument (an
- If argument
is not an Object , returnfalse . - If argument is an
Array exotic object , returntrue . - If argument is a
Proxy exotic object , then- Perform ?
ValidateNonRevokedProxy (argument). - Let proxyTarget be argument.[[ProxyTarget]].
- Return ?
IsArray (proxyTarget).
- Perform ?
- Return
false .
7.2.3 IsCallable ( argument )
The abstract operation IsCallable takes argument argument (an
- If argument
is not an 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 argument
is not an 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 IsRegExp ( argument )
The abstract operation IsRegExp takes argument argument (an
- If argument
is not an Object , returnfalse . - Let matcher be ?
Get (argument,%Symbol.match% ). - If matcher is not
undefined , returnToBoolean (matcher). - If argument has a [[RegExpMatcher]] internal slot, return
true . - Return
false .
7.2.7 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 len be the length of string.
- Let k be 0.
- Repeat, while k < len,
- 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.8 SameType ( x, y )
The abstract operation SameType takes arguments x (an
- If x is
undefined and y isundefined , returntrue . - If x is
null and y isnull , returntrue . - If x
is a Boolean and yis a Boolean , returntrue . - If x
is a Number and yis a Number , returntrue . - If x
is a BigInt and yis a BigInt , returntrue . - If x
is a Symbol and yis a Symbol , returntrue . - If x
is a String and yis a String , returntrue . - If x
is an Object and yis an Object , returntrue . - Return
false .
7.2.9 SameValue ( x, y )
The abstract operation SameValue takes arguments x (an
- If
SameType (x, y) isfalse , returnfalse . - If x
is a Number , then- Return
Number::sameValue (x, y).
- Return
- Return
SameValueNonNumber (x, y).
This algorithm differs from the
7.2.10 SameValueZero ( x, y )
The abstract operation SameValueZero takes arguments x (an
- If
SameType (x, y) isfalse , returnfalse . - If x
is a Number , then- Return
Number::sameValueZero (x, y).
- Return
- Return
SameValueNonNumber (x, y).
SameValueZero differs from
7.2.11 SameValueNonNumber ( x, y )
The abstract operation SameValueNonNumber takes arguments x (an
Assert :SameType (x, y) istrue .- If x is either
undefined ornull , returntrue . - If x
is a BigInt , then- Return
BigInt::equal (x, y).
- Return
- If x
is a String , then- If x and y have the same length and the same code units in the same positions, return
true ; otherwise returnfalse .
- If x and y have the same length and the same code units in the same positions, return
- If x
is a Boolean , then- If x and y are both
true or bothfalse , returntrue ; otherwise returnfalse .
- If x and y are both
- NOTE: All other
ECMAScript language values are compared by identity. - If x is y, return
true ; otherwise returnfalse .
7.2.12 IsLessThan ( x, y, LeftFirst )
The abstract operation IsLessThan takes arguments x (an
- If LeftFirst 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 px
is a String and pyis a String , then- Let lx be the length of px.
- Let ly be the length of py.
- For each
integer i such that 0 ≤ i <min (lx, ly), in ascending order, do- Let cx be the numeric value of the code unit at index i within px.
- Let cy be the numeric value of the code unit at index i within py.
- If cx < cy, return
true . - If cx > cy, return
false .
- If lx < ly, return
true ; otherwise returnfalse .
- Else,
- If px
is a BigInt and pyis a String , then- Let ny be
StringToBigInt (py). - If ny is
undefined , returnundefined . - Return
BigInt::lessThan (px, ny).
- Let ny be
- If px
is a String and pyis a 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
SameType (nx, ny) istrue , then- If nx
is a Number , then- Return
Number::lessThan (nx, ny).
- Return
- Else,
Assert : nxis a BigInt .- Return
BigInt::lessThan (nx, ny).
- If nx
Assert : nxis a BigInt and nyis a Number , or nxis a Number and nyis a 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), returntrue ; otherwise returnfalse .
- If px
The comparison of Strings uses a simple lexicographic ordering on sequences of UTF-16 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 but not in the same normalization form could test as unequal. Also note that lexicographic ordering by code unit differs from ordering by code point for Strings containing
7.2.13 IsLooselyEqual ( x, y )
The abstract operation IsLooselyEqual takes arguments x (an == operator. It performs the following steps when called:
- If
SameType (x, y) istrue , then- Return
IsStrictlyEqual (x, y).
- Return
- If x is
null and y isundefined , returntrue . - If x is
undefined and y isnull , returntrue . - If the
host is a web browser or otherwise supportsThe [[IsHTMLDDA]] Internal Slot , then- If x
is an Object , x has an [[IsHTMLDDA]] internal slot, and y is eitherundefined ornull , returntrue . - If x is either
undefined ornull , yis an Object , and y has an [[IsHTMLDDA]] internal slot, returntrue .
- If x
- If x
is a Number and yis a String , return !IsLooselyEqual (x, !ToNumber (y)). - If x
is a String and yis a Number , return !IsLooselyEqual (!ToNumber (x), y). - If x
is a BigInt and yis a String , then- Let n be
StringToBigInt (y). - If n is
undefined , returnfalse . - Return !
IsLooselyEqual (x, n).
- Let n be
- If x
is a String and yis a BigInt , return !IsLooselyEqual (y, x). - If x
is a Boolean , return !IsLooselyEqual (!ToNumber (x), y). - If y
is a Boolean , return !IsLooselyEqual (x, !ToNumber (y)). - If x is either a String, a Number, a BigInt, or a Symbol and y
is an Object , return !IsLooselyEqual (x, ?ToPrimitive (y)). - If x
is an Object and y is either a String, a Number, a BigInt, or a Symbol, return !IsLooselyEqual (?ToPrimitive (x), y). - If x
is a BigInt and yis a Number , or if xis a Number and yis a BigInt , then - Return
false .
7.2.14 IsStrictlyEqual ( x, y )
The abstract operation IsStrictlyEqual takes arguments x (an === operator. It performs the following steps when called:
- If
SameType (x, y) isfalse , returnfalse . - If x
is a Number , then- Return
Number::equal (x, y).
- Return
- Return
SameValueNonNumber (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
- Set internalSlotsList to the
list-concatenation of internalSlotsList and « [[PrivateElements]] ». - Let obj be a newly created object with an internal slot for each name in internalSlotsList.
- NOTE: As described in
Object Internal Methods and Internal Slots , the initial value of each such internal slot isundefined unless specified otherwise. - Set obj.[[PrivateElements]] to a new empty
List . - 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 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
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. 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 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,
7.3.8 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.9 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.10 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.11 HasProperty ( O, P )
The abstract operation HasProperty takes arguments O (an Object) and P (a
- Return ? O.[[HasProperty]](P).
7.3.12 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.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 . - 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 (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
- Return
true .
7.3.16 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
- Return
true .
7.3.17 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.18 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.19 CreateListFromArrayLike ( obj [ , validElementTypes ] )
The abstract operation CreateListFromArrayLike takes argument obj (an
- If validElementTypes is not present, set validElementTypes to
all . - If obj
is not an Object , throw aTypeError exception. - Let len be ?
LengthOfArrayLike (obj). - Let list be a new empty
List . - Let index be 0.
- Repeat, while index < len,
- Let indexName be !
ToString (𝔽 (index)). - Let next be ?
Get (obj, indexName). - If validElementTypes is
property-key and next is not aproperty key , throw aTypeError exception. - Append next to list.
- Set index to index + 1.
- Let indexName be !
- Return list.
7.3.20 Invoke ( V, P [ , argumentsList ] )
The abstract operation Invoke takes arguments V (an
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 O
is not an Object , returnfalse . - Let P be ?
Get (C,“prototype” ). - If P
is not an Object , throw aTypeError exception. - Repeat,
- Set O to ? O.[[GetPrototypeOf]]().
- If O is
null , returnfalse . - If
SameValue (P, O) istrue , returntrue .
7.3.22 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 C
is not an Object , throw aTypeError exception. - Let S be ?
Get (C,%Symbol.species% ). - If S is either
undefined ornull , return defaultConstructor. - If
IsConstructor (S) istrue , return S. - Throw a
TypeError exception.
7.3.23 EnumerableOwnProperties ( O, kind )
The abstract operation EnumerableOwnProperties takes arguments O (an Object) and kind (
- Let ownKeys be ? O.[[OwnPropertyKeys]]().
- Let results be a new empty
List . - For each element key of ownKeys, do
- If key
is a String , then- Let desc be ? O.[[GetOwnProperty]](key).
- If desc is not
undefined and desc.[[Enumerable]] istrue , then- If kind is
key , then- Append key to results.
- Else,
- Let value be ?
Get (O, key). - If kind is
value , then- Append value to results.
- Else,
Assert : kind iskey+value .- Let entry be
CreateArrayFromList (« key, value »). - Append entry to results.
- Let value be ?
- If kind is
- If key
- Return results.
7.3.24 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 boundTargetFunction be obj.[[BoundTargetFunction]].
- Return ?
GetFunctionRealm (boundTargetFunction).
- If obj is a
Proxy exotic object , then- Perform ?
ValidateNonRevokedProxy (obj). - Let proxyTarget be obj.[[ProxyTarget]].
Assert : proxyTarget is afunction object .- Return ?
GetFunctionRealm (proxyTarget).
- Perform ?
- Return
the current Realm Record .
Step
7.3.25 CopyDataProperties ( target, source, excludedItems )
The abstract operation CopyDataProperties takes arguments target (an Object), source (an
- If source is either
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 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.26 PrivateElementFind ( O, P )
The abstract operation PrivateElementFind takes arguments O (an Object) and P (a
- If O.[[PrivateElements]] contains a
PrivateElement pe such that pe.[[Key]] is P, then- Return pe.
- Return
empty .
7.3.27 PrivateFieldAdd ( O, P, value )
The abstract operation PrivateFieldAdd takes arguments O (an Object), P (a
- If the
host is a web browser, then- Perform ?
HostEnsureCanAddPrivateElement (O).
- Perform ?
- 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.28 PrivateMethodOrAccessorAdd ( O, method )
The abstract operation PrivateMethodOrAccessorAdd takes arguments O (an Object) and method (a
Assert : method.[[Kind]] is eithermethod oraccessor .- If the
host is a web browser, then- Perform ?
HostEnsureCanAddPrivateElement (O).
- Perform ?
- 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.29 HostEnsureCanAddPrivateElement ( O )
The
An implementation of HostEnsureCanAddPrivateElement must conform to the following requirements:
- If O is not a
host-defined exotic object , this abstract operation must returnNormalCompletion (unused ) and perform no other steps. - Any two calls of this abstract operation with the same argument must return the same kind of
Completion Record .
The default implementation of HostEnsureCanAddPrivateElement is to return
This abstract operation is only invoked by ECMAScript
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 either
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 .
- Let initValue be
- If fieldName is a
Private Name , then- Perform ?
PrivateFieldAdd (receiver, fieldName, initValue).
- Perform ?
- Else,
Assert : fieldName is aproperty key .- 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 constructor.[[PrivateMethods]].
- For each
PrivateElement method of methods, do- Perform ?
PrivateMethodOrAccessorAdd (O, method).
- Perform ?
- Let fields be constructor.[[Fields]].
- For each element fieldRecord of fields, do
- Perform ?
DefineField (O, fieldRecord).
- Perform ?
- Return
unused .
7.3.34 AddValueToKeyedGroup ( groups, key, value )
The abstract operation AddValueToKeyedGroup takes arguments groups (a
7.3.35 GroupBy ( items, callback, keyCoercion )
The abstract operation GroupBy takes arguments items (an
- Perform ?
RequireObjectCoercible (items). - If
IsCallable (callback) isfalse , throw aTypeError exception. - Let groups be a new empty
List . - Let iteratorRecord be ?
GetIterator (items,sync ). - Let k be 0.
- Repeat,
- If k ≥ 253 – 1, then
- Let error be
ThrowCompletion (a newly createdTypeError object). - Return ?
IteratorClose (iteratorRecord, error).
- Let error be
- Let next be ?
IteratorStepValue (iteratorRecord). - If next is
done , then- Return groups.
- Let value be next.
- Let key be
Completion (Call (callback,undefined , « value,𝔽 (k) »)). IfAbruptCloseIterator (key, iteratorRecord).- If keyCoercion is
property , then- Set key to
Completion (ToPropertyKey (key)). IfAbruptCloseIterator (key, iteratorRecord).
- Set key to
- Else,
Assert : keyCoercion iscollection .- Set key to
CanonicalizeKeyedCollectionKey (key).
- Perform
AddValueToKeyedGroup (groups, key, value). - Set k to k + 1.
- If k ≥ 253 – 1, then
7.3.36 GetOptionsObject ( options )
The abstract operation GetOptionsObject takes argument options (an
- If options is
undefined , then- Return
OrdinaryObjectCreate (null ).
- Return
- If options
is an Object , then- Return options.
- Throw a
TypeError exception.
7.3.37 SetterThatIgnoresPrototypeProperties ( thisValue, home, p, v )
The abstract operation SetterThatIgnoresPrototypeProperties takes arguments thisValue (an
- If thisValue
is not an Object , then- Throw a
TypeError exception.
- Throw a
- If
SameValue (thisValue, home) istrue , then- NOTE: Throwing here emulates assignment to a non-writable
data property on the home object instrict mode code . - Throw a
TypeError exception.
- NOTE: Throwing here emulates assignment to a non-writable
- Let desc be ? thisValue.[[GetOwnProperty]](p).
- If desc is
undefined , then- Perform ?
CreateDataPropertyOrThrow (thisValue, p, v).
- Perform ?
- Else,
- Perform ?
Set (thisValue, p, v,true ).
- 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 |
| [[NextMethod]] |
an |
The next method of the [[Iterator]] object.
|
| [[Done]] | a Boolean |
Whether the |
7.4.2 GetIteratorDirect ( obj )
The abstract operation GetIteratorDirect takes argument obj (an Object) and returns either a
- Let nextMethod be ?
Get (obj,“next” ). - Let iteratorRecord be the
Iterator Record { [[Iterator]]: obj, [[NextMethod]]: nextMethod, [[Done]]:false }. - Return iteratorRecord.
7.4.3 GetIteratorFromMethod ( obj, method )
The abstract operation GetIteratorFromMethod takes arguments obj (an
- Let iterator be ?
Call (method, obj). - If iterator
is not an Object , throw aTypeError exception. - Return ?
GetIteratorDirect (iterator).
7.4.4 GetIterator ( obj, kind )
The abstract operation GetIterator takes arguments obj (an
- If kind is
async , then- Let method be ?
GetMethod (obj,%Symbol.asyncIterator% ). - If method is
undefined , then- Let syncMethod be ?
GetMethod (obj,%Symbol.iterator% ). - If syncMethod is
undefined , throw aTypeError exception. - Let syncIteratorRecord be ?
GetIteratorFromMethod (obj, syncMethod). - Return
CreateAsyncFromSyncIterator (syncIteratorRecord).
- Let syncMethod be ?
- Let method be ?
- Else,
- Let method be ?
GetMethod (obj,%Symbol.iterator% ).
- Let method be ?
- If method is
undefined , throw aTypeError exception. - Return ?
GetIteratorFromMethod (obj, method).
7.4.5 GetIteratorFlattenable ( obj, primitiveHandling )
The abstract operation GetIteratorFlattenable takes arguments obj (an
- If obj
is not an Object , then- If primitiveHandling is
reject-primitives , throw aTypeError exception. Assert : primitiveHandling isiterate-string-primitives .- If obj
is not a String , throw aTypeError exception.
- If primitiveHandling is
- Let method be ?
GetMethod (obj,%Symbol.iterator% ). - If method is
undefined , then- Let iterator be obj.
- Else,
- Let iterator be ?
Call (method, obj).
- Let iterator be ?
- If iterator
is not an Object , throw aTypeError exception. - Return ?
GetIteratorDirect (iterator).
7.4.6 IteratorNext ( iteratorRecord [ , value ] )
The abstract operation IteratorNext takes argument iteratorRecord (an
- If value is not present, then
- Let result be
Completion (Call (iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]])).
- Let result be
- Else,
- Let result be
Completion (Call (iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]], « value »)).
- Let result be
- If result is a
throw completion , then- Set iteratorRecord.[[Done]] to
true . - Return ? result.
- Set iteratorRecord.[[Done]] to
- Set result to ! result.
- If result
is not an Object , then- Set iteratorRecord.[[Done]] to
true . - Throw a
TypeError exception.
- Set iteratorRecord.[[Done]] to
- Return result.
7.4.7 IteratorComplete ( iteratorResult )
The abstract operation IteratorComplete takes argument iteratorResult (an Object) and returns either a
7.4.8 IteratorValue ( iteratorResult )
The abstract operation IteratorValue takes argument iteratorResult (an Object) and returns either a
- Return ?
Get (iteratorResult,“value” ).
7.4.9 IteratorStep ( iteratorRecord )
The abstract operation IteratorStep takes argument iteratorRecord (an
- Let result be ?
IteratorNext (iteratorRecord). - Let done be
Completion (IteratorComplete (result)). - If done is a
throw completion , then- Set iteratorRecord.[[Done]] to
true . - Return ? done.
- Set iteratorRecord.[[Done]] to
- Set done to ! done.
- If done is
true , then- Set iteratorRecord.[[Done]] to
true . - Return
done .
- Set iteratorRecord.[[Done]] to
- Return result.
7.4.10 IteratorStepValue ( iteratorRecord )
The abstract operation IteratorStepValue takes argument iteratorRecord (an
- Let result be ?
IteratorStep (iteratorRecord). - If result is
done , then- Return
done .
- Return
- Let value be
Completion (IteratorValue (result)). - If value is a
throw completion , then- Set iteratorRecord.[[Done]] to
true .
- Set iteratorRecord.[[Done]] to
- Return ? value.
7.4.11 IteratorClose ( iteratorRecord, completion )
The abstract operation IteratorClose takes arguments iteratorRecord (an
Assert : iteratorRecord.[[Iterator]]is an Object .- Let iterator be iteratorRecord.[[Iterator]].
- Let innerResult be
Completion (GetMethod (iterator,“return” )). - If innerResult is a
normal completion , then- Let return be innerResult.[[Value]].
- If return is
undefined , return ? completion. - Set innerResult to
Completion (Call (return, iterator)).
- If completion is a
throw completion , return ? completion. - If innerResult is a
throw completion , return ? innerResult. - If innerResult.[[Value]]
is not an Object , throw aTypeError exception. - Return ? completion.
7.4.12 IteratorCloseAll ( iters, completion )
The abstract operation IteratorCloseAll takes arguments iters (a
- For each element iter of iters, in reverse
List order, do- Set completion to
Completion (IteratorClose (iter, completion)).
- Set completion to
- Return ? completion.
7.4.13 IfAbruptCloseIterator ( value, iteratorRecord )
IfAbruptCloseIterator is a shorthand for a sequence of algorithm steps that use an
IfAbruptCloseIterator (value, iteratorRecord).
means the same thing as:
Assert : value is aCompletion Record .- If value is an
abrupt completion , return ?IteratorClose (iteratorRecord, value). - Else, set value to ! value.
7.4.14 AsyncIteratorClose ( iteratorRecord, completion )
The abstract operation AsyncIteratorClose takes arguments iteratorRecord (an
Assert : iteratorRecord.[[Iterator]]is an Object .- Let iterator be iteratorRecord.[[Iterator]].
- Let innerResult be
Completion (GetMethod (iterator,“return” )). - If innerResult is a
normal completion , then- Let return be innerResult.[[Value]].
- If return is
undefined , return ? completion. - Set innerResult to
Completion (Call (return, iterator)). - If innerResult is a
normal completion , set innerResult toCompletion (Await (innerResult.[[Value]])).
- If completion is a
throw completion , return ? completion. - If innerResult is a
throw completion , return ? innerResult. - If innerResult.[[Value]]
is not an Object , throw aTypeError exception. - Return ? completion.
7.4.15 IfAbruptCloseAsyncIterator ( value, iteratorRecord )
IfAbruptCloseAsyncIterator is a shorthand for a sequence of algorithm steps that use an
IfAbruptCloseAsyncIterator (value, iteratorRecord).
means the same thing as:
Assert : value is aCompletion Record .- If value is an
abrupt completion , return ?AsyncIteratorClose (iteratorRecord, value). - Else, set value to ! value.
7.4.16 CreateIteratorResultObject ( value, done )
The abstract operation CreateIteratorResultObject takes arguments value (an
- Let obj be
OrdinaryObjectCreate (%Object.prototype% ). - Perform !
CreateDataPropertyOrThrow (obj,“value” , value). - Perform !
CreateDataPropertyOrThrow (obj,“done” , done). - Return obj.
7.4.17 CreateListIteratorRecord ( list )
The abstract operation CreateListIteratorRecord takes argument list (a
- 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 (CreateIteratorResultObject (E,false )).
- Perform ?
- Return
NormalCompletion (undefined ).
- For each element E of list, do
- Let iterator be
CreateIteratorFromClosure (closure,empty ,%Iterator.prototype% ). - Return the
Iterator Record { [[Iterator]]: iterator, [[NextMethod]]: %GeneratorPrototype.next%, [[Done]]:false }.
The list
7.4.18 IteratorToList ( iteratorRecord )
The abstract operation IteratorToList takes argument iteratorRecord (an
- Let values be a new empty
List . - Repeat,
- Let next be ?
IteratorStepValue (iteratorRecord). - If next is
done , then- Return values.
- Append next to values.
- Let next be ?