7 Abstract Operations
These operations are not a part of the ECMAScript language; they are defined here to solely to aid the specification of the semantics of the ECMAScript language. Other, more specialized abstract operations are defined throughout this specification.
7.1 Type Conversion
The ECMAScript language implicitly performs automatic
7.1.1 ToPrimitive ( input [ , PreferredType ] )
The abstract operation ToPrimitive takes an input argument and an optional argument PreferredType. The abstract operation ToPrimitive converts its input argument to a non-Object
Assert : input is anECMAScript language value .- If
Type (input) is Object, then- If PreferredType was not passed, let hint be
"default". - Else if PreferredType is hint String, let hint be
"string". - Else PreferredType is hint Number, let hint be
"number". - Let exoticToPrim be ?
GetMethod (input, @@toPrimitive). - If exoticToPrim is not
undefined , then - If hint is
"default", set hint to"number". - Return ?
OrdinaryToPrimitive (input, hint).
- If PreferredType was not passed, let hint be
- Return input.
When ToPrimitive is called with no hint, then it generally behaves as if the hint were Number. However, objects may over-ride this behaviour by defining a @@toPrimitive method. Of the objects defined in this specification only Date objects (see
7.1.1.1 OrdinaryToPrimitive ( O, hint )
When the abstract operation OrdinaryToPrimitive is called with arguments O and hint, the following steps are taken:
Assert :Type (O) is Object.Assert :Type (hint) is String and its value is either"string"or"number".- If hint is
"string", then- Let methodNames be «
"toString","valueOf"».
- Let methodNames be «
- Else,
- Let methodNames be «
"valueOf","toString"».
- Let methodNames be «
- For each name in methodNames in
List order, do- Let method be ?
Get (O, name). - If
IsCallable (method) istrue , then
- Let method be ?
- Throw a
TypeError exception.
7.1.2 ToBoolean ( argument )
The abstract operation ToBoolean converts argument to a value of
|
Argument |
Result |
|---|---|
| Undefined |
Return |
| Null |
Return |
| Boolean | Return argument. |
| Number |
If argument is |
| String |
If argument is the empty String (its length is zero), return |
| Symbol |
Return |
| Object |
Return |
7.1.3 ToNumber ( argument )
The abstract operation ToNumber converts argument to a value of
|
Argument |
Result |
|---|---|
| Undefined |
Return |
| Null |
Return |
| Boolean |
If argument is |
| Number | Return argument (no conversion). |
| String | See grammar and conversion algorithm below. |
| Symbol |
Throw a |
| Object |
Apply the following steps:
|
7.1.3.1 ToNumber Applied to the String Type
The terminal symbols of this grammar are all composed of Unicode BMP code points so the result will be
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 .
7.1.3.1.1 Runtime Semantics: MV
The conversion of a String to a Number value is similar overall to the determination of the Number value for a numeric literal (see
-
The MV of
is 0.StringNumericLiteral ::: [empty] -
The MV of
is 0.StringNumericLiteral ::: StrWhiteSpace -
The MV of
is the MV ofStringNumericLiteral ::: StrWhiteSpace opt StrNumericLiteral StrWhiteSpace opt StrNumericLiteral , no matter whether white space is present or not. -
The MV of
is the MV ofStrNumericLiteral ::: StrDecimalLiteral StrDecimalLiteral . -
The MV of
is the MV ofStrNumericLiteral ::: BinaryIntegerLiteral BinaryIntegerLiteral . -
The MV of
is the MV ofStrNumericLiteral ::: OctalIntegerLiteral OctalIntegerLiteral . -
The MV of
is the MV ofStrNumericLiteral ::: HexIntegerLiteral HexIntegerLiteral . -
The MV of
is the MV ofStrDecimalLiteral ::: StrUnsignedDecimalLiteral StrUnsignedDecimalLiteral . -
The MV of
is the MV ofStrDecimalLiteral ::: + StrUnsignedDecimalLiteral StrUnsignedDecimalLiteral . -
The MV of
is the negative of the MV ofStrDecimalLiteral ::: - StrUnsignedDecimalLiteral StrUnsignedDecimalLiteral . (Note that if the MV ofStrUnsignedDecimalLiteral is 0, the negative of this MV is also 0. The rounding rule described below handles the conversion of this signless mathematical zero to a floating-point+0 or-0 as appropriate.) -
The MV of
is 1010000 (a value so large that it will round toStrUnsignedDecimalLiteral ::: Infinity +∞ ). -
The MV of
is the MV ofStrUnsignedDecimalLiteral ::: DecimalDigits . DecimalDigits . -
The MV of
is the MV of the firstStrUnsignedDecimalLiteral ::: DecimalDigits . DecimalDigits DecimalDigits plus (the MV of the secondDecimalDigits times 10-n), where n is the number of code points in the secondDecimalDigits . -
The MV of
is the MV ofStrUnsignedDecimalLiteral ::: DecimalDigits . ExponentPart DecimalDigits times 10e, where e is the MV ofExponentPart . -
The MV of
is (the MV of the firstStrUnsignedDecimalLiteral ::: DecimalDigits . DecimalDigits ExponentPart DecimalDigits plus (the MV of the secondDecimalDigits times 10-n)) times 10e, where n is the number of code points in the secondDecimalDigits and e is the MV ofExponentPart . -
The MV of
is the MV ofStrUnsignedDecimalLiteral ::: . DecimalDigits DecimalDigits times 10-n, where n is the number of code points inDecimalDigits . -
The MV of
is the MV ofStrUnsignedDecimalLiteral ::: . DecimalDigits ExponentPart DecimalDigits times 10e-n, where n is the number of code points inDecimalDigits and e is the MV ofExponentPart . -
The MV of
is the MV ofStrUnsignedDecimalLiteral ::: DecimalDigits DecimalDigits . -
The MV of
is the MV ofStrUnsignedDecimalLiteral ::: DecimalDigits ExponentPart DecimalDigits times 10e, where e is the MV ofExponentPart .
Once the exact MV for a String numeric literal has been determined, it is then rounded to a value of the Number "-", in which case the rounded value is
-
it is not
0; or -
there is a nonzero digit to its left and there is a nonzero digit, not in the
ExponentPart , to its right.
7.1.4 ToInteger ( argument )
The abstract operation ToInteger converts argument to an integral numeric value. This abstract operation functions as follows:
7.1.5 ToInt32 ( argument )
The abstract operation ToInt32 converts argument to one of 232 integer values in the range
Given the above definition of ToInt32:
- The ToInt32 abstract operation is idempotent: if applied to a result that it produced, the second application leaves that value unchanged.
-
ToInt32(
ToUint32 (x)) is equal to ToInt32(x) for all values of x. (It is to preserve this latter property that+∞ and-∞ are mapped to+0 .) -
ToInt32 maps
-0 to+0 .
7.1.6 ToUint32 ( argument )
The abstract operation ToUint32 converts argument to one of 232 integer values in the range 0 through
Given the above definition of ToUint32:
-
Step 5 is the only difference between ToUint32 and
ToInt32 . - The ToUint32 abstract operation is idempotent: if applied to a result that it produced, the second application leaves that value unchanged.
-
ToUint32(
ToInt32 (x)) is equal to ToUint32(x) for all values of x. (It is to preserve this latter property that+∞ and-∞ are mapped to+0 .) -
ToUint32 maps
-0 to+0 .
7.1.7 ToInt16 ( argument )
The abstract operation ToInt16 converts argument to one of 216 integer values in the range -32768 through 32767, inclusive. This abstract operation functions as follows:
7.1.8 ToUint16 ( argument )
The abstract operation ToUint16 converts argument to one of 216 integer values in the range 0 through
Given the above definition of ToUint16:
-
The substitution of 216 for 232 in step 4 is the only difference between
ToUint32 and ToUint16. -
ToUint16 maps
-0 to+0 .
7.1.9 ToInt8 ( argument )
The abstract operation ToInt8 converts argument to one of 28 integer values in the range -128 through 127, inclusive. This abstract operation functions as follows:
7.1.10 ToUint8 ( argument )
The abstract operation ToUint8 converts argument to one of 28 integer values in the range 0 through 255, inclusive. This abstract operation functions as follows:
7.1.11 ToUint8Clamp ( argument )
The abstract operation ToUint8Clamp converts argument to one of 28 integer values in the range 0 through 255, inclusive. This abstract operation functions as follows:
Unlike the other ECMAScript integer conversion abstract operation, ToUint8Clamp rounds rather than truncates non-integer values and does not convert Math.round which does “round half up” tie-breaking.
7.1.12 ToString ( argument )
The abstract operation ToString converts argument to a value of
|
Argument |
Result |
|---|---|
| Undefined |
Return "undefined".
|
| Null |
Return "null".
|
| Boolean |
If argument is If argument is |
| Number |
See |
| String | Return argument. |
| Symbol |
Throw a |
| Object |
Apply the following steps:
|
7.1.12.1 ToString Applied to the Number Type
The abstract operation
- If m is
NaN , return the String"NaN". - If m is
+0 or-0 , return the String"0". - If m is less than zero, return the String concatenation of the String
"-"and !ToString (-m). - If m is
+∞ , return the String"Infinity". - Otherwise, let n, k, and s be integers such that k ≥ 1, 10k-1 ≤ s < 10k, the Number value for s × 10n-k is m, and k is as small as possible. Note that k is the number of digits in the decimal representation of s, that s is not divisible by 10, and that the least significant digit of s is not necessarily uniquely determined by these criteria.
- If k ≤ n ≤ 21, return the String consisting of the code units of the k digits of the decimal representation of s (in order, with no leading zeroes), followed by n-k occurrences of the code unit 0x0030 (DIGIT ZERO).
- If 0 < n ≤ 21, return the String consisting of the code units of the most significant n digits of the decimal representation of s, followed by the code unit 0x002E (FULL STOP), followed by the code units of the remaining k-n digits of the decimal representation of s.
- If -6 < n ≤ 0, return the String consisting of the code unit 0x0030 (DIGIT ZERO), followed by the code unit 0x002E (FULL STOP), followed by -n occurrences of the code unit 0x0030 (DIGIT ZERO), followed by the code units of the k digits of the decimal representation of s.
- Otherwise, if k = 1, return the String consisting of the code unit of the single digit of s, followed by code unit 0x0065 (LATIN SMALL LETTER E), followed by the code unit 0x002B (PLUS SIGN) or the code unit 0x002D (HYPHEN-MINUS) according to whether n-1 is positive or negative, followed by the code units of the decimal representation of the integer
abs (n-1) (with no leading zeroes). - Return the String consisting of the code units of the most significant digit of the decimal representation of s, followed by code unit 0x002E (FULL STOP), followed by the code units of the remaining k-1 digits of the decimal representation of s, followed by code unit 0x0065 (LATIN SMALL LETTER E), followed by code unit 0x002B (PLUS SIGN) or the code unit 0x002D (HYPHEN-MINUS) according to whether n-1 is positive or negative, followed by the code units of the decimal representation of the integer
abs (n-1) (with no leading zeroes).
The following observations may be useful as guidelines for implementations, but are not part of the normative requirements of this Standard:
For implementations that provide more accurate conversions than required by the rules above, it is recommended that the following alternative version of step 5 be used as a guideline:
Implementers of ECMAScript may find useful the paper and code written by David M. Gay for binary-to-decimal conversion of floating-point numbers:
Gay, David M. Correctly Rounded Binary-Decimal and Decimal-Binary Conversions. Numerical Analysis, Manuscript 90-10. AT&T Bell Laboratories (Murray Hill, New Jersey). November 30, 1990. Available as
http://ampl.com/REFS/abstracts.html#rounding. Associated code available as
http://netlib.sandia.gov/fp/dtoa.c and as
http://netlib.sandia.gov/fp/g_fmt.c and may also be found at the various netlib mirror sites.
7.1.13 ToObject ( argument )
The abstract operation ToObject converts argument to a value of
|
Argument |
Result |
|---|---|
| Undefined |
Throw a |
| Null |
Throw a |
| Boolean |
Return a new Boolean object whose [[BooleanData]] internal slot is set to argument. See |
| Number |
Return a new Number object whose [[NumberData]] internal slot is set to argument. See |
| String |
Return a new String object whose [[StringData]] internal slot is set to argument. See |
| Symbol |
Return a new Symbol object whose [[SymbolData]] internal slot is set to argument. See |
| Object | Return argument. |
7.1.14 ToPropertyKey ( argument )
The abstract operation ToPropertyKey converts argument to a value that can be used as a property key by performing the following steps:
- Let key be ?
ToPrimitive (argument, hint String). - If
Type (key) is Symbol, then- Return key.
- Return !
ToString (key).
7.1.15 ToLength ( argument )
7.1.16 CanonicalNumericIndexString ( argument )
The abstract operation CanonicalNumericIndexString returns argument converted to a numeric value if it is a String representation of a Number that would be produced by "-0". Otherwise, it returns
A canonical numeric string is any String value for which the CanonicalNumericIndexString abstract operation does not return
7.1.17 ToIndex ( value )
The abstract operation ToIndex returns value argument converted to a numeric value if it is a valid integer index value. This abstract operation functions as follows:
- If value is
undefined , then- Let index be 0.
- Else,
- Let integerIndex be ?
ToInteger (value). - If integerIndex < 0, throw a
RangeError exception. - Let index be !
ToLength (integerIndex). - If
SameValueZero (integerIndex, index) isfalse , throw aRangeError exception.
- Let integerIndex be ?
- Return index.
7.2 Testing and Comparison Operations
7.2.1 RequireObjectCoercible ( argument )
The abstract operation RequireObjectCoercible throws an error if argument is a value that cannot be converted to an Object using
|
Argument |
Result |
|---|---|
| Undefined |
Throw a |
| Null |
Throw a |
| Boolean | Return argument. |
| Number | Return argument. |
| String | Return argument. |
| Symbol | Return argument. |
| Object | Return argument. |
7.2.2 IsArray ( argument )
The abstract operation IsArray takes one argument argument, and performs the following steps:
- If
Type (argument) is not Object, returnfalse . - If argument is an Array exotic object, return
true . - If argument is a Proxy exotic object, then
- If argument.[[ProxyHandler]] is
null , throw aTypeError exception. - Let target be argument.[[ProxyTarget]].
- Return ? IsArray(target).
- If argument.[[ProxyHandler]] is
- Return
false .
7.2.3 IsCallable ( argument )
The abstract operation IsCallable determines if argument, which must be an
- If
Type (argument) is not Object, returnfalse . - If argument has a [[Call]] internal method, return
true . - Return
false .
7.2.4 IsConstructor ( argument )
The abstract operation IsConstructor determines if argument, which must be an
- If
Type (argument) is not Object, returnfalse . - If argument has a [[Construct]] internal method, return
true . - Return
false .
7.2.5 IsExtensible ( O )
7.2.6 IsInteger ( argument )
7.2.7 IsPropertyKey ( argument )
The abstract operation IsPropertyKey determines if argument, which must be an
7.2.8 IsRegExp ( argument )
The abstract operation IsRegExp with argument argument performs the following steps:
7.2.9 SameValue ( x, y )
The internal comparison abstract operation SameValue(x, y), where x and y are ECMAScript language values, produces
- If
Type (x) is different fromType (y), returnfalse . - If
Type (x) is Number, then- If x is
NaN and y isNaN , returntrue . - If x is
+0 and y is-0 , returnfalse . - If x is
-0 and y is+0 , returnfalse . - If x is the same Number value as y, return
true . - Return
false .
- If x is
- Return
SameValueNonNumber (x, y).
This algorithm differs from the
7.2.10 SameValueZero ( x, y )
The internal comparison abstract operation SameValueZero(x, y), where x and y are ECMAScript language values, produces
- If
Type (x) is different fromType (y), returnfalse . - If
Type (x) is Number, then- If x is
NaN and y isNaN , returntrue . - If x is
+0 and y is-0 , returntrue . - If x is
-0 and y is+0 , returntrue . - If x is the same Number value as y, return
true . - Return
false .
- If x is
- Return
SameValueNonNumber (x, y).
SameValueZero differs from
7.2.11 SameValueNonNumber ( x, y )
The internal comparison abstract operation SameValueNonNumber(x, y), where neither x nor y are Number values, produces
Assert :Type (x) is not Number.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.12 Abstract Relational Comparison
The comparison x < y, where x and y are values, produces
- If the LeftFirst flag is
true , then- Let px be ?
ToPrimitive (x, hint Number). - Let py be ?
ToPrimitive (y, hint Number).
- Let px be ?
- Else the order of evaluation needs to be reversed to preserve left to right evaluation,
- Let py be ?
ToPrimitive (y, hint Number). - Let px be ?
ToPrimitive (x, hint Number).
- Let py be ?
- If both px and py are Strings, then
- If py is a prefix of px, return
false . (A String value p is a prefix of String value q if q can be the result of concatenating p and some other String r. Note that any String is a prefix of itself, because r may be the empty String.) - If px is a prefix of py, return
true . - Let k be the smallest nonnegative integer such that the code unit at index k within px is different from the code unit at index k within py. (There must be such a k, for neither String is a prefix of the other.)
- Let m be the integer that is the code unit value at index k within px.
- Let n be the integer that is the code unit value at index k within py.
- If m < n, return
true . Otherwise, returnfalse .
- If py is a prefix of px, return
- Else,
- Let nx be ?
ToNumber (px). Because px and py are primitive values evaluation order is not important. - Let ny be ?
ToNumber (py). - If nx is
NaN , returnundefined . - If ny is
NaN , returnundefined . - If nx and ny are the same Number value, return
false . - If nx is
+0 and ny is-0 , returnfalse . - If nx is
-0 and ny is+0 , returnfalse . - If nx is
+∞ , returnfalse . - If ny is
+∞ , returntrue . - If ny is
-∞ , returnfalse . - If nx is
-∞ , returntrue . - If the mathematical value of nx is less than the mathematical value of ny —note that these mathematical values are both finite and not both zero—return
true . Otherwise, returnfalse .
- Let nx be ?
Step 3 differs from step 7 in the algorithm for the addition operator + (
The comparison of Strings uses a simple lexicographic ordering on sequences of code unit values. There is no attempt to use the more complex, semantically oriented definitions of character or string equality and collating order defined in the Unicode specification. Therefore String values that are canonically equal according to the Unicode standard could test as unequal. In effect this algorithm assumes that both Strings are already in normalized form. Also, note that for strings containing supplementary characters, lexicographic ordering on sequences of UTF-16 code unit values differs from that on sequences of code point values.
7.2.13 Abstract Equality Comparison
The comparison x == y, where x and y are values, produces
- If
Type (x) is the same asType (y), then- Return the result of performing
Strict Equality Comparison x === y.
- Return the result of performing
- If x is
null and y isundefined , returntrue . - If x is
undefined and y isnull , returntrue . - If
Type (x) is Number andType (y) is String, return the result of the comparison x ==ToNumber (y). - If
Type (x) is String andType (y) is Number, return the result of the comparisonToNumber (x) == y. - If
Type (x) is Boolean, return the result of the comparisonToNumber (x) == y. - If
Type (y) is Boolean, return the result of the comparison x ==ToNumber (y). - If
Type (x) is either String, Number, or Symbol andType (y) is Object, return the result of the comparison x ==ToPrimitive (y). - If
Type (x) is Object andType (y) is either String, Number, or Symbol, return the result of the comparisonToPrimitive (x) == y. - Return
false .
7.2.14 Strict Equality Comparison
The comparison x === y, where x and y are values, produces
- If
Type (x) is different fromType (y), returnfalse . - If
Type (x) is Number, then- If x is
NaN , returnfalse . - If y is
NaN , returnfalse . - If x is the same Number value as y, return
true . - If x is
+0 and y is-0 , returntrue . - If x is
-0 and y is+0 , returntrue . - Return
false .
- If x is
- Return
SameValueNonNumber (x, y).
This algorithm differs from the
7.3 Operations on Objects
7.3.1 Get ( O, P )
The abstract operation Get is used to retrieve the value of a specific property of an object. The operation is called with arguments O and P where O is the object and P is the property key. This abstract operation performs the following steps:
Assert :Type (O) is Object.Assert :IsPropertyKey (P) istrue .- Return ? O.[[Get]](P, O).
7.3.2 GetV ( V, P )
The abstract operation GetV is used to retrieve the value of a specific property of an
Assert :IsPropertyKey (P) istrue .- Let O be ?
ToObject (V). - Return ? O.[[Get]](P, V).
7.3.3 Set ( O, P, V, Throw )
The abstract operation
7.3.4 CreateDataProperty ( O, P, V )
The abstract operation CreateDataProperty is used to create a new own property of an object. The operation is called with arguments O, P, and V where O is the object, P is the property key, and V is the value for the property. This abstract operation performs the following steps:
Assert :Type (O) is Object.Assert :IsPropertyKey (P) istrue .- Let newDesc be the PropertyDescriptor{[[Value]]: V, [[Writable]]:
true , [[Enumerable]]:true , [[Configurable]]:true }. - Return ? O.[[DefineOwnProperty]](P, newDesc).
This abstract operation creates a property whose attributes are set to the same defaults used for properties created by the ECMAScript language assignment operator. Normally, the property will not already exist. If it does exist and is not configurable or if O is not extensible, [[DefineOwnProperty]] will return
7.3.5 CreateMethodProperty ( O, P, V )
The abstract operation CreateMethodProperty is used to create a new own property of an object. The operation is called with arguments O, P, and V where O is the object, P is the property key, and V is the value for the property. This abstract operation performs the following steps:
Assert :Type (O) is Object.Assert :IsPropertyKey (P) istrue .- Let newDesc be the PropertyDescriptor{[[Value]]: V, [[Writable]]:
true , [[Enumerable]]:false , [[Configurable]]:true }. - Return ? O.[[DefineOwnProperty]](P, newDesc).
This abstract operation creates a property whose attributes are set to the same defaults used for built-in methods and methods defined using class declaration syntax. Normally, the property will not already exist. If it does exist and is not configurable or if O is not extensible, [[DefineOwnProperty]] will return
7.3.6 CreateDataPropertyOrThrow ( O, P, V )
The abstract operation CreateDataPropertyOrThrow is used to create a new own property of an object. It throws a
Assert :Type (O) is Object.Assert :IsPropertyKey (P) istrue .- Let success be ?
CreateDataProperty (O, P, V). - If success is
false , throw aTypeError exception. - Return success.
This abstract operation creates a property whose attributes are set to the same defaults used for properties created by the ECMAScript language assignment operator. Normally, the property will not already exist. If it does exist and is not configurable or if O is not extensible, [[DefineOwnProperty]] will return
7.3.7 DefinePropertyOrThrow ( O, P, desc )
The abstract operation DefinePropertyOrThrow is used to call the [[DefineOwnProperty]] internal method of an object in a manner that will throw a
Assert :Type (O) is Object.Assert :IsPropertyKey (P) istrue .- Let success be ? O.[[DefineOwnProperty]](P, desc).
- If success is
false , throw aTypeError exception. - Return success.
7.3.8 DeletePropertyOrThrow ( O, P )
The abstract operation DeletePropertyOrThrow is used to remove a specific own property of an object. It throws an exception if the property is not configurable. The operation is called with arguments O and P where O is the object and P is the property key. This abstract operation performs the following steps:
Assert :Type (O) is Object.Assert :IsPropertyKey (P) istrue .- Let success be ? O.[[Delete]](P).
- If success is
false , throw aTypeError exception. - Return success.
7.3.9 GetMethod ( V, P )
The abstract operation GetMethod is used to get the value of a specific property of an
Assert :IsPropertyKey (P) istrue .- Let func be ?
GetV (V, P). - If func is either
undefined ornull , returnundefined . - If
IsCallable (func) isfalse , throw aTypeError exception. - Return func.
7.3.10 HasProperty ( O, P )
The abstract operation HasProperty is used to determine whether an object has a property with the specified property key. The property may be either an own or inherited. A Boolean value is returned. The operation is called with arguments O and P where O is the object and P is the property key. This abstract operation performs the following steps:
Assert :Type (O) is Object.Assert :IsPropertyKey (P) istrue .- Return ? O.[[HasProperty]](P).
7.3.11 HasOwnProperty ( O, P )
The abstract operation HasOwnProperty is used to determine whether an object has an own property with the specified property key. A Boolean value is returned. The operation is called with arguments O and P where O is the object and P is the property key. This abstract operation performs the following steps:
Assert :Type (O) is Object.Assert :IsPropertyKey (P) istrue .- Let desc be ? O.[[GetOwnProperty]](P).
- If desc is
undefined , returnfalse . - Return
true .
7.3.12 Call ( F, V [ , argumentsList ] )
The abstract operation Call is used to call the [[Call]] internal method of a function object. The operation is called with arguments F, V, and optionally argumentsList where F is the function object, V is an
- If argumentsList was not passed, set argumentsList to a new empty
List . - If
IsCallable (F) isfalse , throw aTypeError exception. - Return ? F.[[Call]](V, argumentsList).
7.3.13 Construct ( F [ , argumentsList [ , newTarget ]] )
The abstract operation Construct is used to call the [[Construct]] internal method of a function object. The operation is called with arguments F, and optionally argumentsList, and newTarget where F is the function object. argumentsList and newTarget are the values to be passed as the corresponding arguments of the internal method. If argumentsList is not present, a new empty
- If newTarget was not passed, set newTarget to F.
- If argumentsList was not passed, set argumentsList to a new empty
List . Assert :IsConstructor (F) istrue .Assert :IsConstructor (newTarget) istrue .- Return ? F.[[Construct]](argumentsList, newTarget).
If newTarget is not passed, this operation is equivalent to: new F(...argumentsList)
7.3.14 SetIntegrityLevel ( O, level )
The abstract operation SetIntegrityLevel is used to fix the set of own properties of an object. This abstract operation performs the following steps:
Assert :Type (O) is Object.Assert : level is either"sealed"or"frozen".- 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 level is
"frozen",- 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
- For each element k of keys, do
- Return
true .
7.3.15 TestIntegrityLevel ( O, level )
The abstract operation TestIntegrityLevel is used to determine if the set of own properties of an object are fixed. This abstract operation performs the following steps:
Assert :Type (O) is Object.Assert : level is either"sealed"or"frozen".- Let status be ?
IsExtensible (O). - If status 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.16 CreateArrayFromList ( elements )
The abstract operation CreateArrayFromList is used to create an Array object whose elements are provided by a
Assert : elements is aList whose elements are all ECMAScript language values.- Let array be !
ArrayCreate (0). - Let n be 0.
- For each element e of elements, do
- Let status be
CreateDataProperty (array, !ToString (n), e). Assert : status istrue .- Increment n by 1.
- Let status be
- Return array.
7.3.17 CreateListFromArrayLike ( obj [ , elementTypes ] )
The abstract operation CreateListFromArrayLike is used to create a
7.3.18 Invoke ( V, P [ , argumentsList ] )
The abstract operation Invoke is used to call a method property of an
Assert :IsPropertyKey (P) istrue .- If argumentsList was not passed, set argumentsList to a new empty
List . - Let func be ?
GetV (V, P). - Return ?
Call (func, V, argumentsList).
7.3.19 OrdinaryHasInstance ( C, O )
The abstract operation OrdinaryHasInstance implements the default algorithm for determining if an object O inherits from the instance object inheritance path provided by constructor C. This abstract operation performs the following steps:
- If
IsCallable (C) isfalse , returnfalse . - If C has a [[BoundTargetFunction]] internal slot, then
- Let BC be C.[[BoundTargetFunction]].
- Return ?
InstanceofOperator (O, BC).
- If
Type (O) is not Object, returnfalse . - Let P be ?
Get (C,"prototype"). - If
Type (P) is not Object, throw aTypeError exception. - Repeat,
7.3.20 SpeciesConstructor ( O, defaultConstructor )
The abstract operation SpeciesConstructor is used to retrieve the constructor that should be used to create new objects that are derived from the argument object O. The defaultConstructor argument is the constructor to use if a constructor @@species property cannot be found starting from O. This abstract operation performs the following steps:
Assert :Type (O) is Object.- Let C be ?
Get (O,"constructor"). - If C is
undefined , return defaultConstructor. - If
Type (C) is not Object, throw aTypeError exception. - Let S be ?
Get (C, @@species). - If S is either
undefined ornull , return defaultConstructor. - If
IsConstructor (S) istrue , return S. - Throw a
TypeError exception.
7.3.21 EnumerableOwnProperties ( O, kind )
When the abstract operation EnumerableOwnProperties is called with Object O and String kind the following steps are taken:
Assert :Type (O) is Object.- Let ownKeys be ? O.[[OwnPropertyKeys]]().
- Let properties be a new empty
List . - For each element key of ownKeys in
List order, do- If
Type (key) is String, then- Let desc be ? O.[[GetOwnProperty]](key).
- If desc is not
undefined and desc.[[Enumerable]] istrue , then- If kind is
"key" , append key to properties. - Else,
- Let value be ?
Get (O, key). - If kind is
"value" , append value to properties. - Else,
Assert : kind is"key+value" .- Let entry be
CreateArrayFromList (« key, value »). - Append entry to properties.
- Let value be ?
- If kind is
- If
- Order the elements of properties so they are in the same relative order as would be produced by the Iterator that would be returned if the
EnumerateObjectProperties internal method were invoked with O. - Return properties.
7.3.22 GetFunctionRealm ( obj )
The abstract operation GetFunctionRealm with argument obj performs the following steps:
Assert : obj is a callable object.- If obj has a [[Realm]] internal slot, then
- Return obj.[[Realm]].
- If obj is a Bound Function exotic object, then
- Let target be obj.[[BoundTargetFunction]].
- Return ? GetFunctionRealm(target).
- If obj is a Proxy exotic object, then
- If obj.[[ProxyHandler]] is
null , throw aTypeError exception. - Let proxyTarget be obj.[[ProxyTarget]].
- Return ? GetFunctionRealm(proxyTarget).
- If obj.[[ProxyHandler]] is
- Return
the current Realm Record .
Step 5 will only be reached if target is a non-standard function exotic object that does not have a [[Realm]] internal slot.
7.4 Operations on Iterator Objects
See Common Iteration Interfaces (
7.4.1 GetIterator ( obj [ , method ] )
7.4.2 IteratorNext ( iterator [ , value ] )
The abstract operation IteratorNext with argument iterator and optional argument value performs the following steps:
7.4.3 IteratorComplete ( iterResult )
7.4.4 IteratorValue ( iterResult )
7.4.5 IteratorStep ( iterator )
The abstract operation IteratorStep with argument iterator requests the next value from iterator and returns either
- Let result be ?
IteratorNext (iterator). - Let done be ?
IteratorComplete (result). - If done is
true , returnfalse . - Return result.
7.4.6 IteratorClose ( iterator, completion )
The abstract operation IteratorClose with arguments iterator and completion is used to notify an iterator that it should perform any actions it would normally perform when it has reached its completed state:
Assert :Type (iterator) is Object.Assert : completion is aCompletion Record .- Let return be ?
GetMethod (iterator,"return"). - If return is
undefined , returnCompletion (completion). - Let innerResult be
Call (return, iterator, « »). - If completion.[[Type]] is
throw , returnCompletion (completion). - If innerResult.[[Type]] is
throw , returnCompletion (innerResult). - If
Type (innerResult.[[Value]]) is not Object, throw aTypeError exception. - Return
Completion (completion).
7.4.7 CreateIterResultObject ( value, done )
The abstract operation CreateIterResultObject with arguments value and done creates an object that supports the IteratorResult interface by performing the following steps:
Assert :Type (done) is Boolean.- Let obj be
ObjectCreate (%ObjectPrototype% ). - Perform
CreateDataProperty (obj,"value", value). - Perform
CreateDataProperty (obj,"done", done). - Return obj.
7.4.8 CreateListIterator ( list )
The abstract operation CreateListIterator with argument list creates an Iterator (
- Let iterator be
ObjectCreate (%IteratorPrototype% , « [[IteratedList]], [[ListIteratorNextIndex]] »). Set iterator.[[IteratedList]] to list.Set iterator.[[ListIteratorNextIndex]] to 0.- Let next be a new built-in function object as defined in ListIterator
next(7.4.8.1 ). - Perform
CreateMethodProperty (iterator,"next", next). - Return iterator.
The list iterator object is never directly accessible to ECMAScript code.
7.4.8.1 ListIterator next( )
The ListIterator next method is a standard built-in function object (clause
- Let O be the
this value. Assert :Type (O) is Object.Assert : O has an [[IteratedList]] internal slot.- Let list be O.[[IteratedList]].
- Let index be O.[[ListIteratorNextIndex]].
- Let len be the number of elements of list.
- If index ≥ len, then
- Return
CreateIterResultObject (undefined ,true ).
- Return
Set O.[[ListIteratorNextIndex]] to index+1.- Return
CreateIterResultObject (list[index],false ).