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 exoticToPrimitive be ?
GetMethod (input,%Symbol.toPrimitive% ). - If exoticToPrimitive 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 (exoticToPrimitive, 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, set preferredType to
number . - Return ?
OrdinaryToPrimitive (input, preferredType).
- Let exoticToPrimitive be ?
- Return input.
When ToPrimitive is called without a hint, then it generally behaves as if the hint were
7.1.1.1 OrdinaryToPrimitive ( obj, hint )
The abstract operation OrdinaryToPrimitive takes arguments obj (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 (obj, name). - If
IsCallable (method) istrue , then- Let result be ?
Call (method, obj). - If result
is not an Object , return result.
- Let result be ?
- Let method be ?
- Throw a
TypeError exception.
7.1.2 ToBoolean ( arg )
The abstract operation ToBoolean takes argument arg (an
- If arg
is a Boolean , return arg. - If arg is one of
undefined ,null ,+0 𝔽,-0 𝔽,NaN ,0 ℤ, or the empty String, returnfalse . - If the
host is a web browser orotherwise supports The [[IsHTMLDDA]] Internal Slot , then- If arg
is an Object and arg has an [[IsHTMLDDA]] internal slot, returnfalse .
- If arg
- Return
true .
7.1.3 ToNumeric ( arg )
The abstract operation ToNumeric takes argument arg (an
- Let primitiveValue be ?
ToPrimitive (arg,number ). - If primitiveValue
is a BigInt , return primitiveValue. - Return ?
.ToNumber (primitiveValue)
7.1.4 ToNumber ( arg )
The abstract operation ToNumber takes argument arg (an
- If arg
is a Number , return arg. - If arg is either a Symbol or a BigInt, throw a
TypeError exception. - If arg is
undefined , returnNaN . - If arg is either
null orfalse , return+0 𝔽. - If arg is
true , return1 𝔽. - If arg
is a String , returnStringToNumber (arg). Assert : argis an Object .- Let primitiveValue be ?
ToPrimitive (arg,number ). Assert : primitiveValueis not an Object .- Return ? ToNumber(primitiveValue).
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 ( string )
The abstract operation StringToNumber takes argument string (a String) and returns a Number. It performs the following steps when called:
- Let literal be
ParseText (string,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 of
StrNumericLiteral .
- Return
𝔽 (MV ofNonDecimalIntegerLiteral ).
- Let a be the StringNumericValue of
StrUnsignedDecimalLiteral . - 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 ; else 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 ; else 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 ; else 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 ( arg )
The abstract operation ToIntegerOrInfinity takes argument arg (an
7.1.6 ToFixedSizeInteger ( int, signed, bitWidth )
The abstract operation ToFixedSizeInteger takes arguments int (an
ToFixedSizeInteger is idempotent: for any
7.1.7 ToInt32 ( arg )
The abstract operation ToInt32 takes argument arg (an
- Let int be ?
ToIntegerOrInfinity (arg). - Return
𝔽 (ToFixedSizeInteger (int,signed , 32)).
7.1.8 ToUint32 ( arg )
The abstract operation ToUint32 takes argument arg (an
- Let int be ?
ToIntegerOrInfinity (arg). - Return
𝔽 (ToFixedSizeInteger (int,unsigned , 32)).
7.1.9 ToInt16 ( arg )
The abstract operation ToInt16 takes argument arg (an
- Let int be ?
ToIntegerOrInfinity (arg). - Return
𝔽 (ToFixedSizeInteger (int,signed , 16)).
7.1.10 ToUint16 ( arg )
The abstract operation ToUint16 takes argument arg (an
- Let int be ?
ToIntegerOrInfinity (arg). - Return
𝔽 (ToFixedSizeInteger (int,unsigned , 16)).
7.1.11 ToInt8 ( arg )
The abstract operation ToInt8 takes argument arg (an
- Let int be ?
ToIntegerOrInfinity (arg). - Return
𝔽 (ToFixedSizeInteger (int,signed , 8)).
7.1.12 ToUint8 ( arg )
The abstract operation ToUint8 takes argument arg (an
- Let int be ?
ToIntegerOrInfinity (arg). - Return
𝔽 (ToFixedSizeInteger (int,unsigned , 8)).
7.1.13 ToUint8Clamp ( arg )
The abstract operation ToUint8Clamp takes argument arg (an
- Let number be ?
ToNumber (arg). - 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). - Return
𝔽 (f + 1).
Unlike most other ECMAScript Math.round
7.1.14 ToBigInt ( arg )
The abstract operation ToBigInt takes argument arg (an
- Let primitive be ?
ToPrimitive (arg,number ). - Return the value that primitive corresponds to in
Table 12 .
| Argument Type | Result |
|---|---|
| Undefined |
Throw a |
| Null |
Throw a |
| Boolean |
Return 1n if primitive is 0n if primitive is |
| BigInt | Return primitive. |
| Number |
Throw a |
| String |
|
| Symbol |
Throw a |
7.1.15 StringToBigInt ( string )
The abstract operation StringToBigInt takes argument string (a String) and returns a BigInt or
7.1.15.1 StringIntegerLiteral Grammar
Syntax
7.1.15.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.16 ToBigInt64 ( arg )
The abstract operation ToBigInt64 takes argument arg (an
- Let int be
ℝ (?ToBigInt (arg)). - Return
ℤ (ToFixedSizeInteger (int,signed , 64)).
7.1.17 ToBigUint64 ( arg )
The abstract operation ToBigUint64 takes argument arg (an
- Let int be
ℝ (?ToBigInt (arg)). - Return
ℤ (ToFixedSizeInteger (int,unsigned , 64)).
7.1.18 ToString ( arg )
The abstract operation ToString takes argument arg (an
- If arg
is a String , return arg. - If arg
is a Symbol , throw aTypeError exception. - If arg is
undefined , return"undefined" . - If arg is
null , return"null" . - If arg is
true , return"true" . - If arg is
false , return"false" . - If arg
is a Number , returnNumber::toString (arg, 10). - If arg
is a BigInt , returnBigInt::toString (arg, 10). Assert : argis an Object .- Let primitiveValue be ?
ToPrimitive (arg,string ). Assert : primitiveValueis not an Object .- Return ? ToString(primitiveValue).
7.1.19 ToObject ( arg )
The abstract operation ToObject takes argument arg (an
- If arg is either
undefined ornull , throw aTypeError exception. - If arg
is a Boolean , return a new Boolean object whose [[BooleanData]] internal slot is set to arg. See20.3 for a description of Boolean objects. - If arg
is a Number , return a new Number object whose [[NumberData]] internal slot is set to arg. See21.1 for a description of Number objects. - If arg
is a String , return a new String object whose [[StringData]] internal slot is set to arg. See22.1 for a description of String objects. - If arg
is a Symbol , return a new Symbol object whose [[SymbolData]] internal slot is set to arg. See20.4 for a description of Symbol objects. - If arg
is a BigInt , return a new BigInt object whose [[BigIntData]] internal slot is set to arg. See21.2 for a description of BigInt objects. Assert : argis an Object .- Return arg.
7.1.20 ToPropertyKey ( arg )
The abstract operation ToPropertyKey takes argument arg (an
- Let key be ?
ToPrimitive (arg,string ). - If key
is a Symbol , then- Return key.
- Return !
ToString (key).
7.1.21 ToLength ( arg )
The abstract operation ToLength takes argument arg (an
- Let length be ?
ToIntegerOrInfinity (arg). - If length ≤ 0, return
+0 𝔽. - Return
𝔽 (min (length, 253 - 1)).
7.1.22 CanonicalNumericIndexString ( arg )
The abstract operation CanonicalNumericIndexString takes argument arg (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.23 ToIndex ( arg )
The abstract operation ToIndex takes argument arg (an
- Let int be ?
ToIntegerOrInfinity (arg). - If int is not in the
inclusive interval from 0 to 253 - 1, throw aRangeError exception. - Return int.
7.2 Testing and Comparison Operations
7.2.1 RequireObjectCoercible ( arg )
The abstract operation RequireObjectCoercible takes argument arg (an
- If arg is either
undefined ornull , throw aTypeError exception. - Return
unused .
7.2.2 IsArray ( arg )
The abstract operation IsArray takes argument arg (an
- If arg
is not an Object , returnfalse . - If arg is an
Array exotic object , returntrue . - If arg is a
Proxy exotic object , then- Perform ?
ValidateNonRevokedProxy (arg). - Let proxyTarget be arg.[[ProxyTarget]].
- Return ? IsArray(proxyTarget).
- Perform ?
- Return
false .
7.2.3 IsCallable ( arg )
The abstract operation IsCallable takes argument arg (an
- If arg
is not an Object , returnfalse . - If arg has a [[Call]] internal method, return
true . - Return
false .
7.2.4 IsConstructor ( arg )
The abstract operation IsConstructor takes argument arg (an
- If arg
is not an Object , returnfalse . - If arg has a [[Construct]] internal method, return
true . - Return
false .
7.2.5 IsExtensible ( obj )
The abstract operation IsExtensible takes argument obj (an Object) and returns either a
- Return ?
obj.[[IsExtensible]]() .
7.2.6 IsRegExp ( arg )
The abstract operation IsRegExp takes argument arg (an
- If arg
is not an Object , returnfalse . - Let matcher be ?
Get (arg,%Symbol.match% ). - If matcher is not
undefined , returnToBoolean (matcher). - If arg 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 length be the length of string.
- Let k be 0.
- Repeat, while k < length,
- Let codePoint be
CodePointAt (string, k). - If codePoint.[[IsUnpairedSurrogate]] is
true , returnfalse . - Set k to k + codePoint.[[CodeUnitCount]].
- Let codePoint 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 . - Return
false .
- 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 is
true and y istrue , returntrue . - If x is
false and y isfalse , returntrue . - Return
false .
- If x is
NOTE : All otherECMAScript language values are compared by identity.- If x is y, return
true . - Return
false .
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 . - Return
false .
- 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 , returnNumber::lessThan (nx, ny). 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 is
NaN or ny isNaN , returnundefined . - If nx is
-∞ 𝔽 or ny is+∞ 𝔽, returntrue . - If nx is
+∞ 𝔽 or ny is-∞ 𝔽, returnfalse . - If
ℝ (nx) <ℝ (ny), returntrue . - Return
false .
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 orotherwise supports The [[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 inObject 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 ( obj, propertyKey )
The abstract operation Get takes arguments obj (an Object) and propertyKey (a
- Return ?
obj.[[Get]](propertyKey, obj) .
7.3.3 GetV ( value, propertyKey )
The abstract operation GetV takes arguments value (an
- Let obj be ?
ToObject (value). - Return ?
obj.[[Get]](propertyKey, value) .
7.3.4 Set ( obj, propertyKey, value, throw )
The abstract operation Set takes arguments obj (an Object), propertyKey (a
- Let success be ?
obj.[[Set]](propertyKey, value, obj) . - If success is
false and throw istrue , throw aTypeError exception. - Return
unused .
7.3.5 CreateDataProperty ( obj, propertyKey, value )
The abstract operation CreateDataProperty takes arguments obj (an Object), propertyKey (a
- Let newDesc be the PropertyDescriptor { [[Value]]: value, [[Writable]]:
true , [[Enumerable]]:true , [[Configurable]]:true }. - Return ?
obj.[[DefineOwnProperty]](propertyKey, 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 obj is not extensible, [[DefineOwnProperty]] will return
7.3.6 CreateDataPropertyOrThrow ( obj, propertyKey, value )
The abstract operation CreateDataPropertyOrThrow takes arguments obj (an Object), propertyKey (a
- Let success be ?
CreateDataProperty (obj, propertyKey, value). - 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 obj is not extensible, [[DefineOwnProperty]] will return
7.3.7 CreateNonEnumerableDataPropertyOrThrow ( obj, propertyKey, value )
The abstract operation CreateNonEnumerableDataPropertyOrThrow takes arguments obj (an Object), propertyKey (a
Assert : obj is an ordinary, extensible object with no non-configurable properties.- Let newDesc be the PropertyDescriptor { [[Value]]: value, [[Writable]]:
true , [[Enumerable]]:false , [[Configurable]]:true }. - Perform !
DefinePropertyOrThrow (obj, propertyKey, 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 ( obj, propertyKey, propertyDesc )
The abstract operation DefinePropertyOrThrow takes arguments obj (an Object), propertyKey (a
- Let success be ?
obj.[[DefineOwnProperty]](propertyKey, propertyDesc) . - If success is
false , throw aTypeError exception. - Return
unused .
7.3.9 DeletePropertyOrThrow ( obj, propertyKey )
The abstract operation DeletePropertyOrThrow takes arguments obj (an Object) and propertyKey (a
- Let success be ?
obj.[[Delete]](propertyKey) . - If success is
false , throw aTypeError exception. - Return
unused .
7.3.10 GetMethod ( value, propertyKey )
The abstract operation GetMethod takes arguments value (an
- Let func be ?
GetV (value, propertyKey). - If func is either
undefined ornull , returnundefined . - If
IsCallable (func) isfalse , throw aTypeError exception. - Return func.
7.3.11 HasProperty ( obj, propertyKey )
The abstract operation HasProperty takes arguments obj (an Object) and propertyKey (a
- Return ?
obj.[[HasProperty]](propertyKey) .
7.3.12 HasOwnProperty ( obj, propertyKey )
The abstract operation HasOwnProperty takes arguments obj (an Object) and propertyKey (a
- Let propertyDesc be ?
obj.[[GetOwnProperty]](propertyKey) . - If propertyDesc is
undefined , returnfalse . - Return
true .
7.3.13 Call ( func, thisValue [ , argList ] )
The abstract operation Call takes arguments func (an
- If argList is not present, set argList to a new empty
List . - If
IsCallable (func) isfalse , throw aTypeError exception. - Return ?
func.[[Call]](thisValue, argList) .
7.3.14 Construct ( ctor [ , argList [ , newTarget ] ] )
The abstract operation Construct takes argument ctor (a
- If newTarget is not present, set newTarget to ctor.
- If argList is not present, set argList to a new empty
List . - Return ?
ctor.[[Construct]](argList, newTarget) .
If newTarget is not present, this operation is equivalent to: new F(...argumentsList)
7.3.15 SetIntegrityLevel ( obj, level )
The abstract operation SetIntegrityLevel takes arguments obj (an Object) and level (
- Let status be ? obj.[[PreventExtensions]]().
- If status is
false , returnfalse . - Let keys be ? obj.[[OwnPropertyKeys]]().
- If level is
sealed , then- For each element key of keys, do
- Perform ?
DefinePropertyOrThrow (obj, key, PropertyDescriptor { [[Configurable]]:false }).
- Perform ?
- For each element key of keys, do
- Else,
Assert : level isfrozen .- For each element key of keys, do
- Let currentDesc be ?
obj.[[GetOwnProperty]](key) . - If currentDesc is not
undefined , then- If
IsAccessorDescriptor (currentDesc) istrue , then- Let propertyDesc be the PropertyDescriptor { [[Configurable]]:
false }.
- Let propertyDesc be the PropertyDescriptor { [[Configurable]]:
- Else,
- Let propertyDesc be the PropertyDescriptor { [[Configurable]]:
false , [[Writable]]:false }.
- Let propertyDesc be the PropertyDescriptor { [[Configurable]]:
- Perform ?
DefinePropertyOrThrow (obj, key, propertyDesc).
- If
- Let currentDesc be ?
- Return
true .
7.3.16 TestIntegrityLevel ( obj, level )
The abstract operation TestIntegrityLevel takes arguments obj (an Object) and level (
- Let extensible be ?
IsExtensible (obj). - If extensible is
true , returnfalse . NOTE : If the object is extensible, none of its properties are examined.- Let keys be ? obj.[[OwnPropertyKeys]]().
- For each element key of keys, do
- Let currentDesc be ?
obj.[[GetOwnProperty]](key) . - 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.17 CreateArrayFromList ( elements )
The abstract operation CreateArrayFromList takes argument elements (a
- Let array be !
ArrayCreate (0). - Let n be 0.
- For each element element of elements, do
- Perform !
CreateDataPropertyOrThrow (array, !ToString (𝔽 (n)), element). - 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 length be ?
LengthOfArrayLike (obj). - Let list be a new empty
List . - Let index be 0.
- Repeat, while index < length,
- 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 ( value, propertyKey [ , argList ] )
The abstract operation Invoke takes arguments value (an
7.3.21 OrdinaryHasInstance ( ctor, instance )
The abstract operation OrdinaryHasInstance takes arguments ctor (an
- If
IsCallable (ctor) isfalse , returnfalse . - If ctor has a [[BoundTargetFunction]] internal slot, then
- Let boundCtor be ctor.[[BoundTargetFunction]].
- Return ?
InstanceofOperator (instance, boundCtor).
- If instance
is not an Object , returnfalse . - Let proto be ?
Get (ctor,"prototype" ). - If proto
is not an Object , throw aTypeError exception. - Repeat,
- Set instance to ?
instance.[[GetPrototypeOf]]() . - If instance is
null , returnfalse . - If
SameValue (proto, instance) istrue , returntrue .
- Set instance to ?
7.3.22 SpeciesConstructor ( obj, defaultCtor )
The abstract operation SpeciesConstructor takes arguments obj (an Object) and defaultCtor (a
- Let ctor be ?
Get (obj,"constructor" ). - If ctor is
undefined , return defaultCtor. - If ctor
is not an Object , throw aTypeError exception. - Let species be ?
Get (ctor,%Symbol.species% ). - If species is either
undefined ornull , return defaultCtor. - If
IsConstructor (species) istrue , return species. - Throw a
TypeError exception.
7.3.23 EnumerableOwnProperties ( obj, kind )
The abstract operation EnumerableOwnProperties takes arguments obj (an Object) and kind (
- Let ownKeys be ?
obj.[[OwnPropertyKeys]]() . - Let results be a new empty
List . - For each element key of ownKeys, do
- If key
is a String , then- Let propertyDesc be ?
obj.[[GetOwnProperty]](key) . - If propertyDesc is not
undefined and propertyDesc.[[Enumerable]] istrue , then- If kind is
key , then- Append key to results.
- Else,
- Let value be ?
Get (obj, 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
- Let propertyDesc be ?
- If key
- Return results.
7.3.24 GetFunctionRealm ( func )
The abstract operation GetFunctionRealm takes argument func (a
- If func has a [[Realm]] internal slot, then
- Return func.[[Realm]].
- If func is a
bound function exotic object , then- Let boundTargetFunc be func.[[BoundTargetFunction]].
- Return ? GetFunctionRealm(boundTargetFunc).
- If func is a
Proxy exotic object , then- Perform ?
ValidateNonRevokedProxy (func). - Let proxyTarget be func.[[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 element of excludedItems, do
- If
SameValue (element, nextKey) istrue , then- Set excluded to
true .
- Set excluded to
- If
- If excluded is
false , then- Let propertyDesc be ?
from.[[GetOwnProperty]](nextKey) . - If propertyDesc is not
undefined and propertyDesc.[[Enumerable]] istrue , then- Let propertyValue be ?
Get (from, nextKey). - Perform !
CreateDataPropertyOrThrow (target, nextKey, propertyValue).
- Let propertyValue be ?
- Let propertyDesc 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 ( obj, privateName )
The abstract operation PrivateElementFind takes arguments obj (an Object) and privateName (a
- If obj.[[PrivateElements]] contains a
PrivateElement pe such that pe.[[Key]] is privateName, then- Return pe.
- Return
empty .
7.3.27 PrivateFieldAdd ( obj, privateName, value )
The abstract operation PrivateFieldAdd takes arguments obj (an Object), privateName (a
- If the
host is a web browser, then- Perform ?
HostEnsureCanAddPrivateElement (obj).
- Perform ?
- Let entry be
PrivateElementFind (obj, privateName). - If entry is not
empty , throw aTypeError exception. - Append
PrivateElement { [[Key]]: privateName, [[Kind]]:field , [[Value]]: value } to obj.[[PrivateElements]]. - Return
unused .
7.3.28 PrivateMethodOrAccessorAdd ( obj, method )
The abstract operation PrivateMethodOrAccessorAdd takes arguments obj (an Object) and method (a
Assert : method.[[Kind]] is eithermethod oraccessor .- If the
host is a web browser, then- Perform ?
HostEnsureCanAddPrivateElement (obj).
- Perform ?
- Let entry be
PrivateElementFind (obj, method.[[Key]]). - If entry is not
empty , throw aTypeError exception. - Append method to obj.[[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 ( obj )
The
An implementation of HostEnsureCanAddPrivateElement must conform to the following requirements:
- If obj 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 ( obj, privateName )
The abstract operation PrivateGet takes arguments obj (an Object) and privateName (a
- Let entry be
PrivateElementFind (obj, privateName). - 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, obj).
7.3.31 PrivateSet ( obj, privateName, value )
The abstract operation PrivateSet takes arguments obj (an Object), privateName (a
- Let entry be
PrivateElementFind (obj, privateName). - If entry is
empty , throw aTypeError exception. - If entry.[[Kind]] is
method , throw aTypeError exception. - If entry.[[Kind]] is
field , then- Set entry.[[Value]] to value.
- 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 ( obj, ctor )
The abstract operation InitializeInstanceElements takes arguments obj (an Object) and ctor (an ECMAScript
- Let methods be ctor.[[PrivateMethods]].
- For each
PrivateElement method of methods, do- Perform ?
PrivateMethodOrAccessorAdd (obj, method).
- Perform ?
- Let fields be ctor.[[Fields]].
- For each element fieldRecord of fields, do
- Perform ?
DefineField (obj, 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, propertyKey, value )
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 , thenNOTE : Throwing here emulates assignment to a non-writabledata property on the home object instrict mode code .- Throw a
TypeError exception.
- Let propertyDesc be ? thisValue.[[GetOwnProperty]](propertyKey).
- If propertyDesc is
undefined , then- Perform ?
CreateDataPropertyOrThrow (thisValue, propertyKey, value).
- Perform ?
- Else,
- Perform ?
Set (thisValue, propertyKey, value,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 ( iterators, completion )
The abstract operation IteratorCloseAll takes arguments iterators (a
- For each element iterator of iterators, in reverse
List order, do- Set completion to
Completion (IteratorClose (iterator, 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). - Set value to ! value.
7.4.14 IfAbruptCloseIterators ( value, iteratorRecords )
IfAbruptCloseIterators is a shorthand for a sequence of algorithm steps that use a list of
- IfAbruptCloseIterators(value, iteratorRecords).
means the same thing as:
Assert : value is aCompletion Record .- If value is an
abrupt completion , return ?IteratorCloseAll (iteratorRecords, value). - Set value to ! value.
7.4.15 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.16 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). - Set value to ! value.
7.4.17 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.18 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 value of list, do
- Perform ?
GeneratorYield (CreateIteratorResultObject (value,false )).
- Perform ?
- Return
NormalCompletion (undefined ).
- For each element value 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.19 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 ?