ECMA-262 (12th Edition) ECMAScript 2021 Language Specification - page 15

 

  Главная      Manuals     ECMA-262 (12th Edition) ECMAScript 2021 Language Specification

 

Search            copyright infringement  

 

 

 

 

 

 

 

 

 

 

 

Content      ..     13      14      15      16     ..

 

 

 

ECMA-262 (12th Edition) ECMAScript 2021 Language Specification - page 15

 

 

Table 15: 

ToObject

 Conversions

Argument

Type

Result

Undefined

Throw a 

TypeError

 exception.

Null

Throw a 

TypeError

 exception.

Boolean

Return a new Boolean object whose [[BooleanData]] internal slot is set to 

argument

. See 

20.3

 for a

description of Boolean objects.

Number

Return a new Number object whose [[NumberData]] internal slot is set to 

argument

. See 

21.1

 for a

description of Number objects.

String

Return a new String object whose [[StringData]] internal slot is set to 

argument

. See 

22.1

 for a

description of String objects.

Symbol

Return a new Symbol object whose [[SymbolData]] internal slot is set to 

argument

. See 

20.4

 for a

description of Symbol objects.

BigInt

Return a new BigInt object whose [[BigIntData]] internal slot is set to 

argument

. See 

21.2

 for a

description of BigInt objects.

Object

Return 

argument

.

The abstract operation ToPropertyKey takes argument 

argument

. It converts 

argument

 to a value that can be used as a

property key. It performs the following steps when called:

1.  Let 

key

 be ? 

ToPrimitive

(

argument

string

).

2.  If 

Type

(

key

) is Symbol, then

a.  Return 

key

.

3.  Return ! 

ToString

(

key

).

The abstract operation ToLength takes argument 

argument

. It converts 

argument

 to an 

integral Number

 suitable for use

as the length of an 

array-like object

. It performs the following steps when called:

1.  Let 

len

 be ? 

ToIntegerOrInfinity

(

argument

).

2.  If 

len

 

 0, return 

+0

𝔽

.

3.  Return 

min

(

len

, 2

53

 - 1)).

The abstract operation CanonicalNumericIndexString takes argument 

argument

. It returns 

argument

 converted to a

Number value

 if it is a String representation of a Number that would be produced by 

ToString

, or the string 

"-0"

.

Otherwise, it returns 

undefined

. It performs the following steps when called:

7.1.19  ToPropertyKey ( 

argument

 )

7.1.20  ToLength ( 

argument

 )

7.1.21  CanonicalNumericIndexString ( 

argument

 )

122

1. 

Assert

Type

(

argument

) is String.

2.  If 

argument

 is 

"-0"

, return 

-0

𝔽

.

3.  Let 

n

 be ! 

ToNumber

(

argument

).

4.  If 

SameValue

(! 

ToString

(

n

), 

argument

) is 

false

, return 

undefined

.

5.  Return 

n

.

canonical numeric string

 is any String value for which the CanonicalNumericIndexString abstract operation does not

return 

undefined

.

The abstract operation ToIndex takes argument 

value

. It returns 

value

 argument converted to a non-negative 

integer

 if

it is a valid 

integer index

 value. It performs the following steps when called:

1.  If 

value

 is 

undefined

, then

a.  Return 0.

2.  Else,

a.  Let 

integerIndex

 be 

ToIntegerOrInfinity

(

value

)).

b.  If 

integerIndex

 < 

+0

𝔽

, throw a 

RangeError

 exception.

c.  Let 

index

 be ! 

ToLength

(

integerIndex

).

d.  If ! 

SameValue

(

integerIndex

index

) is 

false

, throw a 

RangeError

 exception.

e.  Return 

index

).

The abstract operation RequireObjectCoercible takes argument 

argument

. It throws an error if 

argument

 is a value that

cannot be converted to an Object using 

ToObject

. It is defined by 

Table 16

:

Table 16: 

RequireObjectCoercible

 Results

Argument Type

Result

Undefined

Throw a 

TypeError

 exception.

Null

Throw a 

TypeError

 exception.

Boolean

Return 

argument

.

Number

Return 

argument

.

String

Return 

argument

.

Symbol

Return 

argument

.

BigInt

Return 

argument

.

Object

Return 

argument

.

7.1.22  ToIndex ( 

value

 )

7.2  Testing and Comparison Operations

7.2.1  RequireObjectCoercible ( 

argument

 )

123

The abstract operation IsArray takes argument 

argument

. It performs the following steps when called:

1.  If 

Type

(

argument

) is not Object, return 

false

.

2.  If 

argument

 is an 

Array exotic object

, return 

true

.

3.  If 

argument

 is a 

Proxy exotic object

, then

a.  If 

argument

.[[ProxyHandler]] is 

null

, throw a 

TypeError

 exception.

b.  Let 

target

 be 

argument

.[[ProxyTarget]].

c.  Return ? 

IsArray

(

target

).

4.  Return 

false

.

The abstract operation IsCallable takes argument 

argument

 (an 

ECMAScript language value

). It determines if 

argument

is a callable function with a [[Call]] internal method. It performs the following steps when called:

1.  If 

Type

(

argument

) is not Object, return 

false

.

2.  If 

argument

 has a [[Call]] internal method, return 

true

.

3.  Return 

false

.

The abstract operation IsConstructor takes argument 

argument

 (an 

ECMAScript language value

). It determines if

argument

 is a 

function object

 with a [[Construct]] internal method. It performs the following steps when called:

1.  If 

Type

(

argument

) is not Object, return 

false

.

2.  If 

argument

 has a [[Construct]] internal method, return 

true

.

3.  Return 

false

.

The abstract operation IsExtensible takes argument 

O

 (an Object) and returns a completion record which, if its [[Type]]

is 

normal

, has a [[Value]] which is a Boolean. It is used to determine whether additional properties can be added to 

O

.

It performs the following steps when called:

1. 

Assert

Type

(

O

) is Object.

2.  Return ? 

O

.[[IsExtensible]]().

The abstract operation IsIntegralNumber takes argument 

argument

. It determines if 

argument

 is a finite 

integral

Number

 value. It performs the following steps when called:

1.  If 

Type

(

argument

) is not Number, return 

false

.

2.  If 

argument

 is 

NaN

+

𝔽

, or 

-

𝔽

, return 

false

.

3.  If 

floor

(

abs

argument

))) 

 

abs

argument

)), return 

false

.

4.  Return 

true

.

7.2.2  IsArray ( 

argument

 )

7.2.3  IsCallable ( 

argument

 )

7.2.4  IsConstructor ( 

argument

 )

7.2.5  IsExtensible ( 

O

 )

7.2.6  IsIntegralNumber ( 

argument

 )

124

The abstract operation IsPropertyKey takes argument 

argument

 (an 

ECMAScript language value

). It determines if

argument

 is a value that may be used as a property key. It performs the following steps when called:

1.  If 

Type

(

argument

) is String, return 

true

.

2.  If 

Type

(

argument

) is Symbol, return 

true

.

3.  Return 

false

.

The abstract operation IsRegExp takes argument 

argument

. It performs the following steps when called:

1.  If 

Type

(

argument

) is not Object, return 

false

.

2.  Let 

matcher

 be ? 

Get

(

argument

@@match

).

3.  If 

matcher

 is not 

undefined

, return ! 

ToBoolean

(

matcher

).

4.  If 

argument

 has a [[RegExpMatcher]] internal slot, return 

true

.

5.  Return 

false

.

The abstract operation IsStringPrefix takes arguments 

p

 (a String) and 

q

 (a String). It determines if 

p

 is a prefix of 

q

. It

performs the following steps when called:

1. 

Assert

Type

(

p

) is String.

2. 

Assert

Type

(

q

) is String.

3.  If 

q

 can be the 

string-concatenation

 of 

p

 and some other String 

r

, return 

true

. Otherwise, return 

false

.

NOTE

The abstract operation SameValue takes arguments 

x

 (an 

ECMAScript language value

) and 

y

 (an 

ECMAScript

language value

) and returns a completion record whose [[Type]] is 

normal

 and whose [[Value]] is a Boolean. It

performs the following steps when called:

1.  If 

Type

(

x

) is different from 

Type

(

y

), return 

false

.

2.  If 

Type

(

x

) is Number or BigInt, then

a.  Return ! 

Type

(

x

)::sameValue(

x

y

).

3.  Return ! 

SameValueNonNumeric

(

x

y

).

NOTE

The abstract operation SameValueZero takes arguments 

x

 (an 

ECMAScript language value

) and 

y

 (an 

ECMAScript

Any String is a prefix of itself, because 

r

 may be the empty String.

This algorithm differs from the 

Strict Equality Comparison

 Algorithm in its treatment of signed

zeroes and NaNs.

7.2.7  IsPropertyKey ( 

argument

 )

7.2.8  IsRegExp ( 

argument

 )

7.2.9  IsStringPrefix ( 

p

q

 )

7.2.10  SameValue ( 

x

y

 )

7.2.11  SameValueZero ( 

x

y

 )

125

language value

) and returns a completion record whose [[Type]] is 

normal

 and whose [[Value]] is a Boolean. It

performs the following steps when called:

1.  If 

Type

(

x

) is different from 

Type

(

y

), return 

false

.

2.  If 

Type

(

x

) is Number or BigInt, then

a.  Return ! 

Type

(

x

)::sameValueZero(

x

y

).

3.  Return ! 

SameValueNonNumeric

(

x

y

).

NOTE

The abstract operation SameValueNonNumeric takes arguments 

x

 (an 

ECMAScript language value

) and 

y

 (an

ECMAScript language value

) and returns a completion record whose [[Type]] is 

normal

 and whose [[Value]] is a

Boolean. It performs the following steps when called:

1. 

Assert

Type

(

x

) is not Number or BigInt.

2. 

Assert

Type

(

x

) is the same as 

Type

(

y

).

3.  If 

Type

(

x

) is Undefined, return 

true

.

4.  If 

Type

(

x

) is Null, return 

true

.

5.  If 

Type

(

x

) is String, then

a.  If 

x

 and 

y

 are exactly the same sequence of code units (same length and same code units at

corresponding indices), return 

true

; otherwise, return 

false

.

6.  If 

Type

(

x

) is Boolean, then

a.  If 

x

 and 

y

 are both 

true

 or both 

false

, return 

true

; otherwise, return 

false

.

7.  If 

Type

(

x

) is Symbol, then

a.  If 

x

 and 

y

 are both the same Symbol value, return 

true

; otherwise, return 

false

.

8.  If 

x

 and 

y

 are the same Object value, return 

true

. Otherwise, return 

false

.

The comparison 

x

 < 

y

, where 

x

 and 

y

 are values, produces 

true

false

, or 

undefined

 (which indicates that at least one

operand is 

NaN

). In addition to 

x

 and 

y

 the algorithm takes a Boolean flag named 

LeftFirst

 as a parameter. The flag is

used to control the order in which operations with potentially visible side-effects are performed upon 

x

 and 

y

. It is

necessary because ECMAScript specifies left to right evaluation of expressions. The default value of 

LeftFirst

 is 

true

and indicates that the 

x

 parameter corresponds to an expression that occurs to the left of the 

y

 parameter's

corresponding expression. If 

LeftFirst

 is 

false

, the reverse is the case and operations must be performed upon 

y

 before

x

. Such a comparison is performed as follows:

1.  If the 

LeftFirst

 flag is 

true

, then

a.  Let 

px

 be ? 

ToPrimitive

(

x

number

).

b.  Let 

py

 be ? 

ToPrimitive

(

y

number

).

2.  Else,

a.  NOTE: The order of evaluation needs to be reversed to preserve left to right evaluation.

b.  Let 

py

 be ? 

ToPrimitive

(

y

number

).

c.  Let 

px

 be ? 

ToPrimitive

(

x

number

).

3.  If 

Type

(

px

) is String and 

Type

(

py

) is String, then

SameValueZero differs from 

SameValue

 only in its treatment of 

+0

𝔽

 and 

-0

𝔽

.

7.2.12  SameValueNonNumeric ( 

x

y

 )

7.2.13  Abstract Relational Comparison

126

a.  If 

IsStringPrefix

(

py

px

) is 

true

, return 

false

.

b.  If 

IsStringPrefix

(

px

py

) is 

true

, return 

true

.

c.  Let 

k

 be the smallest non-negative 

integer

 such that the code unit at index 

k

 within 

px

 is different from

the code unit at index 

k

 within 

py

. (There must be such a 

k

, for neither String is a prefix of the other.)

d.  Let 

m

 be the 

integer

 that is the numeric value of the code unit at index 

k

 within 

px

.

e.  Let 

n

 be the 

integer

 that is the numeric value of the code unit at index 

k

 within 

py

.

f.  If 

m

 < 

n

, return 

true

. Otherwise, return 

false

.

4.  Else,

a.  If 

Type

(

px

) is BigInt and 

Type

(

py

) is String, then

i.  Let 

ny

 be ! 

StringToBigInt

(

py

).

ii.  If 

ny

 is 

NaN

, return 

undefined

.

iii.  Return BigInt::lessThan(

px

ny

).

b.  If 

Type

(

px

) is String and 

Type

(

py

) is BigInt, then

i.  Let 

nx

 be ! 

StringToBigInt

(

px

).

ii.  If 

nx

 is 

NaN

, return 

undefined

.

iii.  Return BigInt::lessThan(

nx

py

).

c.  NOTE: Because 

px

 and 

py

 are primitive values, evaluation order is not important.

d.  Let 

nx

 be ! 

ToNumeric

(

px

).

e.  Let 

ny

 be ! 

ToNumeric

(

py

).

f.  If 

Type

(

nx

) is the same as 

Type

(

ny

), return 

Type

(

nx

)::lessThan(

nx

ny

).

g. 

Assert

Type

(

nx

) is BigInt and 

Type

(

ny

) is Number, or 

Type

(

nx

) is Number and 

Type

(

ny

) is BigInt.

h.  If 

nx

 or 

ny

 is 

NaN

, return 

undefined

.

i.  If 

nx

 is 

-

𝔽

 or 

ny

 is 

+

𝔽

, return 

true

.

j.  If 

nx

 is 

+

𝔽

 or 

ny

 is 

-

𝔽

, return 

false

.

nx

) < 

(

ny

), return 

true

; otherwise return 

false

.

NOTE 1

NOTE 2

The comparison 

x

 == 

y

, where 

x

 and 

y

 are values, produces 

true

 or 

false

. Such a comparison is performed as follows:

1.  If 

Type

(

x

) is the same as 

Type

(

y

), then

a.  Return the result of performing 

Strict Equality Comparison

 

x

 === 

y

.

2.  If 

x

 is 

null

 and 

y

 is 

undefined

, return 

true

.

3.  If 

x

 is 

undefined

 and 

y

 is 

null

, return 

true

.

4.  NOTE: This step is replaced in section 

B.3.7.2

.

Step 

3

 differs from step 

2.c

 in the algorithm that handles the addition operator 

++

 (

13.15.3

) by

using the logical-and operation instead of the logical-or operation.

The comparison of Strings uses a simple lexicographic ordering on sequences of code unit values.
There is no attempt to use the more complex, semantically oriented definitions of character or
string equality and collating order defined in the Unicode specification. Therefore String values
that are canonically equal according to the Unicode standard could test as unequal. In effect this
algorithm assumes that both Strings are already in normalized form. Also, note that for strings
containing supplementary characters, lexicographic ordering on sequences of UTF-16 code unit
values differs from that on sequences of code point values.

7.2.14  Abstract Equality Comparison

127

5.  If 

Type

(

x

) is Number and 

Type

(

y

) is String, return the result of the comparison 

x

 == ! 

ToNumber

(

y

).

6.  If 

Type

(

x

) is String and 

Type

(

y

) is Number, return the result of the comparison ! 

ToNumber

(

x

) == 

y

.

7.  If 

Type

(

x

) is BigInt and 

Type

(

y

) is String, then

a.  Let 

n

 be ! 

StringToBigInt

(

y

).

b.  If 

n

 is 

NaN

, return 

false

.

c.  Return the result of the comparison 

x

 == 

n

.

8.  If 

Type

(

x

) is String and 

Type

(

y

) is BigInt, return the result of the comparison 

y

 == 

x

.

9.  If 

Type

(

x

) is Boolean, return the result of the comparison ! 

ToNumber

(

x

) == 

y

.

10.  If 

Type

(

y

) is Boolean, return the result of the comparison 

x

 == ! 

ToNumber

(

y

).

11.  If 

Type

(

x

) is either String, Number, BigInt, or Symbol and 

Type

(

y

) is Object, return the result of the comparison

x

 == ? 

ToPrimitive

(

y

).

12.  If 

Type

(

x

) is Object and 

Type

(

y

) is either String, Number, BigInt, or Symbol, return the result of the comparison

ToPrimitive

(

x

) == 

y

.

13.  If 

Type

(

x

) is BigInt and 

Type

(

y

) is Number, or if 

Type

(

x

) is Number and 

Type

(

y

) is BigInt, then

a.  If 

x

 or 

y

 are any of 

NaN

+

𝔽

, or 

-

𝔽

, return 

false

.

x

y

), return 

true

; otherwise return 

false

.

14.  Return 

false

.

The comparison 

x

 === 

y

, where 

x

 and 

y

 are values, produces 

true

 or 

false

. Such a comparison is performed as follows:

1.  If 

Type

(

x

) is different from 

Type

(

y

), return 

false

.

2.  If 

Type

(

x

) is Number or BigInt, then

a.  Return ! 

Type

(

x

)::equal(

x

y

).

3.  Return ! 

SameValueNonNumeric

(

x

y

).

NOTE

The abstract operation MakeBasicObject takes argument 

internalSlotsList

. It is the source of all ECMAScript objects

that are created algorithmically, including both ordinary objects and exotic objects. It factors out common steps used
in creating all objects, and centralizes object creation. It performs the following steps when called:

1. 

Assert

internalSlotsList

 is a 

List

 of internal slot names.

2.  Let 

obj

 be a newly created object with an internal slot for each name in 

internalSlotsList

.

3.  Set 

obj

's essential internal methods to the default 

ordinary object

 definitions specified in 

10.1

.

4. 

Assert

: If the caller will not be overriding both 

obj

's [[GetPrototypeOf]] and [[SetPrototypeOf]] essential internal

methods, then 

internalSlotsList

 contains [[Prototype]].

5. 

Assert

: If the caller will not be overriding all of 

obj

's [[SetPrototypeOf]], [[IsExtensible]], and

[[PreventExtensions]] essential internal methods, then 

internalSlotsList

 contains [[Extensible]].

6.  If 

internalSlotsList

 contains [[Extensible]], set 

obj

.[[Extensible]] to 

true

.

7.  Return 

obj

.

This algorithm differs from the 

SameValue

 Algorithm in its treatment of signed zeroes and NaNs.

7.2.15  Strict Equality Comparison

7.3  Operations on Objects

7.3.1  MakeBasicObject ( 

internalSlotsList

 )

128

NOTE

The abstract operation Get takes arguments 

O

 (an Object) and 

P

 (a property key). It is used to retrieve the value of a

specific property of an object. It performs the following steps when called:

1. 

Assert

Type

(

O

) is Object.

2. 

Assert

IsPropertyKey

(

P

) is 

true

.

3.  Return ? 

O

.[[Get]](

P

O

).

The abstract operation GetV takes arguments 

V

 (an 

ECMAScript language value

) and 

P

 (a property key). It is used to

retrieve the value of a specific property of an 

ECMAScript language value

. If the value is not an object, the property

lookup is performed using a wrapper object appropriate for the type of the value. It performs the following steps
when called:

1. 

Assert

IsPropertyKey

(

P

) is 

true

.

2.  Let 

O

 be ? 

ToObject

(

V

).

3.  Return ? 

O

.[[Get]](

P

V

).

The abstract operation Set takes arguments 

O

 (an Object), 

P

 (a property key), 

V

 (an 

ECMAScript language value

), and

Throw

 (a Boolean). It is used to set the value of a specific property of an object. 

V

 is the new value for the property. It

performs the following steps when called:

1. 

Assert

Type

(

O

) is Object.

2. 

Assert

IsPropertyKey

(

P

) is 

true

.

3. 

Assert

Type

(

Throw

) is Boolean.

4.  Let 

success

 be ? 

O

.[[Set]](

P

V

O

).

5.  If 

success

 is 

false

 and 

Throw

 is 

true

, throw a 

TypeError

 exception.

6.  Return 

success

.

The abstract operation CreateDataProperty takes arguments 

O

 (an Object), 

P

 (a property key), and 

V

 (an 

ECMAScript

language value

). It is used to create a new own property of an object. It performs the following steps when called:

1. 

Assert

Type

(

O

) is Object.

2. 

Assert

IsPropertyKey

(

P

) is 

true

.

3.  Let 

newDesc

 be the PropertyDescriptor { [[Value]]: 

V

, [[Writable]]: 

true

, [[Enumerable]]: 

true

, [[Configurable]]:

true

 }.

Within this specification, exotic objects are created in 

abstract operations

 such as 

ArrayCreate

 and

BoundFunctionCreate

 by first calling MakeBasicObject to obtain a basic, foundational object, and

then overriding some or all of that object's internal methods. In order to encapsulate 

exotic object

creation, the object's essential internal methods are never modified outside those operations.

7.3.2  Get ( 

O

P

 )

7.3.3  GetV ( 

V

P

 )

7.3.4  Set ( 

O

P

V

Throw

 )

7.3.5  CreateDataProperty ( 

O

P

V

 )

129

4.  Return ? 

O

.[[DefineOwnProperty]](

P

newDesc

).

NOTE

The abstract operation CreateMethodProperty takes arguments 

O

 (an Object), 

P

 (a property key), and 

V

 (an

ECMAScript language value

). It is used to create a new own property of an object. It performs the following steps

when called:

1. 

Assert

Type

(

O

) is Object.

2. 

Assert

IsPropertyKey

(

P

) is 

true

.

3.  Let 

newDesc

 be the PropertyDescriptor { [[Value]]: 

V

, [[Writable]]: 

true

, [[Enumerable]]: 

false

, [[Configurable]]:

true

 }.

4.  Return ? 

O

.[[DefineOwnProperty]](

P

newDesc

).

NOTE

The abstract operation CreateDataPropertyOrThrow takes arguments 

O

 (an Object), 

P

 (a property key), and 

V

 (an

ECMAScript language value

). It is used to create a new own property of an object. It throws a 

TypeError

 exception if

the requested property update cannot be performed. It performs the following steps when called:

1. 

Assert

Type

(

O

) is Object.

2. 

Assert

IsPropertyKey

(

P

) is 

true

.

3.  Let 

success

 be ? 

CreateDataProperty

(

O

P

V

).

4.  If 

success

 is 

false

, throw a 

TypeError

 exception.

5.  Return 

success

.

NOTE

The abstract operation DefinePropertyOrThrow takes arguments 

O

 (an Object), 

P

 (a property key), and 

desc

 (a

Property Descriptor

). It is used to call the [[DefineOwnProperty]] internal method of an object in a manner that will

throw a 

TypeError

 exception if the requested property update cannot be performed. It performs the following steps

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 

false

.

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 

false

.

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 

false

 causing this operation to throw a 

TypeError

 exception.

7.3.6  CreateMethodProperty ( 

O

P

V

 )

7.3.7  CreateDataPropertyOrThrow ( 

O

P

V

 )

7.3.8  DefinePropertyOrThrow ( 

O

P

desc

 )

130

when called:

1. 

Assert

Type

(

O

) is Object.

2. 

Assert

IsPropertyKey

(

P

) is 

true

.

3.  Let 

success

 be ? 

O

.[[DefineOwnProperty]](

P

desc

).

4.  If 

success

 is 

false

, throw a 

TypeError

 exception.

5.  Return 

success

.

The abstract operation DeletePropertyOrThrow takes arguments 

O

 (an Object) and 

P

 (a property key). It is used to

remove a specific own property of an object. It throws an exception if the property is not configurable. It performs the
following steps when called:

1. 

Assert

Type

(

O

) is Object.

2. 

Assert

IsPropertyKey

(

P

) is 

true

.

3.  Let 

success

 be ? 

O

.[[Delete]](

P

).

4.  If 

success

 is 

false

, throw a 

TypeError

 exception.

5.  Return 

success

.

The abstract operation GetMethod takes arguments 

V

 (an 

ECMAScript language value

) and 

P

 (a property key). It is

used to get the value of a specific property of an 

ECMAScript language value

 when the value of the property is

expected to be a function. It performs the following steps when called:

1. 

Assert

IsPropertyKey

(

P

) is 

true

.

2.  Let 

func

 be ? 

GetV

(

V

P

).

3.  If 

func

 is either 

undefined

 or 

null

, return 

undefined

.

4.  If 

IsCallable

(

func

) is 

false

, throw a 

TypeError

 exception.

5.  Return 

func

.

The abstract operation HasProperty takes arguments 

O

 (an Object) and 

P

 (a property key) and returns a completion

record which, if its [[Type]] is 

normal

, has a [[Value]] which is a Boolean. It is used to determine whether an object has

a property with the specified property key. The property may be either an own or inherited. It performs the following
steps when called:

1. 

Assert

Type

(

O

) is Object.

2. 

Assert

IsPropertyKey

(

P

) is 

true

.

3.  Return ? 

O

.[[HasProperty]](

P

).

The abstract operation HasOwnProperty takes arguments 

O

 (an Object) and 

P

 (a property key) and returns a

completion record which, if its [[Type]] is 

normal

, has a [[Value]] which is a Boolean. It is used to determine whether

an object has an own property with the specified property key. It performs the following steps when called:

7.3.9  DeletePropertyOrThrow ( 

O

P

 )

7.3.10  GetMethod ( 

V

P

 )

7.3.11  HasProperty ( 

O

P

 )

7.3.12  HasOwnProperty ( 

O

P

 )

131

1. 

Assert

Type

(

O

) is Object.

2. 

Assert

IsPropertyKey

(

P

) is 

true

.

3.  Let 

desc

 be ? 

O

.[[GetOwnProperty]](

P

).

4.  If 

desc

 is 

undefined

, return 

false

.

5.  Return 

true

.

The abstract operation Call takes arguments 

F

 (an 

ECMAScript language value

) and 

V

 (an 

ECMAScript language

value

) and optional argument 

argumentsList

 (a 

List

 of ECMAScript language values). It is used to call the [[Call]]

internal method of a 

function object

F

 is the 

function object

V

 is an 

ECMAScript language value

 that is the 

this

 value

of the [[Call]], and 

argumentsList

 is the value passed to the corresponding argument of the internal method. If

argumentsList

 is not present, a new empty 

List

 is used as its value. It performs the following steps when called:

1.  If 

argumentsList

 is not present, set 

argumentsList

 to a new empty 

List

.

2.  If 

IsCallable

(

F

) is 

false

, throw a 

TypeError

 exception.

3.  Return ? 

F

.[[Call]](

V

argumentsList

).

The abstract operation Construct takes argument 

F

 (a 

function object

) and optional arguments 

argumentsList

 and

newTarget

. It is used to call the [[Construct]] internal method of a 

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 

List

 is used as its value. If 

newTarget

 is not present, 

F

 is used as its value. It performs the following steps when

called:

1.  If 

newTarget

 is not present, set 

newTarget

 to 

F

.

2.  If 

argumentsList

 is not present, set 

argumentsList

 to a new empty 

List

.

3. 

Assert

IsConstructor

(

F

) is 

true

.

4. 

Assert

IsConstructor

(

newTarget

) is 

true

.

5.  Return ? 

F

.[[Construct]](

argumentsList

newTarget

).

NOTE

The abstract operation SetIntegrityLevel takes arguments 

O

 and 

level

. It is used to fix the set of own properties of an

object. It performs the following steps when called:

1. 

Assert

Type

(

O

) is Object.

2. 

Assert

level

 is either 

sealed

 or 

frozen

.

3.  Let 

status

 be ? 

O

.[[PreventExtensions]]().

4.  If 

status

 is 

false

, return 

false

.

5.  Let 

keys

 be ? 

O

.[[OwnPropertyKeys]]().

6.  If 

level

 is 

sealed

, then

a.  For each element 

k

 of 

keys

, do

i.  Perform ? 

DefinePropertyOrThrow

(

O

k

, PropertyDescriptor { [[Configurable]]: 

false

 }).

If 

newTarget

 is not present, this operation is equivalent to: 

new F(...argumentsList)

new F(...argumentsList)

7.3.13  Call ( 

F

V

 [ , 

argumentsList

 ] )

7.3.14  Construct ( 

F

 [ , 

argumentsList

 [ , 

newTarget

 ] ] )

7.3.15  SetIntegrityLevel ( 

O

level

 )

132

7.  Else,

a. 

Assert

level

 is 

frozen

.

b.  For each element 

k

 of 

keys

, do

i.  Let 

currentDesc

 be ? 

O

.[[GetOwnProperty]](

k

).

ii.  If 

currentDesc

 is not 

undefined

, then

1.  If 

IsAccessorDescriptor

(

currentDesc

) is 

true

, then

a.  Let 

desc

 be the PropertyDescriptor { [[Configurable]]: 

false

 }.

2.  Else,

a.  Let 

desc

 be the PropertyDescriptor { [[Configurable]]: 

false

, [[Writable]]: 

false

 }.

3.  Perform ? 

DefinePropertyOrThrow

(

O

k

desc

).

8.  Return 

true

.

The abstract operation TestIntegrityLevel takes arguments 

O

 and 

level

. It is used to determine if the set of own

properties of an object are fixed. It performs the following steps when called:

1. 

Assert

Type

(

O

) is Object.

2. 

Assert

level

 is either 

sealed

 or 

frozen

.

3.  Let 

extensible

 be ? 

IsExtensible

(

O

).

4.  If 

extensible

 is 

true

, return 

false

.

5.  NOTE: If the object is extensible, none of its properties are examined.
6.  Let 

keys

 be ? 

O

.[[OwnPropertyKeys]]().

7.  For each element 

k

 of 

keys

, do

a.  Let 

currentDesc

 be ? 

O

.[[GetOwnProperty]](

k

).

b.  If 

currentDesc

 is not 

undefined

, then

i.  If 

currentDesc

.[[Configurable]] is 

true

, return 

false

.

ii.  If 

level

 is 

frozen

 and 

IsDataDescriptor

(

currentDesc

) is 

true

, then

1.  If 

currentDesc

.[[Writable]] is 

true

, return 

false

.

8.  Return 

true

.

The abstract operation CreateArrayFromList takes argument 

elements

 (a 

List

). It is used to create an Array object

whose elements are provided by 

elements

. It performs the following steps when called:

1. 

Assert

elements

 is a 

List

 whose elements are all ECMAScript language values.

2.  Let 

array

 be ! 

ArrayCreate

(0).

3.  Let 

n

 be 0.

4.  For each element 

e

 of 

elements

, do

a.  Perform ! 

CreateDataPropertyOrThrow

(

array

, ! 

ToString

(

(

n

)), 

e

).

b.  Set 

n

 to 

n

 + 1.

5.  Return 

array

.

The abstract operation LengthOfArrayLike takes argument 

obj

. It returns the value of the 

"length"

 property of an

array-like object (as a non-negative 

integer

). It performs the following steps when called:

7.3.16  TestIntegrityLevel ( 

O

level

 )

7.3.17  CreateArrayFromList ( 

elements

 )

7.3.18  LengthOfArrayLike ( 

obj

 )

133

1. 

Assert

Type

(

obj

) is Object.

2.  Return 

ToLength

(? 

Get

(

obj

"length"

))).

An 

array-like object

 is any object for which this operation returns an 

integer

 rather than an 

abrupt completion

.

NOTE 1

NOTE 2

The abstract operation CreateListFromArrayLike takes argument 

obj

 and optional argument 

elementTypes

 (a 

List

 of

names of ECMAScript Language Types). It is used to create a 

List

 value whose elements are provided by the indexed

properties of 

obj

elementTypes

 contains the names of ECMAScript Language Types that are allowed for element values

of the 

List

 that is created. It performs the following steps when called:

1.  If 

elementTypes

 is not present, set 

elementTypes

 to « Undefined, Null, Boolean, String, Symbol, Number, BigInt,

Object ».

2.  If 

Type

(

obj

) is not Object, throw a 

TypeError

 exception.

3.  Let 

len

 be ? 

LengthOfArrayLike

(

obj

).

4.  Let 

list

 be a new empty 

List

.

5.  Let 

index

 be 0.

6.  Repeat, while 

index

 < 

len

,

a.  Let 

indexName

 be ! 

ToString

(

index

)).

b.  Let 

next

 be ? 

Get

(

obj

indexName

).

c.  If 

Type

(

next

) is not an element of 

elementTypes

, throw a 

TypeError

 exception.

d.  Append 

next

 as the last element of 

list

.

e.  Set 

index

 to 

index

 + 1.

7.  Return 

list

.

The abstract operation Invoke takes arguments 

V

 (an 

ECMAScript language value

) and 

P

 (a property key) and

optional argument 

argumentsList

 (a 

List

 of ECMAScript language values). It is used to call a method property of an

ECMAScript language value

V

 serves as both the lookup point for the property and the 

this

 value of the call.

argumentsList

 is the list of arguments values passed to the method. If 

argumentsList

 is not present, a new empty 

List

 is

used as its value. It performs the following steps when called:

1. 

Assert

IsPropertyKey

(

P

) is 

true

.

2.  If 

argumentsList

 is not present, set 

argumentsList

 to a new empty 

List

.

3.  Let 

func

 be ? 

GetV

(

V

P

).

4.  Return ? 

Call

(

func

V

argumentsList

).

The abstract operation OrdinaryHasInstance takes arguments 

C

 (an 

ECMAScript language value

) and 

O

. It

Typically, an array-like object would also have some properties with 

integer index

 names.

However, that is not a requirement of this definition.

Array objects and String objects are examples of array-like objects.

7.3.19  CreateListFromArrayLike ( 

obj

 [ , 

elementTypes

 ] )

7.3.20  Invoke ( 

V

P

 [ , 

argumentsList

 ] )

7.3.21  OrdinaryHasInstance ( 

C

O

 )

134

implements the default algorithm for determining if 

O

 inherits from the instance object inheritance path provided by

C

. It performs the following steps when called:

1.  If 

IsCallable

(

C

) is 

false

, return 

false

.

2.  If 

C

 has a [[BoundTargetFunction]] internal slot, then

a.  Let 

BC

 be 

C

.[[BoundTargetFunction]].

b.  Return ? 

InstanceofOperator

(

O

BC

).

3.  If 

Type

(

O

) is not Object, return 

false

.

4.  Let 

P

 be ? 

Get

(

C

"prototype"

).

5.  If 

Type

(

P

) is not Object, throw a 

TypeError

 exception.

6.  Repeat,

a.  Set 

O

 to ? 

O

.[[GetPrototypeOf]]().

b.  If 

O

 is 

null

, return 

false

.

c.  If 

SameValue

(

P

O

) is 

true

, return 

true

.

The abstract operation SpeciesConstructor takes arguments 

O

 (an Object) and 

defaultConstructor

 (a 

constructor

). It is

used to retrieve the 

constructor

 that should be used to create new objects that are derived from 

O

defaultConstructor

 is

the 

constructor

 to use if a 

constructor

 

@@species

 property cannot be found starting from 

O

. It performs the following

steps when called:

1. 

Assert

Type

(

O

) is Object.

2.  Let 

C

 be ? 

Get

(

O

"constructor"

).

3.  If 

C

 is 

undefined

, return 

defaultConstructor

.

4.  If 

Type

(

C

) is not Object, throw a 

TypeError

 exception.

5.  Let 

S

 be ? 

Get

(

C

@@species

).

6.  If 

S

 is either 

undefined

 or 

null

, return 

defaultConstructor

.

7.  If 

IsConstructor

(

S

) is 

true

, return 

S

.

8.  Throw a 

TypeError

 exception.

The abstract operation EnumerableOwnPropertyNames takes arguments 

O

 (an Object) and 

kind

 (one of 

key

value

, or

key+value

). It performs the following steps when called:

1. 

Assert

Type

(

O

) is Object.

2.  Let 

ownKeys

 be ? 

O

.[[OwnPropertyKeys]]().

3.  Let 

properties

 be a new empty 

List

.

4.  For each element 

key

 of 

ownKeys

, do

a.  If 

Type

(

key

) is String, then

i.  Let 

desc

 be ? 

O

.[[GetOwnProperty]](

key

).

ii.  If 

desc

 is not 

undefined

 and 

desc

.[[Enumerable]] is 

true

, then

1.  If 

kind

 is 

key

, append 

key

 to 

properties

.

2.  Else,

a.  Let 

value

 be ? 

Get

(

O

key

).

b.  If 

kind

 is 

value

, append 

value

 to 

properties

.

c.  Else,

7.3.22  SpeciesConstructor ( 

O

defaultConstructor

 )

7.3.23  EnumerableOwnPropertyNames ( 

O

kind

 )

135

i. 

Assert

kind

 is 

key+value

.

ii.  Let 

entry

 be ! 

CreateArrayFromList

(« 

key

value

 »).

iii.  Append 

entry

 to 

properties

.

5.  Return 

properties

.

The abstract operation GetFunctionRealm takes argument 

obj

. It performs the following steps when called:

1. 

Assert

: ! 

IsCallable

(

obj

) is 

true

.

2.  If 

obj

 has a [[Realm]] internal slot, then

a.  Return 

obj

.[[Realm]].

3.  If 

obj

 is a 

bound function exotic object

, then

a.  Let 

target

 be 

obj

.[[BoundTargetFunction]].

b.  Return ? 

GetFunctionRealm

(

target

).

4.  If 

obj

 is a 

Proxy exotic object

, then

a.  If 

obj

.[[ProxyHandler]] is 

null

, throw a 

TypeError

 exception.

b.  Let 

proxyTarget

 be 

obj

.[[ProxyTarget]].

c.  Return ? 

GetFunctionRealm

(

proxyTarget

).

5.  Return 

the current Realm Record

.

NOTE

The abstract operation CopyDataProperties takes arguments 

target

source

, and 

excludedItems

. It performs the following

steps when called:

1. 

Assert

Type

(

target

) is Object.

2. 

Assert

excludedItems

 is a 

List

 of property keys.

3.  If 

source

 is 

undefined

 or 

null

, return 

target

.

4.  Let 

from

 be ! 

ToObject

(

source

).

5.  Let 

keys

 be ? 

from

.[[OwnPropertyKeys]]().

6.  For each element 

nextKey

 of 

keys

, do

a.  Let 

excluded

 be 

false

.

b.  For each element 

e

 of 

excludedItems

, do

i.  If 

SameValue

(

e

nextKey

) is 

true

, then

1.  Set 

excluded

 to 

true

.

c.  If 

excluded

 is 

false

, then

i.  Let 

desc

 be ? 

from

.[[GetOwnProperty]](

nextKey

).

ii.  If 

desc

 is not 

undefined

 and 

desc

.[[Enumerable]] is 

true

, then

1.  Let 

propValue

 be ? 

Get

(

from

nextKey

).

2.  Perform ! 

CreateDataPropertyOrThrow

(

target

nextKey

propValue

).

7.  Return 

target

.

Step 

5

 will only be reached if 

obj

 is a non-standard function 

exotic object

 that does not have a

[[Realm]] internal slot.

7.3.24  GetFunctionRealm ( 

obj

 )

7.3.25  CopyDataProperties ( 

target

source

excludedItems

 )

136

NOTE

See Common Iteration Interfaces (

27.1

).

The abstract operation GetIterator takes argument 

obj

 and optional arguments 

hint

 and 

method

. It performs the

following steps when called:

1.  If 

hint

 is not present, set 

hint

 to 

sync

.

2. 

Assert

hint

 is either 

sync

 or 

async

.

3.  If 

method

 is not present, then

a.  If 

hint

 is 

async

, then

i.  Set 

method

 to ? 

GetMethod

(

obj

@@asyncIterator

).

ii.  If 

method

 is 

undefined

, then

1.  Let 

syncMethod

 be ? 

GetMethod

(

obj

@@iterator

).

2.  Let 

syncIteratorRecord

 be ? 

GetIterator

(

obj

sync

syncMethod

).

3.  Return ! 

CreateAsyncFromSyncIterator

(

syncIteratorRecord

).

b.  Otherwise, set 

method

 to ? 

GetMethod

(

obj

@@iterator

).

4.  Let 

iterator

 be ? 

Call

(

method

obj

).

5.  If 

Type

(

iterator

) is not Object, throw a 

TypeError

 exception.

6.  Let 

nextMethod

 be ? 

GetV

(

iterator

"next"

).

7.  Let 

iteratorRecord

 be the 

Record

 { [[Iterator]]: 

iterator

, [[NextMethod]]: 

nextMethod

, [[Done]]: 

false

 }.

8.  Return 

iteratorRecord

.

The abstract operation IteratorNext takes argument 

iteratorRecord

 and optional argument 

value

. It performs the

following steps when called:

1.  If 

value

 is not present, then

a.  Let 

result

 be ? 

Call

(

iteratorRecord

.[[NextMethod]], 

iteratorRecord

.[[Iterator]]).

2.  Else,

a.  Let 

result

 be ? 

Call

(

iteratorRecord

.[[NextMethod]], 

iteratorRecord

.[[Iterator]], « 

value

 »).

3.  If 

Type

(

result

) is not Object, throw a 

TypeError

 exception.

4.  Return 

result

.

The abstract operation IteratorComplete takes argument 

iterResult

. It performs the following steps when called:

1. 

Assert

Type

(

iterResult

) is Object.

2.  Return ! 

ToBoolean

(? 

Get

(

iterResult

"done"

)).

The target passed in here is always a newly created object which is not directly accessible in case
of an error being thrown.

7.4  Operations on Iterator Objects

7.4.1  GetIterator ( 

obj

 [ , 

hint

 [ , 

method

 ] ] )

7.4.2  IteratorNext ( 

iteratorRecord

 [ , 

value

 ] )

7.4.3  IteratorComplete ( 

iterResult

 )

137

 

 

 

 

 

 

 

Content      ..     13      14      15      16     ..