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

 

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

 

Search            copyright infringement  

 

 

 

 

 

 

 

 

 

 

 

Content      ..     32      33      34      35     ..

 

 

 

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

 

 

ii.  Set 

kPresent

 to ? 

HasProperty

(

O

Pk

).

iii.  If 

kPresent

 is 

true

, then

1.  Set 

accumulator

 to ? 

Get

(

O

Pk

).

iv.  Set 

k

 to 

k

 - 1.

c.  If 

kPresent

 is 

false

, throw a 

TypeError

 exception.

9.  Repeat, while 

k

 

 0,

a.  Let 

Pk

 be ! 

ToString

(

(

k

)).

b.  Let 

kPresent

 be ? 

HasProperty

(

O

Pk

).

c.  If 

kPresent

 is 

true

, then

i.  Let 

kValue

 be ? 

Get

(

O

Pk

).

ii.  Set 

accumulator

 to ? 

Call

(

callbackfn

undefined

, « 

accumulator

kValue

k

), 

O

 »).

d.  Set 

k

 to 

k

 - 1.

10.  Return 

accumulator

.

NOTE 2

NOTE 1

When the 

reverse

reverse

 method is called, the following steps are taken:

1.  Let 

O

 be ? 

ToObject

(

this

 value).

2.  Let 

len

 be ? 

LengthOfArrayLike

(

O

).

3.  Let 

middle

 be 

floor

(

len

 / 2).

4.  Let 

lower

 be 0.

5.  Repeat, while 

lower

 

 

middle

,

a.  Let 

upper

 be 

len

 - 

lower

 - 1.

b.  Let 

upperP

 be ! 

ToString

(

upper

)).

c.  Let 

lowerP

 be ! 

ToString

(

(

lower

)).

d.  Let 

lowerExists

 be ? 

HasProperty

(

O

lowerP

).

e.  If 

lowerExists

 is 

true

, then

i.  Let 

lowerValue

 be ? 

Get

(

O

lowerP

).

f.  Let 

upperExists

 be ? 

HasProperty

(

O

upperP

).

g.  If 

upperExists

 is 

true

, then

i.  Let 

upperValue

 be ? 

Get

(

O

upperP

).

h.  If 

lowerExists

 is 

true

 and 

upperExists

 is 

true

, then

i.  Perform ? 

Set

(

O

lowerP

upperValue

true

).

ii.  Perform ? 

Set

(

O

upperP

lowerValue

true

).

i.  Else if 

lowerExists

 is 

false

 and 

upperExists

 is 

true

, then

i.  Perform ? 

Set

(

O

lowerP

upperValue

true

).

ii.  Perform ? 

DeletePropertyOrThrow

(

O

upperP

).

j.  Else if 

lowerExists

 is 

true

 and 

upperExists

 is 

false

, then

i.  Perform ? 

DeletePropertyOrThrow

(

O

lowerP

).

ii.  Perform ? 

Set

(

O

upperP

lowerValue

true

).

The 

reduceRight

reduceRight

 function is intentionally generic; it does not require that its 

this

 value be an

Array object. Therefore it can be transferred to other kinds of objects for use as a method.

The elements of the array are rearranged so as to reverse their order. The object is returned as the
result of the call.

23.1.3.23  Array.prototype.reverse ( )

653

k.  Else,

i. 

Assert

lowerExists

 and 

upperExists

 are both 

false

.

ii.  No action is required.

l.  Set 

lower

 to 

lower

 + 1.

6.  Return 

O

.

NOTE 2

NOTE 1

When the 

shift

shift

 method is called, the following steps are taken:

1.  Let 

O

 be ? 

ToObject

(

this

 value).

2.  Let 

len

 be ? 

LengthOfArrayLike

(

O

).

3.  If 

len

 = 0, then

a.  Perform ? 

Set

(

O

"length"

+0

𝔽

true

).

b.  Return 

undefined

.

4.  Let 

first

 be ? 

Get

(

O

"0"

).

5.  Let 

k

 be 1.

6.  Repeat, while 

k

 < 

len

,

a.  Let 

from

 be ! 

ToString

(

(

k

)).

b.  Let 

to

 be ! 

ToString

(

(

k

 - 1)).

c.  Let 

fromPresent

 be ? 

HasProperty

(

O

from

).

d.  If 

fromPresent

 is 

true

, then

i.  Let 

fromVal

 be ? 

Get

(

O

from

).

ii.  Perform ? 

Set

(

O

to

fromVal

true

).

e.  Else,

i. 

Assert

fromPresent

 is 

false

.

ii.  Perform ? 

DeletePropertyOrThrow

(

O

to

).

f.  Set 

k

 to 

k

 + 1.

7.  Perform ? 

DeletePropertyOrThrow

(

O

, ! 

ToString

(

len

 - 1))).

8.  Perform ? 

Set

(

O

"length"

len

 - 1), 

true

).

9.  Return 

first

.

NOTE 2

The 

reverse

reverse

 function is intentionally generic; it does not require that its 

this

 value be an Array

object. Therefore, it can be transferred to other kinds of objects for use as a method.

The first element of the array is removed from the array and returned.

The 

shift

shift

 function is intentionally generic; it does not require that its 

this

 value be an Array

object. Therefore it can be transferred to other kinds of objects for use as a method.

23.1.3.24  Array.prototype.shift ( )

23.1.3.25  Array.prototype.slice ( 

start

end

 )

654

NOTE 1

The following steps are taken:

1.  Let 

O

 be ? 

ToObject

(

this

 value).

2.  Let 

len

 be ? 

LengthOfArrayLike

(

O

).

3.  Let 

relativeStart

 be ? 

ToIntegerOrInfinity

(

start

).

4.  If 

relativeStart

 is -

, let 

k

 be 0.

5.  Else if 

relativeStart

 < 0, let 

k

 be 

max

(

len

 + 

relativeStart

, 0).

6.  Else, let 

k

 be 

min

(

relativeStart

len

).

7.  If 

end

 is 

undefined

, let 

relativeEnd

 be 

len

; else let 

relativeEnd

 be ? 

ToIntegerOrInfinity

(

end

).

8.  If 

relativeEnd

 is -

, let 

final

 be 0.

9.  Else if 

relativeEnd

 < 0, let 

final

 be 

max

(

len

 + 

relativeEnd

, 0).

10.  Else, let 

final

 be 

min

(

relativeEnd

len

).

11.  Let 

count

 be 

max

(

final

 - 

k

, 0).

12.  Let 

A

 be ? 

ArraySpeciesCreate

(

O

count

).

13.  Let 

n

 be 0.

14.  Repeat, while 

k

 < 

final

,

a.  Let 

Pk

 be ! 

ToString

(

(

k

)).

b.  Let 

kPresent

 be ? 

HasProperty

(

O

Pk

).

c.  If 

kPresent

 is 

true

, then

i.  Let 

kValue

 be ? 

Get

(

O

Pk

).

ii.  Perform ? 

CreateDataPropertyOrThrow

(

A

, ! 

ToString

(

(

n

)), 

kValue

).

d.  Set 

k

 to 

k

 + 1.

e.  Set 

n

 to 

n

 + 1.

15.  Perform ? 

Set

(

A

"length"

(

n

), 

true

).

16.  Return 

A

.

NOTE 2

NOTE 3

The 

slice

slice

 method takes two arguments, 

start

 and 

end

, and returns an array containing the

elements of the array from element 

start

 up to, but not including, element 

end

 (or through the end

of the array if 

end

 is 

undefined

). If 

start

 is negative, it is treated as 

length

 + 

start

 where 

length

 is the

length of the array. If 

end

 is negative, it is treated as 

length

 + 

end

 where 

length

 is the length of the

array.

The explicit setting of the 

"length"

 property of the result Array in step 

15

 was necessary in

previous editions of ECMAScript to ensure that its length was correct in situations where the
trailing elements of the result Array were not present. Setting 

"length"

 became unnecessary

starting in ES2015 when the result Array was initialized to its proper length rather than an empty
Array but is carried forward to preserve backward compatibility.

The 

slice

slice

 function is intentionally generic; it does not require that its 

this

 value be an Array

object. Therefore it can be transferred to other kinds of objects for use as a method.

23.1.3.26  Array.prototype.some ( 

callbackfn

 [ , 

thisArg

 ] )

655

NOTE 1

When the 

some

some

 method is called with one or two arguments, the following steps are taken:

1.  Let 

O

 be ? 

ToObject

(

this

 value).

2.  Let 

len

 be ? 

LengthOfArrayLike

(

O

).

3.  If 

IsCallable

(

callbackfn

) is 

false

, throw a 

TypeError

 exception.

4.  Let 

k

 be 0.

5.  Repeat, while 

k

 < 

len

,

a.  Let 

Pk

 be ! 

ToString

(

(

k

)).

b.  Let 

kPresent

 be ? 

HasProperty

(

O

Pk

).

c.  If 

kPresent

 is 

true

, then

i.  Let 

kValue

 be ? 

Get

(

O

Pk

).

ii.  Let 

testResult

 be ! 

ToBoolean

(? 

Call

(

callbackfn

thisArg

, « 

kValue

k

), 

O

 »)).

iii.  If 

testResult

 is 

true

, return 

true

.

d.  Set 

k

 to 

k

 + 1.

6.  Return 

false

.

NOTE 2

The elements of this array are sorted. The sort must be stable (that is, elements that compare equal must remain in
their original order). If 

comparefn

 is not 

undefined

, it should be a function that accepts two arguments 

x

 and 

y

 and

returns a negative value if 

x

 < 

y

, zero if 

x

 = 

y

, or a positive value if 

x

 > 

y

.

The following steps are taken:

callbackfn

 should be a function that accepts three arguments and returns a value that is coercible

to a Boolean value. 

some

some

 calls 

callbackfn

 once for each element present in the array, in ascending

order, until it finds one where 

callbackfn

 returns 

true

. If such an element is found, 

some

some

immediately returns 

true

. Otherwise, 

some

some

 returns 

false

callbackfn

 is called only for elements of

the array which actually exist; it is not called for missing elements of the array.

If a 

thisArg

 parameter is provided, it will be used as the 

this

 value for each invocation of

callbackfn

. If it is not provided, 

undefined

 is used instead.

callbackfn

 is called with three arguments: the value of the element, the index of the element, and

the object being traversed.

some

some

 does not directly mutate the object on which it is called but the object may be mutated by

the calls to 

callbackfn

.

The range of elements processed by 

some

some

 is set before the first call to 

callbackfn

. Elements that

are appended to the array after the call to 

some

some

 begins will not be visited by 

callbackfn

. If existing

elements of the array are changed, their value as passed to 

callbackfn

 will be the value at the time

that 

some

some

 visits them; elements that are deleted after the call to 

some

some

 begins and before being

visited are not visited. 

some

some

 acts like the "exists" quantifier in mathematics. In particular, for an

empty array, it returns 

false

.

The 

some

some

 function is intentionally generic; it does not require that its 

this

 value be an Array

object. Therefore it can be transferred to other kinds of objects for use as a method.

23.1.3.27  Array.prototype.sort ( 

comparefn

 )

656

1.  If 

comparefn

 is not 

undefined

 and 

IsCallable

(

comparefn

) is 

false

, throw a 

TypeError

 exception.

2.  Let 

obj

 be ? 

ToObject

(

this

 value).

3.  Let 

len

 be ? 

LengthOfArrayLike

(

obj

).

4.  Let 

items

 be a new empty 

List

.

5.  Let 

k

 be 0.

6.  Repeat, while 

k

 < 

len

,

a.  Let 

Pk

 be ! 

ToString

(

(

k

)).

b.  Let 

kPresent

 be ? 

HasProperty

(

obj

Pk

).

c.  If 

kPresent

 is 

true

, then

i.  Let 

kValue

 be ? 

Get

(

obj

Pk

).

ii.  Append 

kValue

 to 

items

.

d.  Set 

k

 to 

k

 + 1.

7.  Let 

itemCount

 be the number of elements in 

items

.

8.  Sort 

items

 using an 

implementation-defined

 sequence of calls to 

SortCompare

. If any such call returns an

abrupt completion

, stop before performing any further calls to 

SortCompare

 or steps in this algorithm and

return that completion.

9.  Let 

j

 be 0.

10.  Repeat, while 

j

 < 

itemCount

,

a.  Perform ? 

Set

(

obj

, ! 

ToString

j

)), 

items

[

j

], 

true

).

b.  Set 

j

 to 

j

 + 1.

11.  Repeat, while 

j

 < 

len

,

a.  Perform ? 

DeletePropertyOrThrow

(

obj

, ! 

ToString

(

(

j

))).

b.  Set 

j

 to 

j

 + 1.

12.  Return 

obj

.

The 

sort order

 is the ordering, after completion of this function, of the 

integer-indexed

 property values of 

obj

 whose

integer

 indexes are less than 

len

. The result of the 

sort

sort

 function is then determined as follows:

The sort order is 

implementation-defined

 if any of the following conditions is true:

If 

comparefn

 is not 

undefined

 and is not a consistent comparison function for the elements of 

items

 (see below).

If 

comparefn

 is 

undefined

 and 

SortCompare

 does not act as a consistent comparison function.

If 

comparefn

 is 

undefined

 and all applications of 

ToString

, to any specific value passed as an argument to

SortCompare

, do not produce the same result.

Unless the sort order is specified above to be 

implementation-defined

items

 must satisfy all of the following

conditions after executing step 

8

 of the algorithm above:

There must be some mathematical permutation 

π

 of the non-negative integers less than 

itemCount

, such that for

every non-negative 

integer

 

j

 less than 

itemCount

, the element old[

j

] is exactly the same as new[

π

(

j

)].

Then for all non-negative integers 

j

 and 

k

, each less than 

itemCount

, if 

SortCompare

(old[

j

], old[

k

]) < 0 (see

SortCompare

 below), then 

π

(

j

) < 

π

(

k

).

Here the notation old[

j

] is used to refer to 

items

[

j

] before step 

8

 is executed, and the notation new[

j

] to refer to 

items

[

j

]

after step 

8

 has been executed.

A function 

comparefn

 is a consistent comparison function for a set of values 

S

 if all of the requirements below are met

for all values 

a

b

, and 

c

 (possibly the same value) in the set 

S

: The notation 

a

 <

CF

 

b

 means 

comparefn

(

a

b

) < 0; 

a

 =

CF

 

b

means 

comparefn

(

a

b

) = 0 (of either sign); and 

a

 >

CF

 

b

 means 

comparefn

(

a

b

) > 0.

657

Calling 

comparefn

(

a

b

) always returns the same value 

v

 when given a specific pair of values 

a

 and 

b

 as its two

arguments. Furthermore, 

Type

(

v

) is Number, and 

v

 is not 

NaN

. Note that this implies that exactly one of 

a

 <

CF

b

a

 =

CF

 

b

, and 

a

 >

CF

 

b

 will be true for a given pair of 

a

 and 

b

.

Calling 

comparefn

(

a

b

) does not modify 

obj

 or any object on 

obj

's prototype chain.

a

 =

CF

 

a

 (reflexivity)

If 

a

 =

CF

 

b

, then 

b

 =

CF

 

a

 (symmetry)

If 

a

 =

CF

 

b

 and 

b

 =

CF

 

c

, then 

a

 =

CF

 

c

 (transitivity of =

CF

)

If 

a

 <

CF

 

b

 and 

b

 <

CF

 

c

, then 

a

 <

CF

 

c

 (transitivity of <

CF

)

If 

a

 >

CF

 

b

 and 

b

 >

CF

 

c

, then 

a

 >

CF

 

c

 (transitivity of >

CF

)

NOTE 1

NOTE 2

The abstract operation SortCompare takes arguments 

x

 and 

y

. It also has access to the 

comparefn

 argument passed to

the current invocation of the 

sort

sort

 method. It performs the following steps when called:

1.  If 

x

 and 

y

 are both 

undefined

, return 

+0

𝔽

.

2.  If 

x

 is 

undefined

, return 

1

𝔽

.

3.  If 

y

 is 

undefined

, return 

-1

𝔽

.

4.  If 

comparefn

 is not 

undefined

, then

a.  Let 

v

 be ? 

ToNumber

(? 

Call

(

comparefn

undefined

, « 

x

y

 »)).

b.  If 

v

 is 

NaN

, return 

+0

𝔽

.

c.  Return 

v

.

5.  Let 

xString

 be ? 

ToString

(

x

).

6.  Let 

yString

 be ? 

ToString

(

y

).

7.  Let 

xSmaller

 be the result of performing 

Abstract Relational Comparison

 

xString

 < 

yString

.

8.  If 

xSmaller

 is 

true

, return 

-1

𝔽

.

9.  Let 

ySmaller

 be the result of performing 

Abstract Relational Comparison

 

yString

 < 

xString

.

10.  If 

ySmaller

 is 

true

, return 

1

𝔽

.

11.  Return 

+0

𝔽

.

NOTE 1

NOTE 2

The above conditions are necessary and sufficient to ensure that 

comparefn

 divides the set 

S

 into

equivalence classes and that these equivalence classes are totally ordered.

The 

sort

sort

 function is intentionally generic; it does not require that its 

this

 value be an Array

object. Therefore, it can be transferred to other kinds of objects for use as a method.

Because non-existent property values always compare greater than 

undefined

 property values,

and 

undefined

 always compares greater than any other value, 

undefined

 property values always

sort to the end of the result, followed by non-existent property values.

Method calls performed by the 

ToString

 

abstract operations

 in steps 

5

 and 

6

 have the potential to

cause SortCompare to not behave as a consistent comparison function.

23.1.3.27.1  SortCompare ( 

x

y

 )

23.1.3.28  Array.prototype.splice ( 

start

deleteCount

, ...

items

 )

658

NOTE 1

The following steps are taken:

1.  Let 

O

 be ? 

ToObject

(

this

 value).

2.  Let 

len

 be ? 

LengthOfArrayLike

(

O

).

3.  Let 

relativeStart

 be ? 

ToIntegerOrInfinity

(

start

).

4.  If 

relativeStart

 is -

, let 

actualStart

 be 0.

5.  Else if 

relativeStart

 < 0, let 

actualStart

 be 

max

(

len

 + 

relativeStart

, 0).

6.  Else, let 

actualStart

 be 

min

(

relativeStart

len

).

7.  If 

start

 is not present, then

a.  Let 

insertCount

 be 0.

b.  Let 

actualDeleteCount

 be 0.

8.  Else if 

deleteCount

 is not present, then

a.  Let 

insertCount

 be 0.

b.  Let 

actualDeleteCount

 be 

len

 - 

actualStart

.

9.  Else,

a.  Let 

insertCount

 be the number of elements in 

items

.

b.  Let 

dc

 be ? 

ToIntegerOrInfinity

(

deleteCount

).

c.  Let 

actualDeleteCount

 be the result of 

clamping

 

dc

 between 0 and 

len

 - 

actualStart

.

10.  If 

len

 + 

insertCount

 - 

actualDeleteCount

 > 2

53

 - 1, throw a 

TypeError

 exception.

11.  Let 

A

 be ? 

ArraySpeciesCreate

(

O

actualDeleteCount

).

12.  Let 

k

 be 0.

13.  Repeat, while 

k

 < 

actualDeleteCount

,

a.  Let 

from

 be ! 

ToString

(

(

actualStart

 + 

k

)).

b.  Let 

fromPresent

 be ? 

HasProperty

(

O

from

).

c.  If 

fromPresent

 is 

true

, then

i.  Let 

fromValue

 be ? 

Get

(

O

from

).

ii.  Perform ? 

CreateDataPropertyOrThrow

(

A

, ! 

ToString

(

(

k

)), 

fromValue

).

d.  Set 

k

 to 

k

 + 1.

14.  Perform ? 

Set

(

A

"length"

(

actualDeleteCount

), 

true

).

15.  Let 

itemCount

 be the number of elements in 

items

.

16.  If 

itemCount

 < 

actualDeleteCount

, then

a.  Set 

k

 to 

actualStart

.

b.  Repeat, while 

k

 < (

len

 - 

actualDeleteCount

),

i.  Let 

from

 be ! 

ToString

(

(

k

 + 

actualDeleteCount

)).

ii.  Let 

to

 be ! 

ToString

(

(

k

 + 

itemCount

)).

iii.  Let 

fromPresent

 be ? 

HasProperty

(

O

from

).

iv.  If 

fromPresent

 is 

true

, then

1.  Let 

fromValue

 be ? 

Get

(

O

from

).

2.  Perform ? 

Set

(

O

to

fromValue

true

).

v.  Else,

1. 

Assert

fromPresent

 is 

false

.

2.  Perform ? 

DeletePropertyOrThrow

(

O

to

).

vi.  Set 

k

 to 

k

 + 1.

When the 

splice

splice

 method is called with two or more arguments 

start

deleteCount

 and zero or

more 

items

, the 

deleteCount

 elements of the array starting at 

integer index

 

start

 are replaced by the

elements of 

items

. An Array object containing the deleted elements (if any) is returned.

659

c.  Set 

k

 to 

len

.

d.  Repeat, while 

k

 > (

len

 - 

actualDeleteCount

 + 

itemCount

),

i.  Perform ? 

DeletePropertyOrThrow

(

O

, ! 

ToString

(

k

 - 1))).

ii.  Set 

k

 to 

k

 - 1.

17.  Else if 

itemCount

 > 

actualDeleteCount

, then

a.  Set 

k

 to (

len

 - 

actualDeleteCount

).

b.  Repeat, while 

k

 > 

actualStart

,

i.  Let 

from

 be ! 

ToString

(

(

k

 + 

actualDeleteCount

 - 1)).

ii.  Let 

to

 be ! 

ToString

(

(

k

 + 

itemCount

 - 1)).

iii.  Let 

fromPresent

 be ? 

HasProperty

(

O

from

).

iv.  If 

fromPresent

 is 

true

, then

1.  Let 

fromValue

 be ? 

Get

(

O

from

).

2.  Perform ? 

Set

(

O

to

fromValue

true

).

v.  Else,

1. 

Assert

fromPresent

 is 

false

.

2.  Perform ? 

DeletePropertyOrThrow

(

O

to

).

vi.  Set 

k

 to 

k

 - 1.

18.  Set 

k

 to 

actualStart

.

19.  For each element 

E

 of 

items

, do

a.  Perform ? 

Set

(

O

, ! 

ToString

(

(

k

)), 

E

true

).

b.  Set 

k

 to 

k

 + 1.

20.  Perform ? 

Set

(

O

"length"

len

 - 

actualDeleteCount

 + 

itemCount

), 

true

).

21.  Return 

A

.

NOTE 2

NOTE 3

An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement the

Array.prototype.toLocaleString

Array.prototype.toLocaleString

 method as specified in the ECMA-402 specification. If an ECMAScript

implementation does not include the ECMA-402 API the following specification of the 

toLocaleString

toLocaleString

 method

is used.

NOTE 1

The meanings of the optional parameters to this method are defined in the ECMA-402 specification; implementations
that do not include ECMA-402 support must not use those parameter positions for anything else.

The explicit setting of the 

"length"

 property of the result Array in step 

20

 was necessary in

previous editions of ECMAScript to ensure that its length was correct in situations where the
trailing elements of the result Array were not present. Setting 

"length"

 became unnecessary

starting in ES2015 when the result Array was initialized to its proper length rather than an empty
Array but is carried forward to preserve backward compatibility.

The 

splice

splice

 function is intentionally generic; it does not require that its 

this

 value be an Array

object. Therefore it can be transferred to other kinds of objects for use as a method.

The first edition of ECMA-402 did not include a replacement specification for the

Array.prototype.toLocaleString

Array.prototype.toLocaleString

 method.

23.1.3.29  Array.prototype.toLocaleString ( [ 

reserved1

 [ , 

reserved2

 ] ] )

660

The following steps are taken:

1.  Let 

array

 be ? 

ToObject

(

this

 value).

2.  Let 

len

 be ? 

LengthOfArrayLike

(

array

).

3.  Let 

separator

 be the String value for the list-separator String appropriate for the 

host environment

's current

locale (this is derived in an 

implementation-defined

 way).

4.  Let 

R

 be the empty String.

5.  Let 

k

 be 0.

6.  Repeat, while 

k

 < 

len

,

a.  If 

k

 > 0, then

i.  Set 

R

 to the 

string-concatenation

 of 

R

 and 

separator

.

b.  Let 

nextElement

 be ? 

Get

(

array

, ! 

ToString

(

k

))).

c.  If 

nextElement

 is not 

undefined

 or 

null

, then

i.  Let 

S

 be ? 

ToString

(? 

Invoke

(

nextElement

"toLocaleString"

)).

ii.  Set 

R

 to the 

string-concatenation

 of 

R

 and 

S

.

d.  Set 

k

 to 

k

 + 1.

7.  Return 

R

.

NOTE 2

NOTE 3

When the 

toString

toString

 method is called, the following steps are taken:

1.  Let 

array

 be ? 

ToObject

(

this

 value).

2.  Let 

func

 be ? 

Get

(

array

"join"

).

3.  If 

IsCallable

(

func

) is 

false

, set 

func

 to the intrinsic function %Object.prototype.toString%.

4.  Return ? 

Call

(

func

array

).

NOTE

NOTE 1

When the 

unshift

unshift

 method is called with zero or more arguments 

item1

item2

, etc., the following steps are taken:

The elements of the array are converted to Strings using their 

toLocaleString

toLocaleString

 methods, and

these Strings are then concatenated, separated by occurrences of a separator String that has been
derived in an 

implementation-defined

 locale-specific way. The result of calling this function is

intended to be analogous to the result of 

toString

toString

, except that the result of this function is

intended to be locale-specific.

The 

toLocaleString

toLocaleString

 function is intentionally generic; it does not require that its 

this

 value

be an Array object. Therefore it can be transferred to other kinds of objects for use as a method.

The 

toString

toString

 function is intentionally generic; it does not require that its 

this

 value be an

Array object. Therefore it can be transferred to other kinds of objects for use as a method.

The arguments are prepended to the start of the array, such that their order within the array is the
same as the order in which they appear in the argument list.

23.1.3.30  Array.prototype.toString ( )

23.1.3.31  Array.prototype.unshift ( ...

items

 )

661

1.  Let 

O

 be ? 

ToObject

(

this

 value).

2.  Let 

len

 be ? 

LengthOfArrayLike

(

O

).

3.  Let 

argCount

 be the number of elements in 

items

.

4.  If 

argCount

 > 0, then

a.  If 

len

 + 

argCount

 > 2

53

 - 1, throw a 

TypeError

 exception.

b.  Let 

k

 be 

len

.

c.  Repeat, while 

k

 > 0,

i.  Let 

from

 be ! 

ToString

(

(

k

 - 1)).

ii.  Let 

to

 be ! 

ToString

(

(

k

 + 

argCount

 - 1)).

iii.  Let 

fromPresent

 be ? 

HasProperty

(

O

from

).

iv.  If 

fromPresent

 is 

true

, then

1.  Let 

fromValue

 be ? 

Get

(

O

from

).

2.  Perform ? 

Set

(

O

to

fromValue

true

).

v.  Else,

1. 

Assert

fromPresent

 is 

false

.

2.  Perform ? 

DeletePropertyOrThrow

(

O

to

).

vi.  Set 

k

 to 

k

 - 1.

d.  Let 

j

 be 

+0

𝔽

.

e.  For each element 

E

 of 

items

, do

i.  Perform ? 

Set

(

O

, ! 

ToString

(

j

), 

E

true

).

ii.  Set 

j

 to 

j

 + 

1

𝔽

.

5.  Perform ? 

Set

(

O

"length"

len

 + 

argCount

), 

true

).

6.  Return 

len

 + 

argCount

).

The 

"length"

 property of the 

unshift

unshift

 method is 

1

𝔽

.

NOTE 2

The following steps are taken:

1.  Let 

O

 be ? 

ToObject

(

this

 value).

2.  Return 

CreateArrayIterator

(

O

value

).

The initial value of the 

@@iterator

 property is the same 

function object

 as the initial value of the

Array.prototype.values

Array.prototype.values

 property.

The initial value of the 

@@unscopables

 

data property

 is an object created by the following steps:

1.  Let 

unscopableList

 be ! 

OrdinaryObjectCreate

(

null

).

2.  Perform ! 

CreateDataPropertyOrThrow

(

unscopableList

"copyWithin"

true

).

3.  Perform ! 

CreateDataPropertyOrThrow

(

unscopableList

"entries"

true

).

The 

unshift

unshift

 function is intentionally generic; it does not require that its 

this

 value be an Array

object. Therefore it can be transferred to other kinds of objects for use as a method.

23.1.3.32  Array.prototype.values ( )

23.1.3.33  Array.prototype [ @@iterator ] ( )

23.1.3.34  Array.prototype [ @@unscopables ]

662

4.  Perform ! 

CreateDataPropertyOrThrow

(

unscopableList

"fill"

true

).

5.  Perform ! 

CreateDataPropertyOrThrow

(

unscopableList

"find"

true

).

6.  Perform ! 

CreateDataPropertyOrThrow

(

unscopableList

"findIndex"

true

).

7.  Perform ! 

CreateDataPropertyOrThrow

(

unscopableList

"flat"

true

).

8.  Perform ! 

CreateDataPropertyOrThrow

(

unscopableList

"flatMap"

true

).

9.  Perform ! 

CreateDataPropertyOrThrow

(

unscopableList

"includes"

true

).

10.  Perform ! 

CreateDataPropertyOrThrow

(

unscopableList

"keys"

true

).

11.  Perform ! 

CreateDataPropertyOrThrow

(

unscopableList

"values"

true

).

12.  Return 

unscopableList

.

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

true

 }.

NOTE

Array instances are Array exotic objects and have the internal methods specified for such objects. Array instances
inherit properties from the 

Array prototype object

.

Array instances have a 

"length"

 property, and a set of enumerable properties with 

array index

 names.

The 

"length"

 property of an Array instance is a 

data property

 whose value is always numerically greater than the

name of every configurable own property whose name is an 

array index

.

The 

"length"

 property initially has the attributes { [[Writable]]: 

true

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

NOTE

An Array Iterator is an object, that represents a specific iteration over some specific Array instance object. There is not
a named 

constructor

 for Array Iterator objects. Instead, Array iterator objects are created by calling certain methods of

Array instance objects.

The own property names of this object are property names that were not included as standard
properties of 

Array.prototype

Array.prototype

 prior to the ECMAScript 2015 specification. These names are

ignored for 

with

with

 statement binding purposes in order to preserve the behaviour of existing code

that might use one of these names as a binding in an outer scope that is shadowed by a 

with

with

statement whose binding object is an Array object.

Reducing the value of the 

"length"

 property has the side-effect of deleting own array elements

whose 

array index

 is between the old and new length values. However, non-configurable

properties can not be deleted. Attempting to set the 

"length"

 property of an Array object to a

value that is numerically less than or equal to the largest numeric own 

property name

 of an

existing non-configurable 

array-indexed

 property of the array will result in the length being set

to a numeric value that is one greater than that non-configurable numeric own 

property name

.

See 

10.4.2.1

.

23.1.4  Properties of Array Instances

23.1.4.1  length

23.1.5  Array Iterator Objects

23.1.5.1  CreateArrayIterator ( 

array

kind

 )

663

The abstract operation CreateArrayIterator takes arguments 

array

 and 

kind

. This operation is used to create iterator

objects for Array methods that return such iterators. It performs the following steps when called:

1. 

Assert

Type

(

array

) is Object.

2. 

Assert

kind

 is 

key+value

key

, or 

value

.

3.  Let 

closure

 be a new 

Abstract Closure

 with no parameters that captures 

kind

 and 

array

 and performs the

following steps when called:

a.  Let 

index

 be 0.

b.  Repeat,

i.  If 

array

 has a [[TypedArrayName]] internal slot, then

1.  If 

IsDetachedBuffer

(

array

.[[ViewedArrayBuffer]]) is 

true

, throw a 

TypeError

 exception.

2.  Let 

len

 be 

array

.[[ArrayLength]].

ii.  Else,

1.  Let 

len

 be ? 

LengthOfArrayLike

(

array

).

iii.  If 

index

 

 

len

, return 

undefined

.

iv.  If 

kind

 is 

key

, perform ? 

Yield

index

)).

v.  Else,

1.  Let 

elementKey

 be ! 

ToString

(

index

)).

2.  Let 

elementValue

 be ? 

Get

(

array

elementKey

).

3.  If 

kind

 is 

value

, perform ? 

Yield

(

elementValue

).

4.  Else,

a. 

Assert

kind

 is 

key+value

.

b.  Perform ? 

Yield

(! 

CreateArrayFromList

(« 

(

index

), 

elementValue

 »)).

vi.  Set 

index

 to 

index

 + 1.

4.  Return ! 

CreateIteratorFromClosure

(

closure

"%ArrayIteratorPrototype%"

%ArrayIteratorPrototype%

).

The 

%ArrayIteratorPrototype%

 object:

has properties that are inherited by all Array Iterator Objects.
is an 

ordinary object

.

has a [[Prototype]] internal slot whose value is 

%IteratorPrototype%

.

has the following properties:

1.  Return ? 

GeneratorResume

(

this

 value, 

empty

"%ArrayIteratorPrototype%"

).

The initial value of the 

@@toStringTag

 property is the String value 

"Array Iterator"

.

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

true

 }.

TypedArray

 objects present an array-like view of an underlying binary data buffer (

25.1

). A 

TypedArray element type

 is

23.1.5.2  The %ArrayIteratorPrototype% Object

23.1.5.2.1  %ArrayIteratorPrototype%.next ( )

23.1.5.2.2  %ArrayIteratorPrototype% [ @@toStringTag ]

23.2  TypedArray Objects

664

the underlying binary scalar data type that all elements of a 

TypedArray

 instance have. There is a distinct 

TypedArray

constructor

, listed in 

Table 60

, for each of the supported element types. Each 

constructor

 in 

Table 60

 has a

corresponding distinct prototype object.

Table 60: The TypedArray Constructors

Constructor

 Name and

Intrinsic

Element

Type

Element

Size

Conversion

Operation

Description

Int8Array 

%Int8Array%

Int8

1

ToInt8

8-bit two's complement signed

integer

Uint8Array 

%Uint8Array%

Uint8

1

ToUint8

8-bit unsigned 

integer

Uint8ClampedArray 

%Uint8ClampedArray%

Uint8C

1

ToUint8Clamp

8-bit unsigned 

integer

 (clamped

conversion)

Int16Array 

%Int16Array%

Int16

2

ToInt16

16-bit two's complement signed

integer

Uint16Array 

%Uint16Array%

Uint16

2

ToUint16

16-bit unsigned 

integer

Int32Array 

%Int32Array%

Int32

4

ToInt32

32-bit two's complement signed

integer

Uint32Array 

%Uint32Array%

Uint32

4

ToUint32

32-bit unsigned 

integer

BigInt64Array 

%BigInt64Array%

BigInt64

8

ToBigInt64

64-bit two's complement signed

integer

BigUint64Array 

%BigUint64Array%

BigUint64

8

ToBigUint64

64-bit unsigned 

integer

Float32Array 

%Float32Array%

Float32

4

32-bit IEEE floating point

Float64Array 

%Float64Array%

Float64

8

64-bit IEEE floating point

In the definitions below, references to 

TypedArray

 should be replaced with the appropriate 

constructor

 name from the

above table.

The 

%TypedArray%

 intrinsic object:

is a 

constructor

 

function object

 that all of the 

TypedArray

 

constructor

 objects inherit from.

along with its corresponding prototype object, provides common properties that are inherited by all 

TypedArray

23.2.1  The %TypedArray% Intrinsic Object

665

constructors and their instances.
does not have a global name or appear as a property of the 

global object

.

acts as the abstract superclass of the various 

TypedArray

 constructors.

will throw an error when invoked, because it is an abstract class 

constructor

. The 

TypedArray

 constructors do

not perform a 

super

super

 call to it.

The 

%TypedArray%

 

constructor

 performs the following steps:

1.  Throw a 

TypeError

 exception.

The 

"length"

 property of the 

%TypedArray%

 

constructor

 function is 

+0

𝔽

.

The 

%TypedArray%

 intrinsic object:

has a [[Prototype]] internal slot whose value is 

%Function.prototype%

.

has a 

"name"

 property whose value is 

"TypedArray"

.

has the following properties:

When the 

from

from

 method is called with argument 

source

, and optional arguments 

mapfn

 and 

thisArg

, the following

steps are taken:

1.  Let 

C

 be the 

this

 value.

2.  If 

IsConstructor

(

C

) is 

false

, throw a 

TypeError

 exception.

3.  If 

mapfn

 is 

undefined

, let 

mapping

 be 

false

.

4.  Else,

a.  If 

IsCallable

(

mapfn

) is 

false

, throw a 

TypeError

 exception.

b.  Let 

mapping

 be 

true

.

5.  Let 

usingIterator

 be ? 

GetMethod

(

source

@@iterator

).

6.  If 

usingIterator

 is not 

undefined

, then

a.  Let 

values

 be ? 

IterableToList

(

source

usingIterator

).

b.  Let 

len

 be the number of elements in 

values

.

c.  Let 

targetObj

 be ? 

TypedArrayCreate

(

C

len

) »).

d.  Let 

k

 be 0.

e.  Repeat, while 

k

 < 

len

,

i.  Let 

Pk

 be ! 

ToString

(

(

k

)).

ii.  Let 

kValue

 be the first element of 

values

 and remove that element from 

values

.

iii.  If 

mapping

 is 

true

, then

1.  Let 

mappedValue

 be ? 

Call

(

mapfn

thisArg

, « 

kValue

(

k

) »).

iv.  Else, let 

mappedValue

 be 

kValue

.

v.  Perform ? 

Set

(

targetObj

Pk

mappedValue

true

).

vi.  Set 

k

 to 

k

 + 1.

f. 

Assert

values

 is now an empty 

List

.

g.  Return 

targetObj

.

23.2.1.1  %TypedArray% ( )

23.2.2  Properties of the %TypedArray% Intrinsic Object

23.2.2.1  %TypedArray%.from ( 

source

 [ , 

mapfn

 [ , 

thisArg

 ] ] )

666

7.  NOTE: 

source

 is not an Iterable so assume it is already an 

array-like object

.

8.  Let 

arrayLike

 be ! 

ToObject

(

source

).

9.  Let 

len

 be ? 

LengthOfArrayLike

(

arrayLike

).

10.  Let 

targetObj

 be ? 

TypedArrayCreate

(

C

len

) »).

11.  Let 

k

 be 0.

12.  Repeat, while 

k

 < 

len

,

a.  Let 

Pk

 be ! 

ToString

(

(

k

)).

b.  Let 

kValue

 be ? 

Get

(

arrayLike

Pk

).

c.  If 

mapping

 is 

true

, then

i.  Let 

mappedValue

 be ? 

Call

(

mapfn

thisArg

, « 

kValue

(

k

) »).

d.  Else, let 

mappedValue

 be 

kValue

.

e.  Perform ? 

Set

(

targetObj

Pk

mappedValue

true

).

f.  Set 

k

 to 

k

 + 1.

13.  Return 

targetObj

.

When the 

of

of

 method is called with any number of arguments, the following steps are taken:

1.  Let 

len

 be the number of elements in 

items

.

2.  Let 

C

 be the 

this

 value.

3.  If 

IsConstructor

(

C

) is 

false

, throw a 

TypeError

 exception.

4.  Let 

newObj

 be ? 

TypedArrayCreate

(

C

len

) »).

5.  Let 

k

 be 0.

6.  Repeat, while 

k

 < 

len

,

a.  Let 

kValue

 be 

items

[

k

].

b.  Let 

Pk

 be ! 

ToString

(

(

k

)).

c.  Perform ? 

Set

(

newObj

Pk

kValue

true

).

d.  Set 

k

 to 

k

 + 1.

7.  Return 

newObj

.

The initial value of 

%TypedArray%

.prototype

.prototype

 is the 

%TypedArray% prototype object

.

This property has the attributes { [[Writable]]: 

false

, [[Enumerable]]: 

false

, [[Configurable]]: 

false

 }.

%TypedArray%

[@@species]

[@@species]

 is an 

accessor property

 whose set accessor function is 

undefined

. Its get accessor

function performs the following steps:

1.  Return the 

this

 value.

The value of the 

"name"

 property of this function is 

"get [Symbol.species]"

.

23.2.2.2  %TypedArray%.of ( ...

items

 )

23.2.2.3  %TypedArray%.prototype

23.2.2.4  get %TypedArray% [ @@species ]

667

NOTE

The 

%TypedArray% prototype object

:

has a [[Prototype]] internal slot whose value is 

%Object.prototype%

.

is 

%TypedArray.prototype%

.

is an 

ordinary object

.

does not have a [[ViewedArrayBuffer]] or any other of the internal slots that are specific to 

TypedArray

 instance

objects.

%TypedArray%

.prototype.buffer

.prototype.buffer

 is an 

accessor property

 whose set accessor function is 

undefined

. Its get

accessor function performs the following steps:

1.  Let 

O

 be the 

this

 value.

2.  Perform ? 

RequireInternalSlot

(

O

, [[TypedArrayName]]).

3. 

Assert

O

 has a [[ViewedArrayBuffer]] internal slot.

4.  Let 

buffer

 be 

O

.[[ViewedArrayBuffer]].

5.  Return 

buffer

.

%TypedArray%

.prototype.byteLength

.prototype.byteLength

 is an 

accessor property

 whose set accessor function is 

undefined

. Its

get accessor function performs the following steps:

1.  Let 

O

 be the 

this

 value.

2.  Perform ? 

RequireInternalSlot

(

O

, [[TypedArrayName]]).

3. 

Assert

O

 has a [[ViewedArrayBuffer]] internal slot.

4.  Let 

buffer

 be 

O

.[[ViewedArrayBuffer]].

5.  If 

IsDetachedBuffer

(

buffer

) is 

true

, return 

+0

𝔽

.

6.  Let 

size

 be 

O

.[[ByteLength]].

7.  Return 

size

).

%TypedArray%

.prototype.byteOffset

.prototype.byteOffset

 is an 

accessor property

 whose set accessor function is 

undefined

. Its

get accessor function performs the following steps:

1.  Let 

O

 be the 

this

 value.

2.  Perform ? 

RequireInternalSlot

(

O

, [[TypedArrayName]]).

3. 

Assert

O

 has a [[ViewedArrayBuffer]] internal slot.

4.  Let 

buffer

 be 

O

.[[ViewedArrayBuffer]].

5.  If 

IsDetachedBuffer

(

buffer

) is 

true

, return 

+0

𝔽

.

%TypedArray.prototype%

 methods normally use their 

this

 value's 

constructor

 to create a derived

object. However, a subclass 

constructor

 may over-ride that default behaviour by redefining its

@@species

 property.

23.2.3  Properties of the %TypedArray% Prototype Object

23.2.3.1  get %TypedArray%.prototype.buffer

23.2.3.2  get %TypedArray%.prototype.byteLength

23.2.3.3  get %TypedArray%.prototype.byteOffset

668

 

 

 

 

 

 

 

Content      ..     32      33      34      35     ..