ECMA-262 (12th Edition) ECMAScript 2021 Language Specification — page 34
ii. Set
kPresent
(
O
,
Pk
).
iii. If
kPresent
is
true
, then
1. Set
accumulator
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 !
(
k
)).
b. Let
kPresent
(
O
,
Pk
).
c. If
kPresent
is
true
, then
i. Let
kValue
be ?
(
O
,
Pk
).
ii. Set
accumulator
(
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 ?
this
value).
2. Let
len
be ?
(
O
).
3. Let
middle
(
len
/ 2).
4. Let
lower
be 0.
5. Repeat, while
lower
≠
middle
,
a. Let
upper
be
len
-
lower
- 1.
b. Let
upperP
(
upper
)).
c. Let
lowerP
(
lower
)).
d. Let
lowerExists
(
O
,
lowerP
).
e. If
lowerExists
is
true
, then
i. Let
lowerValue
O
,
lowerP
).
f. Let
upperExists
(
O
,
upperP
).
g. If
upperExists
is
true
, then
i. Let
upperValue
O
,
upperP
).
h. If
lowerExists
is
true
and
upperExists
is
true
, then
i. Perform ?
(
O
,
lowerP
,
upperValue
,
true
).
ii. Perform ?
(
O
,
upperP
,
lowerValue
,
true
).
i. Else if
lowerExists
is
false
and
upperExists
is
true
, then
i. Perform ?
(
O
,
lowerP
,
upperValue
,
true
).
ii. Perform ?
O
,
upperP
).
j. Else if
lowerExists
is
true
and
upperExists
is
false
, then
i. Perform ?
O
,
lowerP
).
ii. Perform ?
(
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.
:
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 ?
this
value).
2. Let
len
be ?
(
O
).
3. If
len
= 0, then
a. Perform ?
(
O
,
"length"
,
+0
𝔽
,
true
).
b. Return
undefined
.
4. Let
first
O
,
"0"
).
5. Let
k
be 1.
6. Repeat, while
k
<
len
,
a. Let
from
(
k
)).
b. Let
to
(
k
- 1)).
c. Let
fromPresent
(
O
,
from
).
d. If
fromPresent
is
true
, then
i. Let
fromVal
O
,
from
).
ii. Perform ?
(
O
,
to
,
fromVal
,
true
).
e. Else,
i.
:
fromPresent
is
false
.
ii. Perform ?
O
,
to
).
f. Set
k
to
k
+ 1.
7. Perform ?
O
, !
(
len
- 1))).
8. Perform ?
(
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 ?
this
value).
2. Let
len
be ?
(
O
).
3. Let
relativeStart
start
).
4. If
relativeStart
is -
∞
, let
k
be 0.
5. Else if
relativeStart
< 0, let
k
be
len
+
relativeStart
, 0).
6. Else, let
k
be
(
relativeStart
,
len
).
7. If
end
is
undefined
, let
relativeEnd
be
len
; else let
relativeEnd
(
end
).
8. If
relativeEnd
is -
∞
, let
final
be 0.
9. Else if
relativeEnd
< 0, let
final
len
+
relativeEnd
, 0).
10. Else, let
final
(
relativeEnd
,
len
).
11. Let
count
be
(
final
-
k
, 0).
12. Let
A
(
O
,
count
).
13. Let
n
be 0.
14. Repeat, while
k
<
final
,
a. Let
Pk
be !
(
k
)).
b. Let
kPresent
(
O
,
Pk
).
c. If
kPresent
is
true
, then
i. Let
kValue
be ?
(
O
,
Pk
).
ii. Perform ?
(
A
, !
(
n
)),
kValue
).
d. Set
k
to
k
+ 1.
e. Set
n
to
n
+ 1.
15. Perform ?
(
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
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 ?
this
value).
2. Let
len
be ?
(
O
).
3. If
callbackfn
) is
false
, throw a
TypeError
exception.
4. Let
k
be 0.
5. Repeat, while
k
<
len
,
a. Let
Pk
be !
(
k
)).
b. Let
kPresent
(
O
,
Pk
).
c. If
kPresent
is
true
, then
i. Let
kValue
be ?
(
O
,
Pk
).
ii. Let
testResult
(
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
(
comparefn
) is
false
, throw a
TypeError
exception.
2. Let
obj
this
value).
3. Let
len
be ?
(
obj
).
4. Let
items
5. Let
k
be 0.
6. Repeat, while
k
<
len
,
a. Let
Pk
be !
(
k
)).
b. Let
kPresent
(
obj
,
Pk
).
c. If
kPresent
is
true
, then
i. Let
kValue
be ?
(
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
sequence of calls to
. If any such call returns an
, stop before performing any further calls to
or steps in this algorithm and
return that completion.
9. Let
j
be 0.
10. Repeat, while
j
<
itemCount
,
a. Perform ?
(
obj
, !
j
)),
items
[
j
],
true
).
b. Set
j
to
j
+ 1.
11. Repeat, while
j
<
len
,
a. Perform ?
obj
(
j
))).
b. Set
j
to
j
+ 1.
12. Return
obj
.
The
sort order
is the ordering, after completion of this function, of the
property values of
obj
whose
indexes are less than
len
. The result of the
sort
sort
function is then determined as follows:
The sort order is
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
does not act as a consistent comparison function.
If
comparefn
is
undefined
and all applications of
, to any specific value passed as an argument to
, do not produce the same result.
Unless the sort order is specified above to be
,
items
must satisfy all of the following
conditions after executing step
There must be some mathematical permutation
π
of the non-negative integers less than
itemCount
, such that for
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
j
], old[
k
]) < 0 (see
π
(
j
) <
π
(
k
).
Here the notation old[
j
] is used to refer to
items
[
j
] before step
is executed, and the notation new[
j
] to refer to
items
[
j
]
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,
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 ?
comparefn
,
undefined
, «
x
,
y
»)).
b. If
v
is
NaN
, return
+0
𝔽
.
c. Return
v
.
5. Let
xString
x
).
6. Let
yString
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
in steps
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 ?
this
value).
2. Let
len
be ?
(
O
).
3. Let
relativeStart
start
).
4. If
relativeStart
is -
∞
, let
actualStart
be 0.
5. Else if
relativeStart
< 0, let
actualStart
(
len
+
relativeStart
, 0).
6. Else, let
actualStart
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 ?
(
deleteCount
).
c. Let
actualDeleteCount
be the result of
dc
between 0 and
len
-
actualStart
.
10. If
len
+
insertCount
-
actualDeleteCount
> 2
53
- 1, throw a
TypeError
exception.
11. Let
A
be ?
(
O
,
actualDeleteCount
).
12. Let
k
be 0.
13. Repeat, while
k
<
actualDeleteCount
,
a. Let
from
(
actualStart
+
k
)).
b. Let
fromPresent
(
O
,
from
).
c. If
fromPresent
is
true
, then
i. Let
fromValue
(
O
,
from
).
ii. Perform ?
(
A
, !
(
k
)),
fromValue
).
d. Set
k
to
k
+ 1.
14. Perform ?
(
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
(
k
+
actualDeleteCount
)).
ii. Let
to
(
k
+
itemCount
)).
iii. Let
fromPresent
(
O
,
from
).
iv. If
fromPresent
is
true
, then
1. Let
fromValue
be ?
(
O
,
from
).
2. Perform ?
(
O
,
to
,
fromValue
,
true
).
v. Else,
1.
:
fromPresent
is
false
.
2. Perform ?
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
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 ?
O
, !
(
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
(
k
+
actualDeleteCount
- 1)).
ii. Let
to
(
k
+
itemCount
- 1)).
iii. Let
fromPresent
(
O
,
from
).
iv. If
fromPresent
is
true
, then
1. Let
fromValue
be ?
(
O
,
from
).
2. Perform ?
(
O
,
to
,
fromValue
,
true
).
v. Else,
1.
:
fromPresent
is
false
.
2. Perform ?
O
,
to
).
vi. Set
k
to
k
- 1.
18. Set
k
to
actualStart
.
19. For each element
E
of
items
, do
a. Perform ?
(
O
, !
(
k
)),
E
,
true
).
b. Set
k
to
k
+ 1.
20. Perform ?
(
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
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 ?
(
this
value).
2. Let
len
be ?
(
array
).
3. Let
separator
be the String value for the list-separator String appropriate for the
's current
locale (this is derived in an
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
of
R
and
separator
.
b. Let
nextElement
array
, !
(
k
))).
c. If
nextElement
is not
undefined
or
null
, then
i. Let
S
nextElement
,
"toLocaleString"
)).
ii. Set
R
to the
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 ?
(
this
value).
2. Let
func
be ?
(
array
,
"join"
).
3. If
func
) is
false
, set
func
to the intrinsic function %Object.prototype.toString%.
4. Return ?
(
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
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 ?
this
value).
2. Let
len
be ?
(
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
(
k
- 1)).
ii. Let
to
(
k
+
argCount
- 1)).
iii. Let
fromPresent
(
O
,
from
).
iv. If
fromPresent
is
true
, then
1. Let
fromValue
be ?
(
O
,
from
).
2. Perform ?
(
O
,
to
,
fromValue
,
true
).
v. Else,
1.
:
fromPresent
is
false
.
2. Perform ?
O
,
to
).
vi. Set
k
to
k
- 1.
d. Let
j
be
+0
𝔽
.
e. For each element
E
of
items
, do
i. Perform ?
(
O
, !
j
),
E
,
true
).
ii. Set
j
to
j
+
1
𝔽
.
5. Perform ?
(
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 ?
this
value).
2. Return
O
,
value
).
property is the same
Array.prototype.values
Array.prototype.values
property.
is an object created by the following steps:
1. Let
unscopableList
(
null
).
2. Perform !
(
unscopableList
,
"copyWithin"
,
true
).
3. Perform !
(
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 !
(
unscopableList
,
"fill"
,
true
).
5. Perform !
(
unscopableList
,
"find"
,
true
).
6. Perform !
(
unscopableList
,
"findIndex"
,
true
).
7. Perform !
(
unscopableList
,
"flat"
,
true
).
8. Perform !
(
unscopableList
,
"flatMap"
,
true
).
9. Perform !
(
unscopableList
,
"includes"
,
true
).
10. Perform !
(
unscopableList
,
"keys"
,
true
).
11. Perform !
(
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 instances have a
"length"
property, and a set of enumerable properties with
names.
The
"length"
property of an Array instance is a
whose value is always numerically greater than the
name of every configurable own property whose name is an
.
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
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
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 of the array will result in the length being set
to a numeric value that is one greater than that non-configurable numeric own
.
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.
:
array
) is Object.
2.
:
kind
is
key+value
,
key
, or
value
.
3. Let
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
(
array
.[[ViewedArrayBuffer]]) is
true
, throw a
TypeError
exception.
2. Let
len
be
array
.[[ArrayLength]].
ii. Else,
1. Let
len
be ?
(
array
).
iii. If
index
≥
len
, return
undefined
.
iv. If
kind
is
key
index
)).
v. Else,
1. Let
elementKey
be !
(
index
)).
2. Let
elementValue
array
,
elementKey
).
3. If
kind
is
value
, perform ?
(
elementValue
).
4. Else,
a.
:
kind
is
key+value
.
b. Perform ?
(
index
),
elementValue
»)).
vi. Set
index
to
index
+ 1.
4. Return !
(
closure
,
"%ArrayIteratorPrototype%"
,
).
The
%ArrayIteratorPrototype%
object:
has properties that are inherited by all Array Iterator Objects.
is an
.
has a [[Prototype]] internal slot whose value is
.
has the following properties:
1. Return ?
(
this
value,
empty
,
"%ArrayIteratorPrototype%"
).
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 (
). 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
, for each of the supported element types. Each
in
corresponding distinct prototype object.
Table 60: The TypedArray Constructors
Intrinsic
Element
Type
Element
Size
Conversion
Operation
Description
Int8Array
%Int8Array%
Int8
1
8-bit two's complement signed
Uint8Array
%Uint8Array%
Uint8
1
8-bit unsigned
Uint8ClampedArray
%Uint8ClampedArray%
Uint8C
1
8-bit unsigned
(clamped
conversion)
Int16Array
%Int16Array%
Int16
2
16-bit two's complement signed
Uint16Array
%Uint16Array%
Uint16
2
16-bit unsigned
Int32Array
%Int32Array%
Int32
4
32-bit two's complement signed
Uint32Array
%Uint32Array%
Uint32
4
32-bit unsigned
BigInt64Array
%BigInt64Array%
BigInt64
8
64-bit two's complement signed
BigUint64Array
%BigUint64Array%
BigUint64
8
64-bit unsigned
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
name from the
above table.
The
%TypedArray%
intrinsic object:
is a
that all of the
TypedArray
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
acts as the abstract superclass of the various
TypedArray
constructors.
will throw an error when invoked, because it is an abstract class
. The
TypedArray
constructors do
not perform a
super
super
call to it.
1. Throw a
TypeError
exception.
The
"length"
property of the
+0
𝔽
.
intrinsic object:
has a [[Prototype]] internal slot whose value is
.
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
C
) is
false
, throw a
TypeError
exception.
3. If
mapfn
is
undefined
, let
mapping
be
false
.
4. Else,
a. If
mapfn
) is
false
, throw a
TypeError
exception.
b. Let
mapping
be
true
.
5. Let
usingIterator
be ?
source
,
6. If
usingIterator
is not
undefined
, then
a. Let
values
be ?
(
source
,
usingIterator
).
b. Let
len
be the number of elements in
values
.
c. Let
targetObj
(
C
len
) »).
d. Let
k
be 0.
e. Repeat, while
k
<
len
,
i. Let
Pk
be !
(
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
(
mapfn
,
thisArg
, «
kValue
,
(
k
) »).
iv. Else, let
mappedValue
be
kValue
.
v. Perform ?
(
targetObj
,
Pk
,
mappedValue
,
true
).
vi. Set
k
to
k
+ 1.
f.
:
values
.
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
.
8. Let
arrayLike
be !
source
).
9. Let
len
be ?
(
arrayLike
).
10. Let
targetObj
(
C
len
) »).
11. Let
k
be 0.
12. Repeat, while
k
<
len
,
a. Let
Pk
be !
(
k
)).
b. Let
kValue
be ?
(
arrayLike
,
Pk
).
c. If
mapping
is
true
, then
i. Let
mappedValue
(
mapfn
,
thisArg
, «
kValue
,
(
k
) »).
d. Else, let
mappedValue
be
kValue
.
e. Perform ?
(
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
C
) is
false
, throw a
TypeError
exception.
4. Let
newObj
(
C
len
) »).
5. Let
k
be 0.
6. Repeat, while
k
<
len
,
a. Let
kValue
be
items
[
k
].
b. Let
Pk
be !
(
k
)).
c. Perform ?
(
newObj
,
Pk
,
kValue
,
true
).
d. Set
k
to
k
+ 1.
7. Return
newObj
.
The initial value of
.prototype
.
This property has the attributes { [[Writable]]:
false
, [[Enumerable]]:
false
, [[Configurable]]:
false
}.
[@@species]
[@@species]
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
is
%TypedArray.prototype%
.
is an
.
does not have a [[ViewedArrayBuffer]] or any other of the internal slots that are specific to
TypedArray
instance
objects.
.prototype.buffer
.prototype.buffer
is an
whose set accessor function is
undefined
. Its get
accessor function performs the following steps:
1. Let
O
be the
this
value.
2. Perform ?
(
O
, [[TypedArrayName]]).
3.
:
O
has a [[ViewedArrayBuffer]] internal slot.
4. Let
buffer
be
O
.[[ViewedArrayBuffer]].
5. Return
buffer
.
.prototype.byteLength
.prototype.byteLength
is an
whose set accessor function is
undefined
. Its
get accessor function performs the following steps:
1. Let
O
be the
this
value.
2. Perform ?
(
O
, [[TypedArrayName]]).
3.
:
O
has a [[ViewedArrayBuffer]] internal slot.
4. Let
buffer
be
O
.[[ViewedArrayBuffer]].
5. If
(
buffer
) is
true
, return
+0
𝔽
.
6. Let
size
be
O
.[[ByteLength]].
7. Return
size
).
.prototype.byteOffset
.prototype.byteOffset
is an
whose set accessor function is
undefined
. Its
get accessor function performs the following steps:
1. Let
O
be the
this
value.
2. Perform ?
(
O
, [[TypedArrayName]]).
3.
:
O
has a [[ViewedArrayBuffer]] internal slot.
4. Let
buffer
be
O
.[[ViewedArrayBuffer]].
5. If
(
buffer
) is
true
, return
+0
𝔽
.
this
value's
to create a derived
object. However, a subclass
may over-ride that default behaviour by redefining its
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

Нет комментариевНе стесняйтесь поделиться с нами вашим ценным мнением.
Текст