23 Indexed Collections
23.1 Array Objects
Arrays are
23.1.1 The Array Constructor
The Array
- is
%Array% . - is the initial value of the
"Array" property of theglobal object . - creates and initializes a new Array when called as a
constructor . - also creates and initializes a new Array when called as a function rather than as a
constructor . Thus the function callArray(…)is equivalent to the object creation expressionnew Array(…)with the same arguments. - is a function whose behaviour differs based upon the number and types of its arguments.
- may be used as the value of an
extendsclause of a class definition. Subclassconstructors that intend to inherit the exotic Array behaviour must include asupercall to the Arrayconstructor to initialize subclass instances that areArray exotic objects . However, most of theArray.prototypemethods are generic methods that are not dependent upon theirthis value being anArray exotic object .
23.1.1.1 Array ( ...values )
This function performs the following steps when called:
- If NewTarget is
undefined , let newTarget be theactive function object ; else let newTarget be NewTarget. - Let proto be ?
GetPrototypeFromConstructor (newTarget," ).%Array.prototype% " - Let numberOfArgs be the number of elements in values.
- If numberOfArgs = 0, return !
ArrayCreate (0, proto). - If numberOfArgs = 1, then
- Let length be values[0].
- Let array be !
ArrayCreate (0, proto). - If length
is not a Number , then- Perform !
CreateDataPropertyOrThrow (array,"0" , length). - Let intLength be
1 𝔽.
- Perform !
- Else,
- Let intLength be !
ToUint32 (length). - If
SameValueZero (intLength, length) isfalse , throw aRangeError exception.
- Let intLength be !
- Perform !
Set (array,"length" , intLength,true ). - Return array.
Assert : numberOfArgs ≥ 2.- Let array be ?
ArrayCreate (numberOfArgs, proto). - Let k be 0.
- Repeat, while k < numberOfArgs,
- Let propertyKey be !
ToString (𝔽 (k)). - Let itemK be values[k].
- Perform !
CreateDataPropertyOrThrow (array, propertyKey, itemK). - Set k to k + 1.
- Let propertyKey be !
Assert : Themathematical value of array's"length" property is numberOfArgs.- Return array.
23.1.2 Properties of the Array Constructor
The Array
- has a [[Prototype]] internal slot whose value is
%Function.prototype% . - has a
"length" property whose value is1 𝔽. - has the following properties:
23.1.2.1 Array.from ( items [ , mapper [ , thisArg ] ] )
This function performs the following steps when called:
- Let ctor be the
this value. - If mapper is
undefined , then- Let mapping be
false .
- Let mapping be
- Else,
- If
IsCallable (mapper) isfalse , throw aTypeError exception. - Let mapping be
true .
- If
- Let usingIterator be ?
GetMethod (items,%Symbol.iterator% ). - If usingIterator is not
undefined , then- If
IsConstructor (ctor) istrue , then- Let array be ?
Construct (ctor).
- Let array be ?
- Else,
- Let array be !
ArrayCreate (0).
- Let array be !
- Let iteratorRecord be ?
GetIteratorFromMethod (items, usingIterator). - Let k be 0.
- Repeat,
- If k ≥ 253 - 1, then
- Let error be
ThrowCompletion (a newly createdTypeError object). - Return ?
IteratorClose (iteratorRecord, error).
- Let error be
- Let propertyKey be !
ToString (𝔽 (k)). - Let next be ?
IteratorStepValue (iteratorRecord). - If next is
done , then - If mapping is
true , then- Let mappedValue be
Completion (Call (mapper, thisArg, « next,𝔽 (k) »)). IfAbruptCloseIterator (mappedValue, iteratorRecord).
- Let mappedValue be
- Else,
- Let mappedValue be next.
- Let defineStatus be
Completion (CreateDataPropertyOrThrow (array, propertyKey, mappedValue)). IfAbruptCloseIterator (defineStatus, iteratorRecord).- Set k to k + 1.
- If k ≥ 253 - 1, then
- If
NOTE : items is notiterable so assume it is anarray-like object .- Let arrayLike be !
ToObject (items). - Let length be ?
LengthOfArrayLike (arrayLike). - If
IsConstructor (ctor) istrue , then - Else,
- Let array be ?
ArrayCreate (length).
- Let array be ?
- Let k be 0.
- Repeat, while k < length,
- Perform ?
Set (array,"length" ,𝔽 (length),true ). - Return array.
This method is an intentionally generic factory method; it does not require that its
23.1.2.2 Array.fromAsync ( items [ , mapper [ , thisArg ] ] )
This async function performs the following steps when called:
- Let ctor be the
this value. - Let mapping be
false . - If mapper is not
undefined , then- If
IsCallable (mapper) isfalse , throw aTypeError exception. - Set mapping to
true .
- If
- Let iteratorRecord be
undefined . - Let usingAsyncIterator be ?
GetMethod (items,%Symbol.asyncIterator% ). - If usingAsyncIterator is
undefined , then- Let usingSyncIterator be ?
GetMethod (items,%Symbol.iterator% ). - If usingSyncIterator is not
undefined , then- Set iteratorRecord to
CreateAsyncFromSyncIterator (?GetIteratorFromMethod (items, usingSyncIterator)).
- Set iteratorRecord to
- Let usingSyncIterator be ?
- Else,
- Set iteratorRecord to ?
GetIteratorFromMethod (items, usingAsyncIterator).
- Set iteratorRecord to ?
- If iteratorRecord is not
undefined , then- If
IsConstructor (ctor) istrue , then- Let array be ?
Construct (ctor).
- Let array be ?
- Else,
- Let array be !
ArrayCreate (0).
- Let array be !
- Let k be 0.
- Repeat,
- If k ≥ 253 - 1, then
- Let error be
ThrowCompletion (a newly createdTypeError object). - Return ?
AsyncIteratorClose (iteratorRecord, error).
- Let error be
- Let propertyKey be !
ToString (𝔽 (k)). - Let nextResult be ?
Call (iteratorRecord.[[NextMethod]], iteratorRecord.[[Iterator]]). - Set nextResult to ?
Await (nextResult). - If nextResult
is not an Object , throw aTypeError exception. - Let done be ?
IteratorComplete (nextResult). - If done is
true , then - Let nextValue be ?
IteratorValue (nextResult). - If mapping is
true , then- Let mappedValue be
Completion (Call (mapper, thisArg, « nextValue,𝔽 (k) »)). IfAbruptCloseAsyncIterator (mappedValue, iteratorRecord).- Set mappedValue to
Completion (Await (mappedValue)). IfAbruptCloseAsyncIterator (mappedValue, iteratorRecord).
- Let mappedValue be
- Else,
- Let mappedValue be nextValue.
- Let defineStatus be
Completion (CreateDataPropertyOrThrow (array, propertyKey, mappedValue)). IfAbruptCloseAsyncIterator (defineStatus, iteratorRecord).- Set k to k + 1.
- If k ≥ 253 - 1, then
- If
- Else,
NOTE : items is neitherasync iterable noriterable so assume it is anarray-like object .- Let arrayLike be !
ToObject (items). - Let length be ?
LengthOfArrayLike (arrayLike). - If
IsConstructor (ctor) istrue , then - Else,
- Let array be ?
ArrayCreate (length).
- Let array be ?
- Let k be 0.
- Repeat, while k < length,
- Let propertyKey be !
ToString (𝔽 (k)). - Let kValue be ?
Get (arrayLike, propertyKey). - Set kValue to ?
Await (kValue). - If mapping is
true , then - Else,
- Let mappedValue be kValue.
- Perform ?
CreateDataPropertyOrThrow (array, propertyKey, mappedValue). - Set k to k + 1.
- Let propertyKey be !
- Perform ?
Set (array,"length" ,𝔽 (length),true ). - Return array.
This method is an intentionally generic factory method; it does not require that its
23.1.2.3 Array.isArray ( arg )
This function performs the following steps when called:
- Return ?
IsArray (arg).
23.1.2.4 Array.of ( ...items )
This method performs the following steps when called:
- Let length be the number of elements in items.
- Let lengthNumber be
𝔽 (length). - Let ctor be the
this value. - If
IsConstructor (ctor) istrue , then- Let array be ?
Construct (ctor, « lengthNumber »).
- Let array be ?
- Else,
- Let array be ?
ArrayCreate (length).
- Let array be ?
- Let k be 0.
- Repeat, while k < length,
- Let kValue be items[k].
- Let propertyKey be !
ToString (𝔽 (k)). - Perform ?
CreateDataPropertyOrThrow (array, propertyKey, kValue). - Set k to k + 1.
- Perform ?
Set (array,"length" , lengthNumber,true ). - Return array.
This method is an intentionally generic factory method; it does not require that its
23.1.2.5 Array.prototype
The value of Array.prototype is the
This property has the attributes { [[Writable]]:
23.1.2.6 get Array [ %Symbol.species% ]
Array[%Symbol.species%] is an
- Return the
this value.
The value of the
Array prototype methods normally use their
23.1.3 Properties of the Array Prototype Object
The Array prototype object:
- is
%Array.prototype% . - is an
Array exotic object and has the internal methods specified for such objects. - has a
"length" property whose initial value is+0 𝔽 and whose attributes are { [[Writable]]:true , [[Enumerable]]:false , [[Configurable]]:false }. - has a [[Prototype]] internal slot whose value is
%Object.prototype% .
The Array prototype object is specified to be an
23.1.3.1 Array.prototype.at ( index )
- Let obj be ?
ToObject (this value). - Let length be ?
LengthOfArrayLike (obj). - Let relativeIndex be ?
ToIntegerOrInfinity (index). - If relativeIndex ≥ 0, then
- Let k be relativeIndex.
- Else,
- Let k be length + relativeIndex.
- If k < 0 or k ≥ length, return
undefined . - Return ?
Get (obj, !ToString (𝔽 (k))).
23.1.3.2 Array.prototype.concat ( ...items )
This method returns an array containing the array elements of the object followed by the array elements of each argument.
It performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let array be ?
ArraySpeciesCreate (obj, 0). - Let nextIndex be 0.
- Prepend obj to items.
- For each element item of items, do
- Let spreadable be ?
IsConcatSpreadable (item). - If spreadable is
true , then- Let length be ?
LengthOfArrayLike (item). - If nextIndex + length > 253 - 1, throw a
TypeError exception. - Let sourceIndex be 0.
- Repeat, while sourceIndex < length,
- Let propertyKey be !
ToString (𝔽 (sourceIndex)). - Let exists be ?
HasProperty (item, propertyKey). - If exists is
true , then- Let subElement be ?
Get (item, propertyKey). - Perform ?
CreateDataPropertyOrThrow (array, !ToString (𝔽 (nextIndex)), subElement).
- Let subElement be ?
- Set nextIndex to nextIndex + 1.
- Set sourceIndex to sourceIndex + 1.
- Let propertyKey be !
- Let length be ?
- Else,
NOTE : item is added as a single item rather than spread.- If nextIndex ≥ 253 - 1, throw a
TypeError exception. - Perform ?
CreateDataPropertyOrThrow (array, !ToString (𝔽 (nextIndex)), item). - Set nextIndex to nextIndex + 1.
- Let spreadable be ?
- Perform ?
Set (array,"length" ,𝔽 (nextIndex),true ). - Return array.
The
The explicit setting of the
This method is intentionally generic; it does not require that its
23.1.3.2.1 IsConcatSpreadable ( obj )
The abstract operation IsConcatSpreadable takes argument obj (an
- If obj
is not an Object , returnfalse . - Let spreadable be ?
Get (obj,%Symbol.isConcatSpreadable% ). - If spreadable is not
undefined , returnToBoolean (spreadable). - Return ?
IsArray (obj).
23.1.3.3 Array.prototype.constructor
The initial value of Array.prototype.constructor is
23.1.3.4 Array.prototype.copyWithin ( target, start [ , end ] )
The end argument is optional. If it is not provided, the length of the
If target is negative, it is treated as
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let length be ?
LengthOfArrayLike (obj). - Let relativeTarget be ?
ToIntegerOrInfinity (target). - If relativeTarget = -∞, let to be 0.
- Else if relativeTarget < 0, let to be
max (length + relativeTarget, 0). - Else, let to be
min (relativeTarget, length). - Let relativeStart be ?
ToIntegerOrInfinity (start). - If relativeStart = -∞, let from be 0.
- Else if relativeStart < 0, let from be
max (length + relativeStart, 0). - Else, let from be
min (relativeStart, length). - If end is
undefined , let relativeEnd be length; else let relativeEnd be ?ToIntegerOrInfinity (end). - If relativeEnd = -∞, let final be 0.
- Else if relativeEnd < 0, let final be
max (length + relativeEnd, 0). - Else, let final be
min (relativeEnd, length). - Let count be
min (final - from, length - to). - If from < to and to < from + count, then
- Let direction be -1.
- Set from to from + count - 1.
- Set to to to + count - 1.
- Else,
- Let direction be 1.
- Repeat, while count > 0,
- Let fromKey be !
ToString (𝔽 (from)). - Let toKey be !
ToString (𝔽 (to)). - Let fromPresent be ?
HasProperty (obj, fromKey). - If fromPresent is
true , then - Else,
Assert : fromPresent isfalse .- Perform ?
DeletePropertyOrThrow (obj, toKey).
- Set from to from + direction.
- Set to to to + direction.
- Set count to count - 1.
- Let fromKey be !
- Return obj.
This method is intentionally generic; it does not require that its
23.1.3.5 Array.prototype.entries ( )
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - Return
CreateArrayIterator (obj,key+value ).
23.1.3.6 Array.prototype.every ( callback [ , thisArg ] )
callback should be a function that accepts three arguments and returns a value that is coercible to a Boolean value. every calls callback once for each element present in the array, in ascending order, until it finds one where callback returns every immediately returns every returns
If a thisArg parameter is provided, it will be used as the
callback is called with three arguments: the value of the element, the index of the element, and the object being traversed.
every does not directly mutate the object on which it is called but the object may be mutated by the calls to callback.
The range of elements processed by every is set before the first call to callback. Elements which are appended to the array after the call to every begins will not be visited by callback. If existing elements of the array are changed, their value as passed to callback will be the value at the time every visits them; elements that are deleted after the call to every begins and before being visited are not visited. every acts like the “for all” quantifier in mathematics. In particular, for an empty array, it returns
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let length be ?
LengthOfArrayLike (obj). - If
IsCallable (callback) isfalse , throw aTypeError exception. - Let k be 0.
- Repeat, while k < length,
- Return
true .
This method is intentionally generic; it does not require that its
23.1.3.7 Array.prototype.fill ( value [ , start [ , end ] ] )
The start argument is optional. If it is not provided,
The end argument is optional. If it is not provided, the length of the
If start is negative, it is treated as
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let length be ?
LengthOfArrayLike (obj). - Let relativeStart be ?
ToIntegerOrInfinity (start). - If relativeStart = -∞, let k be 0.
- Else if relativeStart < 0, let k be
max (length + relativeStart, 0). - Else, let k be
min (relativeStart, length). - If end is
undefined , let relativeEnd be length; else let relativeEnd be ?ToIntegerOrInfinity (end). - If relativeEnd = -∞, let final be 0.
- Else if relativeEnd < 0, let final be
max (length + relativeEnd, 0). - Else, let final be
min (relativeEnd, length). - Repeat, while k < final,
- Return obj.
This method is intentionally generic; it does not require that its
23.1.3.8 Array.prototype.filter ( callback [ , thisArg ] )
callback should be a function that accepts three arguments and returns a value that is coercible to a Boolean value. filter calls callback once for each element in the array, in ascending order, and constructs a new array of all the values for which callback returns
If a thisArg parameter is provided, it will be used as the
callback is called with three arguments: the value of the element, the index of the element, and the object being traversed.
filter does not directly mutate the object on which it is called but the object may be mutated by the calls to callback.
The range of elements processed by filter is set before the first call to callback. Elements which are appended to the array after the call to filter begins will not be visited by callback. If existing elements of the array are changed their value as passed to callback will be the value at the time filter visits them; elements that are deleted after the call to filter begins and before being visited are not visited.
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let length be ?
LengthOfArrayLike (obj). - If
IsCallable (callback) isfalse , throw aTypeError exception. - Let array be ?
ArraySpeciesCreate (obj, 0). - Let k be 0.
- Let to be 0.
- Repeat, while k < length,
- Let propertyKey be !
ToString (𝔽 (k)). - Let kPresent be ?
HasProperty (obj, propertyKey). - If kPresent is
true , then - Set k to k + 1.
- Let propertyKey be !
- Return array.
This method is intentionally generic; it does not require that its
23.1.3.9 Array.prototype.find ( predicate [ , thisArg ] )
This method calls predicate once for each element of the array, in ascending index order, until it finds one where predicate returns a value that coerces to find immediately returns that element value. Otherwise, find returns
See
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let length be ?
LengthOfArrayLike (obj). - Let findRecord be ?
FindViaPredicate (obj, length,ascending , predicate, thisArg). - Return findRecord.[[Value]].
This method is intentionally generic; it does not require that its
23.1.3.10 Array.prototype.findIndex ( predicate [ , thisArg ] )
This method calls predicate once for each element of the array, in ascending index order, until it finds one where predicate returns a value that coerces to findIndex immediately returns the index of that element value. Otherwise, findIndex returns -1.
See
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let length be ?
LengthOfArrayLike (obj). - Let findRecord be ?
FindViaPredicate (obj, length,ascending , predicate, thisArg). - Return findRecord.[[Index]].
This method is intentionally generic; it does not require that its
23.1.3.11 Array.prototype.findLast ( predicate [ , thisArg ] )
This method calls predicate once for each element of the array, in descending index order, until it finds one where predicate returns a value that coerces to findLast immediately returns that element value. Otherwise, findLast returns
See
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let length be ?
LengthOfArrayLike (obj). - Let findRecord be ?
FindViaPredicate (obj, length,descending , predicate, thisArg). - Return findRecord.[[Value]].
This method is intentionally generic; it does not require that its
23.1.3.12 Array.prototype.findLastIndex ( predicate [ , thisArg ] )
This method calls predicate once for each element of the array, in descending index order, until it finds one where predicate returns a value that coerces to findLastIndex immediately returns the index of that element value. Otherwise, findLastIndex returns -1.
See
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let length be ?
LengthOfArrayLike (obj). - Let findRecord be ?
FindViaPredicate (obj, length,descending , predicate, thisArg). - Return findRecord.[[Index]].
This method is intentionally generic; it does not require that its
23.1.3.12.1 FindViaPredicate ( obj, length, direction, predicate, thisArg )
The abstract operation FindViaPredicate takes arguments obj (an Object), length (a non-negative
obj should be an
predicate should be a function. When called for an element of the array, it is passed three arguments: the value of the element, the index of the element, and the object being traversed. Its return value will be coerced to a Boolean value.
thisArg will be used as the
This operation does not directly mutate the object on which it is called, but the object may be mutated by the calls to predicate.
The range of elements processed is set before the first call to predicate, just before the traversal begins. Elements that are appended to the array after this will not be visited by predicate. If existing elements of the array are changed, their value as passed to predicate will be the value at the time that this operation visits them. Elements that are deleted after traversal begins and before being visited are still visited and are either looked up from the prototype or are
It performs the following steps when called:
- If
IsCallable (predicate) isfalse , throw aTypeError exception. - If direction is
ascending , then - Else,
- For each
integer k of indices, do- Let propertyKey be !
ToString (𝔽 (k)). NOTE : If obj is aTypedArray , the following invocation ofGet will return anormal completion .- Let kValue be ?
Get (obj, propertyKey). - Let testResult be ?
Call (predicate, thisArg, « kValue,𝔽 (k), obj »). - If
ToBoolean (testResult) istrue , return theRecord { [[Index]]:𝔽 (k), [[Value]]: kValue }.
- Let propertyKey be !
- Return the
Record { [[Index]]:-1 𝔽, [[Value]]:undefined }.
23.1.3.13 Array.prototype.flat ( [ depth ] )
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let sourceLength be ?
LengthOfArrayLike (obj). - Let depthNumber be 1.
- If depth is not
undefined , then- Set depthNumber to ?
ToIntegerOrInfinity (depth). - If depthNumber < 0, set depthNumber to 0.
- Set depthNumber to ?
- Let array be ?
ArraySpeciesCreate (obj, 0). - Perform ?
FlattenIntoArray (array, obj, sourceLength, 0, depthNumber). - Return array.
23.1.3.13.1 FlattenIntoArray ( target, source, sourceLength, start, depth [ , mapperFunc [ , thisArg ] ] )
The abstract operation FlattenIntoArray takes arguments target (an Object), source (an Object), sourceLength (a non-negative
Assert : If mapperFunc is present, thenIsCallable (mapperFunc) istrue , thisArg is present, and depth is 1.- Let targetIndex be start.
- Let sourceIndex be
+0 𝔽. - Repeat, while
ℝ (sourceIndex) < sourceLength,- Let propertyKey be !
ToString (sourceIndex). - Let exists be ?
HasProperty (source, propertyKey). - If exists is
true , then- Let element be ?
Get (source, propertyKey). - If mapperFunc is present, then
- Set element to ?
Call (mapperFunc, thisArg, « element, sourceIndex, source »).
- Set element to ?
- Let shouldFlatten be
false . - If depth > 0, then
- Set shouldFlatten to ?
IsArray (element).
- Set shouldFlatten to ?
- If shouldFlatten is
true , then- If depth = +∞, let newDepth be +∞.
- Else, let newDepth be depth - 1.
- Let elementLength be ?
LengthOfArrayLike (element). - Set targetIndex to ? FlattenIntoArray(target, element, elementLength, targetIndex, newDepth).
- Else,
- If targetIndex ≥ 253 - 1, throw a
TypeError exception. - Perform ?
CreateDataPropertyOrThrow (target, !ToString (𝔽 (targetIndex)), element). - Set targetIndex to targetIndex + 1.
- If targetIndex ≥ 253 - 1, throw a
- Let element be ?
- Set sourceIndex to sourceIndex +
1 𝔽.
- Let propertyKey be !
- Return targetIndex.
23.1.3.14 Array.prototype.flatMap ( mapperFunc [ , thisArg ] )
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let sourceLength be ?
LengthOfArrayLike (obj). - If
IsCallable (mapperFunc) isfalse , throw aTypeError exception. - Let array be ?
ArraySpeciesCreate (obj, 0). - Perform ?
FlattenIntoArray (array, obj, sourceLength, 0, 1, mapperFunc, thisArg). - Return array.
23.1.3.15 Array.prototype.forEach ( callback [ , thisArg ] )
callback should be a function that accepts three arguments. forEach calls callback once for each element present in the array, in ascending order. callback 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
callback is called with three arguments: the value of the element, the index of the element, and the object being traversed.
forEach does not directly mutate the object on which it is called but the object may be mutated by the calls to callback.
The range of elements processed by forEach is set before the first call to callback. Elements which are appended to the array after the call to forEach begins will not be visited by callback. If existing elements of the array are changed, their value as passed to callback will be the value at the time forEach visits them; elements that are deleted after the call to forEach begins and before being visited are not visited.
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let length be ?
LengthOfArrayLike (obj). - If
IsCallable (callback) isfalse , throw aTypeError exception. - Let k be 0.
- Repeat, while k < length,
- Return
undefined .
This method is intentionally generic; it does not require that its
23.1.3.16 Array.prototype.includes ( searchElement [ , fromIndex ] )
This method compares searchElement to the elements of the array, in ascending order, using the
The optional second argument fromIndex defaults to
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let length be ?
LengthOfArrayLike (obj). - If length = 0, return
false . - Let startIndex be ?
ToIntegerOrInfinity (fromIndex). Assert : If fromIndex isundefined , then startIndex is 0.- If startIndex = +∞, return
false . - If startIndex = -∞, set startIndex to 0.
- If startIndex ≥ 0, then
- Let k be startIndex.
- Else,
- Let k be length + startIndex.
- If k < 0, set k to 0.
- Repeat, while k < length,
- Let elementK be ?
Get (obj, !ToString (𝔽 (k))). - If
SameValueZero (searchElement, elementK) istrue , returntrue . - Set k to k + 1.
- Let elementK be ?
- Return
false .
This method is intentionally generic; it does not require that its
This method intentionally differs from the similar indexOf method in two ways. First, it uses the
23.1.3.17 Array.prototype.indexOf ( searchElement [ , fromIndex ] )
This method compares searchElement to the elements of the array, in ascending order, using the
The optional second argument fromIndex defaults to
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let length be ?
LengthOfArrayLike (obj). - If length = 0, return
-1 𝔽. - Let startIndex be ?
ToIntegerOrInfinity (fromIndex). Assert : If fromIndex isundefined , then startIndex is 0.- If startIndex = +∞, return
-1 𝔽. - If startIndex = -∞, set startIndex to 0.
- If startIndex ≥ 0, then
- Let k be startIndex.
- Else,
- Let k be length + startIndex.
- If k < 0, set k to 0.
- Repeat, while k < length,
- Let propertyKey be !
ToString (𝔽 (k)). - Let kPresent be ?
HasProperty (obj, propertyKey). - If kPresent is
true , then- Let elementK be ?
Get (obj, propertyKey). - If
IsStrictlyEqual (searchElement, elementK) istrue , return𝔽 (k).
- Let elementK be ?
- Set k to k + 1.
- Let propertyKey be !
- Return
-1 𝔽.
This method is intentionally generic; it does not require that its
23.1.3.18 Array.prototype.join ( separator )
This method converts the elements of the array to Strings, and then concatenates these Strings, separated by occurrences of the separator. If no separator is provided, a single comma is used as the separator.
It performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let length be ?
LengthOfArrayLike (obj). - If separator is
undefined , let sep be"," . - Else, let sep be ?
ToString (separator). - Let result be the empty String.
- Let k be 0.
- Repeat, while k < length,
- If k > 0, set result to the
string-concatenation of result and sep. - Let element be ?
Get (obj, !ToString (𝔽 (k))). - If element is neither
undefined nornull , then- Let elementString be ?
ToString (element). - Set result to the
string-concatenation of result and elementString.
- Let elementString be ?
- Set k to k + 1.
- If k > 0, set result to the
- Return result.
This method is intentionally generic; it does not require that its
23.1.3.19 Array.prototype.keys ( )
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - Return
CreateArrayIterator (obj,key ).
23.1.3.20 Array.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
This method compares searchElement to the elements of the array in descending order using the
The optional second argument fromIndex defaults to the array's length minus one (i.e. the whole array is searched). If it is greater than or equal to the length of the array, the whole array will be searched. If it is less than
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let length be ?
LengthOfArrayLike (obj). - If length = 0, return
-1 𝔽. - If fromIndex is present, let startIndex be ?
ToIntegerOrInfinity (fromIndex); else let startIndex be length - 1. - If startIndex = -∞, return
-1 𝔽. - If startIndex ≥ 0, then
- Let k be
min (startIndex, length - 1).
- Let k be
- Else,
- Let k be length + startIndex.
- Repeat, while k ≥ 0,
- Let propertyKey be !
ToString (𝔽 (k)). - Let kPresent be ?
HasProperty (obj, propertyKey). - If kPresent is
true , then- Let elementK be ?
Get (obj, propertyKey). - If
IsStrictlyEqual (searchElement, elementK) istrue , return𝔽 (k).
- Let elementK be ?
- Set k to k - 1.
- Let propertyKey be !
- Return
-1 𝔽.
This method is intentionally generic; it does not require that its
23.1.3.21 Array.prototype.map ( callback [ , thisArg ] )
callback should be a function that accepts three arguments. map calls callback once for each element in the array, in ascending order, and constructs a new Array from the results. callback 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
callback is called with three arguments: the value of the element, the index of the element, and the object being traversed.
map does not directly mutate the object on which it is called but the object may be mutated by the calls to callback.
The range of elements processed by map is set before the first call to callback. Elements which are appended to the array after the call to map begins will not be visited by callback. If existing elements of the array are changed, their value as passed to callback will be the value at the time map visits them; elements that are deleted after the call to map begins and before being visited are not visited.
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let length be ?
LengthOfArrayLike (obj). - If
IsCallable (callback) isfalse , throw aTypeError exception. - Let array be ?
ArraySpeciesCreate (obj, length). - Let k be 0.
- Repeat, while k < length,
- Let propertyKey be !
ToString (𝔽 (k)). - Let kPresent be ?
HasProperty (obj, propertyKey). - If kPresent is
true , then- Let kValue be ?
Get (obj, propertyKey). - Let mappedValue be ?
Call (callback, thisArg, « kValue,𝔽 (k), obj »). - Perform ?
CreateDataPropertyOrThrow (array, propertyKey, mappedValue).
- Let kValue be ?
- Set k to k + 1.
- Let propertyKey be !
- Return array.
This method is intentionally generic; it does not require that its
23.1.3.22 Array.prototype.pop ( )
This method removes the last element of the array and returns it.
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let length be ?
LengthOfArrayLike (obj). - If length = 0, then
- Perform ?
Set (obj,"length" ,+0 𝔽,true ). - Return
undefined .
- Perform ?
Assert : length > 0.- Let newLength be
𝔽 (length - 1). - Let index be !
ToString (newLength). - Let element be ?
Get (obj, index). - Perform ?
DeletePropertyOrThrow (obj, index). - Perform ?
Set (obj,"length" , newLength,true ). - Return element.
This method is intentionally generic; it does not require that its
23.1.3.23 Array.prototype.push ( ...items )
This method appends the arguments to the end of the array, in the order in which they appear. It returns the new length of the array.
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let length be ?
LengthOfArrayLike (obj). - Let argCount be the number of elements in items.
- If length + argCount > 253 - 1, throw a
TypeError exception. - For each element item of items, do
- Perform ?
Set (obj,"length" ,𝔽 (length),true ). - Return
𝔽 (length).
The
This method is intentionally generic; it does not require that its
23.1.3.24 Array.prototype.reduce ( callback [ , initialValue ] )
callback should be a function that takes four arguments. reduce calls callback once for each element present in the array, in ascending order, skipping the first element unless initialValue is provided.
callback is called with four arguments: the previousValue (value from the previous call to callback), the currentValue (value of the current element), the currentIndex, and the object being traversed. The first time that callback is called, the previousValue and currentValue can be one of two values. If an initialValue was supplied in the call to reduce, then previousValue will be initialValue and currentValue will be the first value in the array. If no initialValue was supplied, then previousValue will be the first value in the array and currentValue will be the second. It is a
reduce does not directly mutate the object on which it is called but the object may be mutated by the calls to callback.
The range of elements processed by reduce is set before the first call to callback. Elements that are appended to the array after the call to reduce begins will not be visited by callback. If existing elements of the array are changed, their value as passed to callback will be the value at the time reduce visits them; elements that are deleted after the call to reduce begins and before being visited are not visited.
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let length be ?
LengthOfArrayLike (obj). - If
IsCallable (callback) isfalse , throw aTypeError exception. - If length = 0 and initialValue is not present, throw a
TypeError exception. - Let k be 0.
- Let accumulator be
undefined . - If initialValue is present, then
- Set accumulator to initialValue.
- Else,
- Let kPresent be
false . - Repeat, while kPresent is
false and k < length,- Let propertyKey be !
ToString (𝔽 (k)). - Set kPresent to ?
HasProperty (obj, propertyKey). - If kPresent is
true , then- Set accumulator to ?
Get (obj, propertyKey).
- Set accumulator to ?
- Set k to k + 1.
- Let propertyKey be !
- If kPresent is
false , throw aTypeError exception.
- Let kPresent be
- Repeat, while k < length,
- Return accumulator.
This method is intentionally generic; it does not require that its
23.1.3.25 Array.prototype.reduceRight ( callback [ , initialValue ] )
callback should be a function that takes four arguments. reduceRight calls callback once for each element present in the array, in descending order, skipping the first call unless initialValue is provided.
callback is called with four arguments: the previousValue (value from the previous call to callback), the currentValue (value of the current element), the currentIndex, and the object being traversed. The first time the function is called, the previousValue and currentValue can be one of two values. If an initialValue was supplied in the call to reduceRight, then previousValue will be initialValue and currentValue will be the last value in the array. If no initialValue was supplied, then previousValue will be the last value in the array and currentValue will be the second-to-last value. It is a
reduceRight does not directly mutate the object on which it is called but the object may be mutated by the calls to callback.
The range of elements processed by reduceRight is set before the first call to callback. Elements that are appended to the array after the call to reduceRight begins will not be visited by callback. If existing elements of the array are changed by callback, their value as passed to callback will be the value at the time reduceRight visits them; elements that are deleted after the call to reduceRight begins and before being visited are not visited.
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let length be ?
LengthOfArrayLike (obj). - If
IsCallable (callback) isfalse , throw aTypeError exception. - If length = 0 and initialValue is not present, throw a
TypeError exception. - Let k be length - 1.
- Let accumulator be
undefined . - If initialValue is present, then
- Set accumulator to initialValue.
- Else,
- Let kPresent be
false . - Repeat, while kPresent is
false and k ≥ 0,- Let propertyKey be !
ToString (𝔽 (k)). - Set kPresent to ?
HasProperty (obj, propertyKey). - If kPresent is
true , then- Set accumulator to ?
Get (obj, propertyKey).
- Set accumulator to ?
- Set k to k - 1.
- Let propertyKey be !
- If kPresent is
false , throw aTypeError exception.
- Let kPresent be
- Repeat, while k ≥ 0,
- Return accumulator.
This method is intentionally generic; it does not require that its
23.1.3.26 Array.prototype.reverse ( )
This method rearranges the elements of the array so as to reverse their order. It returns the reversed array.
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let length be ?
LengthOfArrayLike (obj). - Let middle be
floor (length / 2). - Let lower be 0.
- Repeat, while lower ≠ middle,
- Let upper be length - lower - 1.
- Let upperP be !
ToString (𝔽 (upper)). - Let lowerP be !
ToString (𝔽 (lower)). - Let lowerExists be ?
HasProperty (obj, lowerP). - If lowerExists is
true , then- Let lowerValue be ?
Get (obj, lowerP).
- Let lowerValue be ?
- Let upperExists be ?
HasProperty (obj, upperP). - If upperExists is
true , then- Let upperValue be ?
Get (obj, upperP).
- Let upperValue be ?
- If lowerExists is
true and upperExists istrue , then - Else if lowerExists is
false and upperExists istrue , then- Perform ?
Set (obj, lowerP, upperValue,true ). - Perform ?
DeletePropertyOrThrow (obj, upperP).
- Perform ?
- Else if lowerExists is
true and upperExists isfalse , then- Perform ?
DeletePropertyOrThrow (obj, lowerP). - Perform ?
Set (obj, upperP, lowerValue,true ).
- Perform ?
- Else,
- Set lower to lower + 1.
- Return obj.
This method is intentionally generic; it does not require that its
23.1.3.27 Array.prototype.shift ( )
This method removes the first element of the array and returns it.
It performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let length be ?
LengthOfArrayLike (obj). - If length = 0, then
- Perform ?
Set (obj,"length" ,+0 𝔽,true ). - Return
undefined .
- Perform ?
- Let first be ?
Get (obj,"0" ). - Let k be 1.
- Repeat, while k < length,
- Let from be !
ToString (𝔽 (k)). - Let to be !
ToString (𝔽 (k - 1)). - Let fromPresent be ?
HasProperty (obj, from). - If fromPresent is
true , then - Else,
Assert : fromPresent isfalse .- Perform ?
DeletePropertyOrThrow (obj, to).
- Set k to k + 1.
- Let from be !
- Perform ?
DeletePropertyOrThrow (obj, !ToString (𝔽 (length - 1))). - Perform ?
Set (obj,"length" ,𝔽 (length - 1),true ). - Return first.
This method is intentionally generic; it does not require that its
23.1.3.28 Array.prototype.slice ( start, end )
This method 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
It performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let length be ?
LengthOfArrayLike (obj). - Let relativeStart be ?
ToIntegerOrInfinity (start). - If relativeStart = -∞, let k be 0.
- Else if relativeStart < 0, let k be
max (length + relativeStart, 0). - Else, let k be
min (relativeStart, length). - If end is
undefined , let relativeEnd be length; else let relativeEnd be ?ToIntegerOrInfinity (end). - If relativeEnd = -∞, let final be 0.
- Else if relativeEnd < 0, let final be
max (length + relativeEnd, 0). - Else, let final be
min (relativeEnd, length). - Let count be
max (final - k, 0). - Let array be ?
ArraySpeciesCreate (obj, count). - Let resultIndex be 0.
- Repeat, while k < final,
- Let propertyKey be !
ToString (𝔽 (k)). - Let kPresent be ?
HasProperty (obj, propertyKey). - If kPresent is
true , then- Let kValue be ?
Get (obj, propertyKey). - Perform ?
CreateDataPropertyOrThrow (array, !ToString (𝔽 (resultIndex)), kValue).
- Let kValue be ?
- Set k to k + 1.
- Set resultIndex to resultIndex + 1.
- Let propertyKey be !
- Perform ?
Set (array,"length" ,𝔽 (resultIndex),true ). - Return array.
The explicit setting of the
This method is intentionally generic; it does not require that its
23.1.3.29 Array.prototype.some ( callback [ , thisArg ] )
callback should be a function that accepts three arguments and returns a value that is coercible to a Boolean value. some calls callback once for each element present in the array, in ascending order, until it finds one where callback returns some immediately returns some returns
If a thisArg parameter is provided, it will be used as the
callback is called with three arguments: the value of the element, the index of the element, and the object being traversed.
some does not directly mutate the object on which it is called but the object may be mutated by the calls to callback.
The range of elements processed by some is set before the first call to callback. Elements that are appended to the array after the call to some begins will not be visited by callback. If existing elements of the array are changed, their value as passed to callback will be the value at the time that some visits them; elements that are deleted after the call to some begins and before being visited are not visited. some acts like the “exists” quantifier in mathematics. In particular, for an empty array, it returns
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let length be ?
LengthOfArrayLike (obj). - If
IsCallable (callback) isfalse , throw aTypeError exception. - Let k be 0.
- Repeat, while k < length,
- Return
false .
This method is intentionally generic; it does not require that its
23.1.3.30 Array.prototype.sort ( comparator )
This method sorts the elements of this array. If comparator is not
It performs the following steps when called:
- If comparator is not
undefined andIsCallable (comparator) isfalse , throw aTypeError exception. - Let obj be ?
ToObject (this value). - Let length be ?
LengthOfArrayLike (obj). - Let sortCompare be a new
Abstract Closure with parameters (x, y) that captures comparator and performs the following steps when called:- Return ?
CompareArrayElements (x, y, comparator).
- Return ?
- Let sortedList be ?
SortIndexedProperties (obj, length, sortCompare,skip-holes ). - Let itemCount be the number of elements in sortedList.
- Let j be 0.
- Repeat, while j < itemCount,
NOTE : The call toSortIndexedProperties in step5 usesskip-holes . The remaining indices are deleted to preserve the number of holes that were detected and excluded from the sort.- Repeat, while j < length,
- Perform ?
DeletePropertyOrThrow (obj, !ToString (𝔽 (j))). - Set j to j + 1.
- Perform ?
- Return obj.
Because non-existent property values always compare greater than
Method calls performed by the
This method is intentionally generic; it does not require that its
23.1.3.30.1 SortIndexedProperties ( obj, length, sortCompare, holes )
The abstract operation SortIndexedProperties takes arguments obj (an Object), length (a non-negative
- Let items be a new empty
List . - Let k be 0.
- Repeat, while k < length,
- Let propertyKey be !
ToString (𝔽 (k)). - If holes is
skip-holes , then- Let kRead be ?
HasProperty (obj, propertyKey).
- Let kRead be ?
- Else,
Assert : holes isread-through-holes .- Let kRead be
true .
- If kRead is
true , then- Let kValue be ?
Get (obj, propertyKey). - Append kValue to items.
- Let kValue be ?
- Set k to k + 1.
- Let propertyKey be !
- Sort items using an
implementation-defined sequence ofcalls to sortCompare . If any such call returns anabrupt completion , stop before performing any further calls to sortCompare and return thatCompletion Record . - Return items.
The sort order is the ordering of items after completion of step
Unless the
-
There must be some mathematical permutation π of the non-negative
integers less than itemCount, such that for every non-negativeinteger j less than itemCount, the elementold[j] is exactly the same asnew[π(j)] . -
Then for all non-negative
integers j and k, each less than itemCount, if , thenℝ (sortCompare(old[j], old[k])) < 0π(j) < π(k) . -
And for all non-negative
integers j and k such that j < k < itemCount, if , thenℝ (sortCompare(old[j], old[k])) = 0π(j) < π(k) ; i.e., the sort is stable.
Here the notation
An
-
Calling comparator(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 a Number , and v is notNaN . Note that this implies that exactly one of a <C b, a =C b, and a >C b will be true for a given pair of a and b. - Calling comparator(a, b) does not modify obj or any object on obj's prototype chain.
- a =C a (reflexivity)
- If a =C b, then b =C a (symmetry)
- If a =C b and b =C c, then a =C c (transitivity of =C)
- If a <C b and b <C c, then a <C c (transitivity of <C)
- If a >C b and b >C c, then a >C c (transitivity of >C)
The above conditions are necessary and sufficient to ensure that comparator divides the set values into equivalence classes and that these equivalence classes are totally ordered.
23.1.3.30.2 CompareArrayElements ( x, y, comparator )
The abstract operation CompareArrayElements takes arguments x (an
- If x is
undefined and y isundefined , return+0 𝔽. - If x is
undefined , return1 𝔽. - If y is
undefined , return-1 𝔽. - If comparator is not
undefined , then - Let xString be ?
ToString (x). - Let yString be ?
ToString (y). - Let xSmaller be !
IsLessThan (xString, yString,true ). - If xSmaller is
true , return-1 𝔽. - Let ySmaller be !
IsLessThan (yString, xString,true ). - If ySmaller is
true , return1 𝔽. - Return
+0 𝔽.
23.1.3.31 Array.prototype.splice ( start, deleteCount, ...items )
This method deletes the deleteCount elements of the array starting at
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let length be ?
LengthOfArrayLike (obj). - Let relativeStart be ?
ToIntegerOrInfinity (start). - If relativeStart = -∞, let actualStart be 0.
- Else if relativeStart < 0, let actualStart be
max (length + relativeStart, 0). - Else, let actualStart be
min (relativeStart, length). - Let itemCount be the number of elements in items.
- If start is not present, then
- Let actualDeleteCount be 0.
- Else if deleteCount is not present, then
- Let actualDeleteCount be length - actualStart.
- Else,
- Let dc be ?
ToIntegerOrInfinity (deleteCount). - Let actualDeleteCount be the result of
clamping dc between 0 and length - actualStart.
- Let dc be ?
- If length + itemCount - actualDeleteCount > 253 - 1, throw a
TypeError exception. - Let deletedArray be ?
ArraySpeciesCreate (obj, actualDeleteCount). - Let k be 0.
- Repeat, while k < actualDeleteCount,
- Let from be !
ToString (𝔽 (actualStart + k)). - If ?
HasProperty (obj, from) istrue , then- Let fromValue be ?
Get (obj, from). - Perform ?
CreateDataPropertyOrThrow (deletedArray, !ToString (𝔽 (k)), fromValue).
- Let fromValue be ?
- Set k to k + 1.
- Let from be !
- Perform ?
Set (deletedArray,"length" ,𝔽 (actualDeleteCount),true ). - If itemCount < actualDeleteCount, then
- Set k to actualStart.
- Repeat, while k < (length - actualDeleteCount),
- Let from be !
ToString (𝔽 (k + actualDeleteCount)). - Let to be !
ToString (𝔽 (k + itemCount)). - If ?
HasProperty (obj, from) istrue , then - Else,
- Perform ?
DeletePropertyOrThrow (obj, to).
- Perform ?
- Set k to k + 1.
- Let from be !
- Set k to length.
- Repeat, while k > (length - actualDeleteCount + itemCount),
- Perform ?
DeletePropertyOrThrow (obj, !ToString (𝔽 (k - 1))). - Set k to k - 1.
- Perform ?
- Else if itemCount > actualDeleteCount, then
- Set k to (length - actualDeleteCount).
- Repeat, while k > actualStart,
- Let from be !
ToString (𝔽 (k + actualDeleteCount - 1)). - Let to be !
ToString (𝔽 (k + itemCount - 1)). - If ?
HasProperty (obj, from) istrue , then - Else,
- Perform ?
DeletePropertyOrThrow (obj, to).
- Perform ?
- Set k to k - 1.
- Let from be !
- Set k to actualStart.
- For each element item of items, do
- Perform ?
Set (obj,"length" ,𝔽 (length - actualDeleteCount + itemCount),true ). - Return deletedArray.
This method is intentionally generic; it does not require that its
23.1.3.32 Array.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )
An ECMAScript implementation that includes the ECMA-402 Internationalization API must implement this method as specified in the ECMA-402 specification. If an ECMAScript implementation does not include the ECMA-402 API the following specification of this method is used.
The first edition of ECMA-402 did not include a replacement specification for this method.
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.
This method performs the following steps when called:
- Let array be ?
ToObject (this value). - Let length be ?
LengthOfArrayLike (array). - Let separator be the
implementation-defined list-separator String value appropriate for thehost environment 's current locale (such as", " ). - Let result be the empty String.
- Let k be 0.
- Repeat, while k < length,
- If k > 0, set result to the
string-concatenation of result and separator. - Let element be ?
Get (array, !ToString (𝔽 (k))). - If element is neither
undefined nornull , then- Let elementString be ?
ToString (?Invoke (element,"toLocaleString" )). - Set result to the
string-concatenation of result and elementString.
- Let elementString be ?
- Set k to k + 1.
- If k > 0, set result to the
- Return result.
This method converts the elements of the array to Strings using their toLocaleString methods, and then concatenates these Strings, separated by occurrences of an toString except that it is intended to yield a locale-sensitive result corresponding with conventions of the
This method is intentionally generic; it does not require that its
23.1.3.33 Array.prototype.toReversed ( )
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let length be ?
LengthOfArrayLike (obj). - Let array be ?
ArrayCreate (length). - Let k be 0.
- Repeat, while k < length,
- Return array.
23.1.3.34 Array.prototype.toSorted ( comparator )
This method performs the following steps when called:
- If comparator is not
undefined andIsCallable (comparator) isfalse , throw aTypeError exception. - Let obj be ?
ToObject (this value). - Let length be ?
LengthOfArrayLike (obj). - Let array be ?
ArrayCreate (length). - Let sortCompare be a new
Abstract Closure with parameters (x, y) that captures comparator and performs the following steps when called:- Return ?
CompareArrayElements (x, y, comparator).
- Return ?
- Let sortedList be ?
SortIndexedProperties (obj, length, sortCompare,read-through-holes ). - Let j be 0.
- Repeat, while j < length,
- Perform !
CreateDataPropertyOrThrow (array, !ToString (𝔽 (j)), sortedList[j]). - Set j to j + 1.
- Perform !
- Return array.
23.1.3.35 Array.prototype.toSpliced ( start, skipCount, ...items )
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let length be ?
LengthOfArrayLike (obj). - Let relativeStart be ?
ToIntegerOrInfinity (start). - If relativeStart = -∞, let actualStart be 0.
- Else if relativeStart < 0, let actualStart be
max (length + relativeStart, 0). - Else, let actualStart be
min (relativeStart, length). - Let insertCount be the number of elements in items.
- If start is not present, then
- Let actualSkipCount be 0.
- Else if skipCount is not present, then
- Let actualSkipCount be length - actualStart.
- Else,
- Let sc be ?
ToIntegerOrInfinity (skipCount). - Let actualSkipCount be the result of
clamping sc between 0 and length - actualStart.
- Let sc be ?
- Let newLength be length + insertCount - actualSkipCount.
- If newLength > 253 - 1, throw a
TypeError exception. - Let newArray be ?
ArrayCreate (newLength). - Let writeIndex be 0.
- Let readIndex be actualStart + actualSkipCount.
- Repeat, while writeIndex < actualStart,
- Let propertyKey be !
ToString (𝔽 (writeIndex)). - Let iValue be ?
Get (obj, propertyKey). - Perform !
CreateDataPropertyOrThrow (newArray, propertyKey, iValue). - Set writeIndex to writeIndex + 1.
- Let propertyKey be !
- For each element item of items, do
- Let propertyKey be !
ToString (𝔽 (writeIndex)). - Perform !
CreateDataPropertyOrThrow (newArray, propertyKey, item). - Set writeIndex to writeIndex + 1.
- Let propertyKey be !
- Repeat, while writeIndex < newLength,
- Return newArray.
23.1.3.36 Array.prototype.toString ( )
This method performs the following steps when called:
- Let array be ?
ToObject (this value). - Let func be ?
Get (array,"join" ). - If
IsCallable (func) isfalse , set func to the intrinsic function%Object.prototype.toString% . - Return ?
Call (func, array).
This method is intentionally generic; it does not require that its
23.1.3.37 Array.prototype.unshift ( ...items )
This method prepends the arguments 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.
It performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let length be ?
LengthOfArrayLike (obj). - Let argCount be the number of elements in items.
- If argCount > 0, then
- If length + argCount > 253 - 1, throw a
TypeError exception. - Let k be length.
- Repeat, while k > 0,
- Let from be !
ToString (𝔽 (k - 1)). - Let to be !
ToString (𝔽 (k + argCount - 1)). - Let fromPresent be ?
HasProperty (obj, from). - If fromPresent is
true , then - Else,
Assert : fromPresent isfalse .- Perform ?
DeletePropertyOrThrow (obj, to).
- Set k to k - 1.
- Let from be !
- Let j be
+0 𝔽. - For each element item of items, do
- If length + argCount > 253 - 1, throw a
- Perform ?
Set (obj,"length" ,𝔽 (length + argCount),true ). - Return
𝔽 (length + argCount).
The
This method is intentionally generic; it does not require that its
23.1.3.38 Array.prototype.values ( )
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - Return
CreateArrayIterator (obj,value ).
23.1.3.39 Array.prototype.with ( index, value )
This method performs the following steps when called:
- Let obj be ?
ToObject (this value). - Let length be ?
LengthOfArrayLike (obj). - Let relativeIndex be ?
ToIntegerOrInfinity (index). - If relativeIndex ≥ 0, let actualIndex be relativeIndex.
- Else, let actualIndex be length + relativeIndex.
- If actualIndex ≥ length or actualIndex < 0, throw a
RangeError exception. - Let array be ?
ArrayCreate (length). - Let k be 0.
- Repeat, while k < length,
- Let propertyKey be !
ToString (𝔽 (k)). - If k = actualIndex, let fromValue be value.
- Else, let fromValue be ?
Get (obj, propertyKey). - Perform !
CreateDataPropertyOrThrow (array, propertyKey, fromValue). - Set k to k + 1.
- Let propertyKey be !
- Return array.
23.1.3.40 Array.prototype [ %Symbol.iterator% ] ( )
The initial value of the
23.1.3.41 Array.prototype [ %Symbol.unscopables% ]
The initial value of the
- Let unscopableList be
OrdinaryObjectCreate (null ). - Perform !
CreateDataPropertyOrThrow (unscopableList,"at" ,true ). - Perform !
CreateDataPropertyOrThrow (unscopableList,"copyWithin" ,true ). - Perform !
CreateDataPropertyOrThrow (unscopableList,"entries" ,true ). - Perform !
CreateDataPropertyOrThrow (unscopableList,"fill" ,true ). - Perform !
CreateDataPropertyOrThrow (unscopableList,"find" ,true ). - Perform !
CreateDataPropertyOrThrow (unscopableList,"findIndex" ,true ). - Perform !
CreateDataPropertyOrThrow (unscopableList,"findLast" ,true ). - Perform !
CreateDataPropertyOrThrow (unscopableList,"findLastIndex" ,true ). - Perform !
CreateDataPropertyOrThrow (unscopableList,"flat" ,true ). - Perform !
CreateDataPropertyOrThrow (unscopableList,"flatMap" ,true ). - Perform !
CreateDataPropertyOrThrow (unscopableList,"includes" ,true ). - Perform !
CreateDataPropertyOrThrow (unscopableList,"keys" ,true ). - Perform !
CreateDataPropertyOrThrow (unscopableList,"toReversed" ,true ). - Perform !
CreateDataPropertyOrThrow (unscopableList,"toSorted" ,true ). - Perform !
CreateDataPropertyOrThrow (unscopableList,"toSpliced" ,true ). - Perform !
CreateDataPropertyOrThrow (unscopableList,"values" ,true ). - Return unscopableList.
This property has the attributes { [[Writable]]:
The own Array.prototype prior to the ECMAScript 2015 specification. These names are ignored for 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 statement whose binding object is an Array.
The reason that
23.1.4 Properties of Array Instances
Array instances are
Array instances have a
23.1.4.1 length
The
The
Reducing the value of the
23.1.5 Array Iterator Objects
An Array Iterator is an object that represents a specific iteration over some specific Array instance object. There is not a named
23.1.5.1 CreateArrayIterator ( array, kind )
The abstract operation CreateArrayIterator takes arguments array (an Object) and kind (
- Let iterator be
OrdinaryObjectCreate (%ArrayIteratorPrototype% , « [[IteratedArrayLike]], [[ArrayLikeNextIndex]], [[ArrayLikeIterationKind]] »). - Set iterator.[[IteratedArrayLike]] to array.
- Set iterator.[[ArrayLikeNextIndex]] to 0.
- Set iterator.[[ArrayLikeIterationKind]] to kind.
- Return iterator.
23.1.5.2 The %ArrayIteratorPrototype% Object
The
- has properties that are inherited by all
Array Iterator objects . - is an
ordinary object . - has a [[Prototype]] internal slot whose value is
%Iterator.prototype% . - has the following properties:
23.1.5.2.1 %ArrayIteratorPrototype% .next ( )
- Let iteratorObj be the
this value. - If iteratorObj
is not an Object , throw aTypeError exception. - If iteratorObj does not have all of the internal slots of an
Array Iterator Instance (23.1.5.3 ), throw aTypeError exception. - Let array be iteratorObj.[[IteratedArrayLike]].
- If array is
undefined , returnCreateIteratorResultObject (undefined ,true ). - Let index be iteratorObj.[[ArrayLikeNextIndex]].
- Let kind be iteratorObj.[[ArrayLikeIterationKind]].
- If array has a [[TypedArrayName]] internal slot, then
- Let taRecord be
MakeTypedArrayWithBufferWitnessRecord (array,seq-cst ). - If
IsTypedArrayOutOfBounds (taRecord) istrue , throw aTypeError exception. - Let length be
TypedArrayLength (taRecord).
- Let taRecord be
- Else,
- Let length be ?
LengthOfArrayLike (array).
- Let length be ?
- If index ≥ length, then
- Set iteratorObj.[[IteratedArrayLike]] to
undefined . - Return
CreateIteratorResultObject (undefined ,true ).
- Set iteratorObj.[[IteratedArrayLike]] to
- Set iteratorObj.[[ArrayLikeNextIndex]] to index + 1.
- Let indexNumber be
𝔽 (index). - If kind is
key , then- Let result be indexNumber.
- Else,
- Let elementKey be !
ToString (indexNumber). - Let elementValue be ?
Get (array, elementKey). - If kind is
value , then- Let result be elementValue.
- Else,
Assert : kind iskey+value .- Let result be
CreateArrayFromList (« indexNumber, elementValue »).
- Let elementKey be !
- Return
CreateIteratorResultObject (result,false ).
23.1.5.2.2 %ArrayIteratorPrototype% [ %Symbol.toStringTag% ]
The initial value of the
This property has the attributes { [[Writable]]:
23.1.5.3 Properties of Array Iterator Instances
| Internal Slot | Type | Description |
|---|---|---|
| [[IteratedArrayLike]] |
an Object or |
The |
| [[ArrayLikeNextIndex]] |
a non-negative |
The |
| [[ArrayLikeIterationKind]] |
|
A value that identifies what is returned for each element of the iteration. |
23.2 TypedArray Objects
A TypedArray presents an array-like view of an underlying binary data buffer (
|
|
Element Type | Element Size | Conversion Operation | Description |
|---|---|---|---|---|
|
Int8Array |
|
1 |
|
8-bit two's complement signed |
|
Uint8Array |
|
1 |
|
8-bit unsigned |
|
Uint8ClampedArray |
|
1 |
|
8-bit unsigned |
|
Int16Array |
|
2 |
|
16-bit two's complement signed |
|
Uint16Array |
|
2 |
|
16-bit unsigned |
|
Int32Array |
|
4 |
|
32-bit two's complement signed |
|
Uint32Array |
|
4 |
|
32-bit unsigned |
|
BigInt64Array |
|
8 |
|
64-bit two's complement signed |
|
BigUint64Array |
|
8 |
|
64-bit unsigned |
|
Float16Array |
|
2 | 16-bit IEEE floating point | |
|
Float32Array |
|
4 | 32-bit IEEE floating point | |
|
Float64Array |
|
8 | 64-bit IEEE floating point |
In the definitions below, references to TypedArray should be replaced with the appropriate
23.2.1 The %TypedArray% Intrinsic Object
The
- is a
constructor function object that all of the TypedArrayconstructor objects inherit from. - along with its corresponding prototype object, provides common properties that are inherited by all TypedArray
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 TypedArrayconstructors do not perform asupercall to it.
23.2.1.1 %TypedArray% ( )
This function performs the following steps when called:
- Throw a
TypeError exception.
The
23.2.2 Properties of the %TypedArray% Intrinsic Object
The
- has a [[Prototype]] internal slot whose value is
%Function.prototype% . - has a
"name" property whose value is"TypedArray" . - has the following properties:
23.2.2.1 %TypedArray% .from ( source [ , mapper [ , thisArg ] ] )
This method performs the following steps when called:
- Let ctor be the
this value. - If
IsConstructor (ctor) isfalse , throw aTypeError exception. - If mapper is
undefined , then- Let mapping be
false .
- Let mapping be
- Else,
- If
IsCallable (mapper) isfalse , throw aTypeError exception. - Let mapping be
true .
- If
- Let usingIterator be ?
GetMethod (source,%Symbol.iterator% ). - If usingIterator is not
undefined , then- Let values be ?
IteratorToList (?GetIteratorFromMethod (source, usingIterator)). - Let length be the number of elements in values.
- Let targetObj be ?
TypedArrayCreateFromConstructor (ctor, «𝔽 (length) »). - Let k be 0.
- Repeat, while k < length,
Assert : values is now an emptyList .- Return targetObj.
- Let values be ?
NOTE : source is not aniterable object , so assume it is already anarray-like object .- Let arrayLike be !
ToObject (source). - Let length be ?
LengthOfArrayLike (arrayLike). - Let targetObj be ?
TypedArrayCreateFromConstructor (ctor, «𝔽 (length) »). - Let k be 0.
- Repeat, while k < length,
- Return targetObj.
23.2.2.2 %TypedArray% .of ( ...items )
This method performs the following steps when called:
- Let length be the number of elements in items.
- Let ctor be the
this value. - If
IsConstructor (ctor) isfalse , throw aTypeError exception. - Let newObj be ?
TypedArrayCreateFromConstructor (ctor, «𝔽 (length) »). - Let k be 0.
- Repeat, while k < length,
- Return newObj.
23.2.2.3 %TypedArray% .prototype
The initial value of .prototype is the
This property has the attributes { [[Writable]]:
23.2.2.4 get %TypedArray% [ %Symbol.species% ]
[%Symbol.species%] is an
- Return the
this value.
The value of the
23.2.3 Properties of the %TypedArray% Prototype Object
The
- 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.
23.2.3.1 %TypedArray% .prototype.at ( index )
- Let obj be the
this value. - Let taRecord be ?
ValidateTypedArray (obj,seq-cst ). - Let length be
TypedArrayLength (taRecord). - Let relativeIndex be ?
ToIntegerOrInfinity (index). - If relativeIndex ≥ 0, then
- Let k be relativeIndex.
- Else,
- Let k be length + relativeIndex.
- If k < 0 or k ≥ length, return
undefined . - Return !
Get (obj, !ToString (𝔽 (k))).
23.2.3.2 get %TypedArray% .prototype.buffer
.prototype.buffer is an
- Let obj be the
this value. - Perform ?
RequireInternalSlot (obj, [[TypedArrayName]]). Assert : obj has a [[ViewedArrayBuffer]] internal slot.- Let buffer be obj.[[ViewedArrayBuffer]].
- Return buffer.
23.2.3.3 get %TypedArray% .prototype.byteLength
.prototype.byteLength is an
- Let obj be the
this value. - Perform ?
RequireInternalSlot (obj, [[TypedArrayName]]). Assert : obj has a [[ViewedArrayBuffer]] internal slot.- Let taRecord be
MakeTypedArrayWithBufferWitnessRecord (obj,seq-cst ). - If
IsTypedArrayOutOfBounds (taRecord) istrue , return+0 𝔽. - Let size be
TypedArrayByteLength (taRecord). - Return
𝔽 (size).
23.2.3.4 get %TypedArray% .prototype.byteOffset
.prototype.byteOffset is an
- Let obj be the
this value. - Perform ?
RequireInternalSlot (obj, [[TypedArrayName]]). Assert : obj has a [[ViewedArrayBuffer]] internal slot.- Let taRecord be
MakeTypedArrayWithBufferWitnessRecord (obj,seq-cst ). - If
IsTypedArrayOutOfBounds (taRecord) istrue , return+0 𝔽. - Let offset be obj.[[ByteOffset]].
- Return
𝔽 (offset).
23.2.3.5 %TypedArray% .prototype.constructor
The initial value of .prototype.constructor is
23.2.3.6 %TypedArray% .prototype.copyWithin ( target, start [ , end ] )
The interpretation and use of the arguments of this method are the same as for Array.prototype.copyWithin as defined in
This method performs the following steps when called:
- Let obj be the
this value. - Let taRecord be ?
ValidateTypedArray (obj,seq-cst ). - Let length be
TypedArrayLength (taRecord). - Let relativeTarget be ?
ToIntegerOrInfinity (target). - If relativeTarget = -∞, let targetIndex be 0.
- Else if relativeTarget < 0, let targetIndex be
max (length + relativeTarget, 0). - Else, let targetIndex be
min (relativeTarget, length). - Let relativeStart be ?
ToIntegerOrInfinity (start). - If relativeStart = -∞, let startIndex be 0.
- Else if relativeStart < 0, let startIndex be
max (length + relativeStart, 0). - Else, let startIndex be
min (relativeStart, length). - If end is
undefined , let relativeEnd be length; else let relativeEnd be ?ToIntegerOrInfinity (end). - If relativeEnd = -∞, let endIndex be 0.
- Else if relativeEnd < 0, let endIndex be
max (length + relativeEnd, 0). - Else, let endIndex be
min (relativeEnd, length). - Let count be
min (endIndex - startIndex, length - targetIndex). - If count > 0, then
NOTE : The copying must be performed in a manner that preserves the bit-level encoding of the source data.- Let buffer be obj.[[ViewedArrayBuffer]].
- Set taRecord to
MakeTypedArrayWithBufferWitnessRecord (obj,seq-cst ). - If
IsTypedArrayOutOfBounds (taRecord) istrue , throw aTypeError exception. - Set length to
TypedArrayLength (taRecord). NOTE : Side-effects of the above steps may have reduced the size of obj, in which case copying should proceed with the longest still-applicable prefix.- Set count to
min (count, length - startIndex, length - targetIndex). - Let elementSize be
TypedArrayElementSize (obj). - Let byteOffset be obj.[[ByteOffset]].
- Let toByteIndex be (targetIndex × elementSize) + byteOffset.
- Let fromByteIndex be (startIndex × elementSize) + byteOffset.
- Let countBytes be count × elementSize.
- If fromByteIndex < toByteIndex and toByteIndex < fromByteIndex + countBytes, then
- Let direction be -1.
- Set fromByteIndex to fromByteIndex + countBytes - 1.
- Set toByteIndex to toByteIndex + countBytes - 1.
- Else,
- Let direction be 1.
- Repeat, while countBytes > 0,
- Let value be
GetValueFromBuffer (buffer, fromByteIndex,uint8 ,true ,unordered ). - Perform
SetValueInBuffer (buffer, toByteIndex,uint8 , value,true ,unordered ). - Set fromByteIndex to fromByteIndex + direction.
- Set toByteIndex to toByteIndex + direction.
- Set countBytes to countBytes - 1.
- Let value be
- Return obj.
23.2.3.7 %TypedArray% .prototype.entries ( )
This method performs the following steps when called:
- Let obj be the
this value. - Perform ?
ValidateTypedArray (obj,seq-cst ). - Return
CreateArrayIterator (obj,key+value ).
23.2.3.8 %TypedArray% .prototype.every ( callback [ , thisArg ] )
The interpretation and use of the arguments of this method are the same as for Array.prototype.every as defined in
This method performs the following steps when called:
- Let obj be the
this value. - Let taRecord be ?
ValidateTypedArray (obj,seq-cst ). - Let length be
TypedArrayLength (taRecord). - If
IsCallable (callback) isfalse , throw aTypeError exception. - Let k be 0.
- Repeat, while k < length,
- Return
true .
This method is not generic. The
23.2.3.9 %TypedArray% .prototype.fill ( value [ , start [ , end ] ] )
The interpretation and use of the arguments of this method are the same as for Array.prototype.fill as defined in
This method performs the following steps when called:
- Let obj be the
this value. - Let taRecord be ?
ValidateTypedArray (obj,seq-cst ). - Let length be
TypedArrayLength (taRecord). - If obj.[[ContentType]] is
bigint , set value to ?ToBigInt (value). - Else, set value to ?
ToNumber (value). - Let relativeStart be ?
ToIntegerOrInfinity (start). - If relativeStart = -∞, let startIndex be 0.
- Else if relativeStart < 0, let startIndex be
max (length + relativeStart, 0). - Else, let startIndex be
min (relativeStart, length). - If end is
undefined , let relativeEnd be length; else let relativeEnd be ?ToIntegerOrInfinity (end). - If relativeEnd = -∞, let endIndex be 0.
- Else if relativeEnd < 0, let endIndex be
max (length + relativeEnd, 0). - Else, let endIndex be
min (relativeEnd, length). - Set taRecord to
MakeTypedArrayWithBufferWitnessRecord (obj,seq-cst ). - If
IsTypedArrayOutOfBounds (taRecord) istrue , throw aTypeError exception. - Set length to
TypedArrayLength (taRecord). - Set endIndex to
min (endIndex, length). - Let k be startIndex.
- Repeat, while k < endIndex,
- Return obj.
23.2.3.10 %TypedArray% .prototype.filter ( callback [ , thisArg ] )
The interpretation and use of the arguments of this method are the same as for Array.prototype.filter as defined in
This method performs the following steps when called:
- Let obj be the
this value. - Let taRecord be ?
ValidateTypedArray (obj,seq-cst ). - Let length be
TypedArrayLength (taRecord). - If
IsCallable (callback) isfalse , throw aTypeError exception. - Let kept be a new empty
List . - Let captured be 0.
- Let k be 0.
- Repeat, while k < length,
- Let result be ?
TypedArraySpeciesCreate (obj, «𝔽 (captured) »). - Let n be 0.
- For each element element of kept, do
- Return result.
This method is not generic. The
23.2.3.11 %TypedArray% .prototype.find ( predicate [ , thisArg ] )
The interpretation and use of the arguments of this method are the same as for Array.prototype.find as defined in
This method performs the following steps when called:
- Let obj be the
this value. - Let taRecord be ?
ValidateTypedArray (obj,seq-cst ). - Let length be
TypedArrayLength (taRecord). - Let findRecord be ?
FindViaPredicate (obj, length,ascending , predicate, thisArg). - Return findRecord.[[Value]].
This method is not generic. The
23.2.3.12 %TypedArray% .prototype.findIndex ( predicate [ , thisArg ] )
The interpretation and use of the arguments of this method are the same as for Array.prototype.findIndex as defined in
This method performs the following steps when called:
- Let obj be the
this value. - Let taRecord be ?
ValidateTypedArray (obj,seq-cst ). - Let length be
TypedArrayLength (taRecord). - Let findRecord be ?
FindViaPredicate (obj, length,ascending , predicate, thisArg). - Return findRecord.[[Index]].
This method is not generic. The
23.2.3.13 %TypedArray% .prototype.findLast ( predicate [ , thisArg ] )
The interpretation and use of the arguments of this method are the same as for Array.prototype.findLast as defined in
This method performs the following steps when called:
- Let obj be the
this value. - Let taRecord be ?
ValidateTypedArray (obj,seq-cst ). - Let length be
TypedArrayLength (taRecord). - Let findRecord be ?
FindViaPredicate (obj, length,descending , predicate, thisArg). - Return findRecord.[[Value]].
This method is not generic. The
23.2.3.14 %TypedArray% .prototype.findLastIndex ( predicate [ , thisArg ] )
The interpretation and use of the arguments of this method are the same as for Array.prototype.findLastIndex as defined in
This method performs the following steps when called:
- Let obj be the
this value. - Let taRecord be ?
ValidateTypedArray (obj,seq-cst ). - Let length be
TypedArrayLength (taRecord). - Let findRecord be ?
FindViaPredicate (obj, length,descending , predicate, thisArg). - Return findRecord.[[Index]].
This method is not generic. The
23.2.3.15 %TypedArray% .prototype.forEach ( callback [ , thisArg ] )
The interpretation and use of the arguments of this method are the same as for Array.prototype.forEach as defined in
This method performs the following steps when called:
- Let obj be the
this value. - Let taRecord be ?
ValidateTypedArray (obj,seq-cst ). - Let length be
TypedArrayLength (taRecord). - If
IsCallable (callback) isfalse , throw aTypeError exception. - Let k be 0.
- Repeat, while k < length,
- Return
undefined .
This method is not generic. The
23.2.3.16 %TypedArray% .prototype.includes ( searchElement [ , fromIndex ] )
The interpretation and use of the arguments of this method are the same as for Array.prototype.includes as defined in
This method performs the following steps when called:
- Let obj be the
this value. - Let taRecord be ?
ValidateTypedArray (obj,seq-cst ). - Let length be
TypedArrayLength (taRecord). - If length = 0, return
false . - Let n be ?
ToIntegerOrInfinity (fromIndex). Assert : If fromIndex isundefined , then n is 0.- If n = +∞, return
false . - If n = -∞, set n to 0.
- If n ≥ 0, then
- Let k be n.
- Else,
- Let k be length + n.
- If k < 0, set k to 0.
- Repeat, while k < length,
- Let elementK be !
Get (obj, !ToString (𝔽 (k))). - If
SameValueZero (searchElement, elementK) istrue , returntrue . - Set k to k + 1.
- Let elementK be !
- Return
false .
This method is not generic. The
23.2.3.17 %TypedArray% .prototype.indexOf ( searchElement [ , fromIndex ] )
The interpretation and use of the arguments of this method are the same as for Array.prototype.indexOf as defined in
This method performs the following steps when called:
- Let obj be the
this value. - Let taRecord be ?
ValidateTypedArray (obj,seq-cst ). - Let length be
TypedArrayLength (taRecord). - If length = 0, return
-1 𝔽. - Let n be ?
ToIntegerOrInfinity (fromIndex). Assert : If fromIndex isundefined , then n is 0.- If n = +∞, return
-1 𝔽. - If n = -∞, set n to 0.
- If n ≥ 0, then
- Let k be n.
- Else,
- Let k be length + n.
- If k < 0, set k to 0.
- Repeat, while k < length,
- Let propertyKey be !
ToString (𝔽 (k)). - Let kPresent be !
HasProperty (obj, propertyKey). - If kPresent is
true , then- Let elementK be !
Get (obj, propertyKey). - If
IsStrictlyEqual (searchElement, elementK) istrue , return𝔽 (k).
- Let elementK be !
- Set k to k + 1.
- Let propertyKey be !
- Return
-1 𝔽.
This method is not generic. The
23.2.3.18 %TypedArray% .prototype.join ( separator )
The interpretation and use of the arguments of this method are the same as for Array.prototype.join as defined in
This method performs the following steps when called:
- Let obj be the
this value. - Let taRecord be ?
ValidateTypedArray (obj,seq-cst ). - Let length be
TypedArrayLength (taRecord). - If separator is
undefined , let sep be"," . - Else, let sep be ?
ToString (separator). - Let result be the empty String.
- Let k be 0.
- Repeat, while k < length,
- If k > 0, set result to the
string-concatenation of result and sep. - Let element be !
Get (obj, !ToString (𝔽 (k))). - If element is not
undefined , then- Let elementString be !
ToString (element). - Set result to the
string-concatenation of result and elementString.
- Let elementString be !
- Set k to k + 1.
- If k > 0, set result to the
- Return result.
This method is not generic. The
23.2.3.19 %TypedArray% .prototype.keys ( )
This method performs the following steps when called:
- Let obj be the
this value. - Perform ?
ValidateTypedArray (obj,seq-cst ). - Return
CreateArrayIterator (obj,key ).
23.2.3.20 %TypedArray% .prototype.lastIndexOf ( searchElement [ , fromIndex ] )
The interpretation and use of the arguments of this method are the same as for Array.prototype.lastIndexOf as defined in
This method performs the following steps when called:
- Let obj be the
this value. - Let taRecord be ?
ValidateTypedArray (obj,seq-cst ). - Let length be
TypedArrayLength (taRecord). - If length = 0, return
-1 𝔽. - If fromIndex is present, let n be ?
ToIntegerOrInfinity (fromIndex); else let n be length - 1. - If n = -∞, return
-1 𝔽. - If n ≥ 0, then
- Let k be
min (n, length - 1).
- Let k be
- Else,
- Let k be length + n.
- Repeat, while k ≥ 0,
- Let propertyKey be !
ToString (𝔽 (k)). - Let kPresent be !
HasProperty (obj, propertyKey). - If kPresent is
true , then- Let elementK be !
Get (obj, propertyKey). - If
IsStrictlyEqual (searchElement, elementK) istrue , return𝔽 (k).
- Let elementK be !
- Set k to k - 1.
- Let propertyKey be !
- Return
-1 𝔽.
This method is not generic. The
23.2.3.21 get %TypedArray% .prototype.length
.prototype.length is an
- Let obj be the
this value. - Perform ?
RequireInternalSlot (obj, [[TypedArrayName]]). Assert : obj has [[ViewedArrayBuffer]] and [[ArrayLength]] internal slots.- Let taRecord be
MakeTypedArrayWithBufferWitnessRecord (obj,seq-cst ). - If
IsTypedArrayOutOfBounds (taRecord) istrue , return+0 𝔽. - Let length be
TypedArrayLength (taRecord). - Return
𝔽 (length).
This function is not generic. The
23.2.3.22 %TypedArray% .prototype.map ( callback [ , thisArg ] )
The interpretation and use of the arguments of this method are the same as for Array.prototype.map as defined in
This method performs the following steps when called:
- Let obj be the
this value. - Let taRecord be ?
ValidateTypedArray (obj,seq-cst ). - Let length be
TypedArrayLength (taRecord). - If
IsCallable (callback) isfalse , throw aTypeError exception. - Let result be ?
TypedArraySpeciesCreate (obj, «𝔽 (length) »). - Let k be 0.
- Repeat, while k < length,
- Return result.
This method is not generic. The
23.2.3.23 %TypedArray% .prototype.reduce ( callback [ , initialValue ] )
The interpretation and use of the arguments of this method are the same as for Array.prototype.reduce as defined in
This method performs the following steps when called:
- Let obj be the
this value. - Let taRecord be ?
ValidateTypedArray (obj,seq-cst ). - Let length be
TypedArrayLength (taRecord). - If
IsCallable (callback) isfalse , throw aTypeError exception. - If length = 0 and initialValue is not present, throw a
TypeError exception. - Let k be 0.
- Let accumulator be
undefined . - If initialValue is present, then
- Set accumulator to initialValue.
- Else,
- Repeat, while k < length,
- Return accumulator.
This method is not generic. The
23.2.3.24 %TypedArray% .prototype.reduceRight ( callback [ , initialValue ] )
The interpretation and use of the arguments of this method are the same as for Array.prototype.reduceRight as defined in
This method performs the following steps when called:
- Let obj be the
this value. - Let taRecord be ?
ValidateTypedArray (obj,seq-cst ). - Let length be
TypedArrayLength (taRecord). - If
IsCallable (callback) isfalse , throw aTypeError exception. - If length = 0 and initialValue is not present, throw a
TypeError exception. - Let k be length - 1.
- Let accumulator be
undefined . - If initialValue is present, then
- Set accumulator to initialValue.
- Else,
- Repeat, while k ≥ 0,
- Return accumulator.
This method is not generic. The
23.2.3.25 %TypedArray% .prototype.reverse ( )
The interpretation and use of the arguments of this method are the same as for Array.prototype.reverse as defined in
This method performs the following steps when called:
- Let obj be the
this value. - Let taRecord be ?
ValidateTypedArray (obj,seq-cst ). - Let length be
TypedArrayLength (taRecord). - Let middle be
floor (length / 2). - Let lower be 0.
- Repeat, while lower ≠ middle,
- Return obj.
This method is not generic. The
23.2.3.26 %TypedArray% .prototype.set ( source [ , offset ] )
This method sets multiple values in this TypedArray, reading the values from source. The details differ based upon the type of source. The optional offset value indicates the first element index in this TypedArray where values are written. If omitted, it is assumed to be 0.
It performs the following steps when called:
- Let target be the
this value. - Perform ?
RequireInternalSlot (target, [[TypedArrayName]]). Assert : target has a [[ViewedArrayBuffer]] internal slot.- Let targetOffset be ?
ToIntegerOrInfinity (offset). - If targetOffset < 0, throw a
RangeError exception. - If source
is an Object that has a [[TypedArrayName]] internal slot, then- Perform ?
SetTypedArrayFromTypedArray (target, targetOffset, source).
- Perform ?
- Else,
- Perform ?
SetTypedArrayFromArrayLike (target, targetOffset, source).
- Perform ?
- Return
undefined .
This method is not generic. The
23.2.3.26.1 SetTypedArrayFromArrayLike ( target, targetOffset, source )
The abstract operation SetTypedArrayFromArrayLike takes arguments target (a
- Let targetRecord be
MakeTypedArrayWithBufferWitnessRecord (target,seq-cst ). - If
IsTypedArrayOutOfBounds (targetRecord) istrue , throw aTypeError exception. - Let targetLength be
TypedArrayLength (targetRecord). - Set source to ?
ToObject (source). - Let sourceLength be ?
LengthOfArrayLike (source). - If targetOffset = +∞, throw a
RangeError exception. - If sourceLength + targetOffset > targetLength, throw a
RangeError exception. - Let k be 0.
- Repeat, while k < sourceLength,
- Let propertyKey be !
ToString (𝔽 (k)). - Let value be ?
Get (source, propertyKey). - Let targetIndex be
𝔽 (targetOffset + k). - Perform ?
TypedArraySetElement (target, targetIndex, value). - Set k to k + 1.
- Let propertyKey be !
- Return
unused .
23.2.3.26.2 SetTypedArrayFromTypedArray ( target, targetOffset, source )
The abstract operation SetTypedArrayFromTypedArray takes arguments target (a
- Let targetBuffer be target.[[ViewedArrayBuffer]].
- Let targetRecord be
MakeTypedArrayWithBufferWitnessRecord (target,seq-cst ). - If
IsTypedArrayOutOfBounds (targetRecord) istrue , throw aTypeError exception. - Let targetLength be
TypedArrayLength (targetRecord). - Let sourceBuffer be source.[[ViewedArrayBuffer]].
- Let sourceRecord be
MakeTypedArrayWithBufferWitnessRecord (source,seq-cst ). - If
IsTypedArrayOutOfBounds (sourceRecord) istrue , throw aTypeError exception. - Let sourceLength be
TypedArrayLength (sourceRecord). - Let targetType be
TypedArrayElementType (target). - Let targetElementSize be
TypedArrayElementSize (target). - Let targetByteOffset be target.[[ByteOffset]].
- Let sourceType be
TypedArrayElementType (source). - Let sourceElementSize be
TypedArrayElementSize (source). - Let sourceByteOffset be source.[[ByteOffset]].
- If targetOffset = +∞, throw a
RangeError exception. - If sourceLength + targetOffset > targetLength, throw a
RangeError exception. - If target.[[ContentType]] is not source.[[ContentType]], throw a
TypeError exception. - If
IsSharedArrayBuffer (sourceBuffer) istrue ,IsSharedArrayBuffer (targetBuffer) istrue , and sourceBuffer.[[ArrayBufferData]] is targetBuffer.[[ArrayBufferData]], let sameSharedArrayBuffer betrue ; else let sameSharedArrayBuffer befalse . - If
SameValue (sourceBuffer, targetBuffer) istrue or sameSharedArrayBuffer istrue , then- Let sourceByteLength be
TypedArrayByteLength (sourceRecord). - Set sourceBuffer to ?
CloneArrayBuffer (sourceBuffer, sourceByteOffset, sourceByteLength). - Let sourceByteIndex be 0.
- Let sourceByteLength be
- Else,
- Let sourceByteIndex be sourceByteOffset.
- Let targetByteIndex be (targetOffset × targetElementSize) + targetByteOffset.
- Let limit be targetByteIndex + (targetElementSize × sourceLength).
- If sourceType is targetType, then
NOTE : The transfer must be performed in a manner that preserves the bit-level encoding of the source data.- Repeat, while targetByteIndex < limit,
- Let value be
GetValueFromBuffer (sourceBuffer, sourceByteIndex,uint8 ,true ,unordered ). - Perform
SetValueInBuffer (targetBuffer, targetByteIndex,uint8 , value,true ,unordered ). - Set sourceByteIndex to sourceByteIndex + 1.
- Set targetByteIndex to targetByteIndex + 1.
- Let value be
- Else,
- Repeat, while targetByteIndex < limit,
- Let value be
GetValueFromBuffer (sourceBuffer, sourceByteIndex, sourceType,true ,unordered ). - Perform
SetValueInBuffer (targetBuffer, targetByteIndex, targetType, value,true ,unordered ). - Set sourceByteIndex to sourceByteIndex + sourceElementSize.
- Set targetByteIndex to targetByteIndex + targetElementSize.
- Let value be
- Repeat, while targetByteIndex < limit,
- Return
unused .
23.2.3.27 %TypedArray% .prototype.slice ( start, end )
The interpretation and use of the arguments of this method are the same as for Array.prototype.slice as defined in
This method performs the following steps when called:
- Let obj be the
this value. - Let taRecord be ?
ValidateTypedArray (obj,seq-cst ). - Let sourceArrayLength be
TypedArrayLength (taRecord). - Let relativeStart be ?
ToIntegerOrInfinity (start). - If relativeStart = -∞, let startIndex be 0.
- Else if relativeStart < 0, let startIndex be
max (sourceArrayLength + relativeStart, 0). - Else, let startIndex be
min (relativeStart, sourceArrayLength). - If end is
undefined , let relativeEnd be sourceArrayLength; else let relativeEnd be ?ToIntegerOrInfinity (end). - If relativeEnd = -∞, let endIndex be 0.
- Else if relativeEnd < 0, let endIndex be
max (sourceArrayLength + relativeEnd, 0). - Else, let endIndex be
min (relativeEnd, sourceArrayLength). - Let countBytes be
max (endIndex - startIndex, 0). - Let resultArray be ?
TypedArraySpeciesCreate (obj, «𝔽 (countBytes) »). - If countBytes > 0, then
- Set taRecord to
MakeTypedArrayWithBufferWitnessRecord (obj,seq-cst ). - If
IsTypedArrayOutOfBounds (taRecord) istrue , throw aTypeError exception. - Set endIndex to
min (endIndex,TypedArrayLength (taRecord)). - Set countBytes to
max (endIndex - startIndex, 0). - Let sourceType be
TypedArrayElementType (obj). - Let targetType be
TypedArrayElementType (resultArray). - If sourceType is targetType, then
NOTE : The transfer must be performed in a manner that preserves the bit-level encoding of the source data.- Let sourceBuffer be obj.[[ViewedArrayBuffer]].
- Let targetBuffer be resultArray.[[ViewedArrayBuffer]].
- Let elementSize be
TypedArrayElementSize (obj). - Let sourceByteOffset be obj.[[ByteOffset]].
- Let sourceByteIndex be (startIndex × elementSize) + sourceByteOffset.
- Let targetByteIndex be resultArray.[[ByteOffset]].
- Let endByteIndex be targetByteIndex + (countBytes × elementSize).
- Repeat, while targetByteIndex < endByteIndex,
- Let value be
GetValueFromBuffer (sourceBuffer, sourceByteIndex,uint8 ,true ,unordered ). - Perform
SetValueInBuffer (targetBuffer, targetByteIndex,uint8 , value,true ,unordered ). - Set sourceByteIndex to sourceByteIndex + 1.
- Set targetByteIndex to targetByteIndex + 1.
- Let value be
- Else,
- Set taRecord to
- Return resultArray.
This method is not generic. The
23.2.3.28 %TypedArray% .prototype.some ( callback [ , thisArg ] )
The interpretation and use of the arguments of this method are the same as for Array.prototype.some as defined in
This method performs the following steps when called:
- Let obj be the
this value. - Let taRecord be ?
ValidateTypedArray (obj,seq-cst ). - Let length be
TypedArrayLength (taRecord). - If
IsCallable (callback) isfalse , throw aTypeError exception. - Let k be 0.
- Repeat, while k < length,
- Return
false .
This method is not generic. The
23.2.3.29 %TypedArray% .prototype.sort ( comparator )
This is a distinct method that, except as described below, implements the same requirements as those of Array.prototype.sort as defined in
This method is not generic. The
It performs the following steps when called:
- If comparator is not
undefined andIsCallable (comparator) isfalse , throw aTypeError exception. - Let obj be the
this value. - Let taRecord be ?
ValidateTypedArray (obj,seq-cst ). - Let length be
TypedArrayLength (taRecord). NOTE : The following closure performs a numeric comparison rather than the string comparison used in23.1.3.30 .- Let sortCompare be a new
Abstract Closure with parameters (x, y) that captures comparator and performs the following steps when called:- Return ?
CompareTypedArrayElements (x, y, comparator).
- Return ?
- Let sortedList be ?
SortIndexedProperties (obj, length, sortCompare,read-through-holes ). - Let j be 0.
- Repeat, while j < length,
- Return obj.
Because
23.2.3.30 %TypedArray% .prototype.subarray ( start, end )
This method returns a new TypedArray whose element type is the element type of this TypedArray and whose ArrayBuffer is the ArrayBuffer of this TypedArray, referencing the elements in the
It performs the following steps when called:
- Let obj be the
this value. - Perform ?
RequireInternalSlot (obj, [[TypedArrayName]]). Assert : obj has a [[ViewedArrayBuffer]] internal slot.- Let buffer be obj.[[ViewedArrayBuffer]].
- Let sourceRecord be
MakeTypedArrayWithBufferWitnessRecord (obj,seq-cst ). - If
IsTypedArrayOutOfBounds (sourceRecord) istrue , then- Let sourceLength be 0.
- Else,
- Let sourceLength be
TypedArrayLength (sourceRecord).
- Let sourceLength be
- Let relativeStart be ?
ToIntegerOrInfinity (start). - If relativeStart = -∞, let startIndex be 0.
- Else if relativeStart < 0, let startIndex be
max (sourceLength + relativeStart, 0). - Else, let startIndex be
min (relativeStart, sourceLength). - Let elementSize be
TypedArrayElementSize (obj). - Let sourceByteOffset be obj.[[ByteOffset]].
- Let beginByteOffset be sourceByteOffset + (startIndex × elementSize).
- If obj.[[ArrayLength]] is
auto and end isundefined , then- Let argList be « buffer,
𝔽 (beginByteOffset) ».
- Let argList be « buffer,
- Else,
- If end is
undefined , let relativeEnd be sourceLength; else let relativeEnd be ?ToIntegerOrInfinity (end). - If relativeEnd = -∞, let endIndex be 0.
- Else if relativeEnd < 0, let endIndex be
max (sourceLength + relativeEnd, 0). - Else, let endIndex be
min (relativeEnd, sourceLength). - Let newLength be
max (endIndex - startIndex, 0). - Let argList be « buffer,
𝔽 (beginByteOffset),𝔽 (newLength) ».
- If end is
- Return ?
TypedArraySpeciesCreate (obj, argList).
This method is not generic. The
23.2.3.31 %TypedArray% .prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )
This is a distinct method that implements the same algorithm as Array.prototype.toLocaleString as defined in
This method is not generic.
If the ECMAScript implementation includes the ECMA-402 Internationalization API this method is based upon the algorithm for Array.prototype.toLocaleString that is in the ECMA-402 specification.
23.2.3.32 %TypedArray% .prototype.toReversed ( )
This method performs the following steps when called:
- Let obj be the
this value. - Let taRecord be ?
ValidateTypedArray (obj,seq-cst ). - Let length be
TypedArrayLength (taRecord). - Let resultArray be ?
TypedArrayCreateSameType (obj, length). - Let k be 0.
- Repeat, while k < length,
- Return resultArray.
23.2.3.33 %TypedArray% .prototype.toSorted ( comparator )
This method performs the following steps when called:
- If comparator is not
undefined andIsCallable (comparator) isfalse , throw aTypeError exception. - Let obj be the
this value. - Let taRecord be ?
ValidateTypedArray (obj,seq-cst ). - Let length be
TypedArrayLength (taRecord). - Let resultArray be ?
TypedArrayCreateSameType (obj, length). NOTE : The following closure performs a numeric comparison rather than the string comparison used in23.1.3.34 .- Let sortCompare be a new
Abstract Closure with parameters (x, y) that captures comparator and performs the following steps when called:- Return ?
CompareTypedArrayElements (x, y, comparator).
- Return ?
- Let sortedList be ?
SortIndexedProperties (obj, length, sortCompare,read-through-holes ). - Let j be 0.
- Repeat, while j < length,
- Return resultArray.
23.2.3.34 %TypedArray% .prototype.toString ( )
The initial value of the
23.2.3.35 %TypedArray% .prototype.values ( )
This method performs the following steps when called:
- Let obj be the
this value. - Perform ?
ValidateTypedArray (obj,seq-cst ). - Return
CreateArrayIterator (obj,value ).
23.2.3.36 %TypedArray% .prototype.with ( index, value )
This method performs the following steps when called:
- Let obj be the
this value. - Let taRecord be ?
ValidateTypedArray (obj,seq-cst ). - Let length be
TypedArrayLength (taRecord). - Let relativeIndex be ?
ToIntegerOrInfinity (index). - If relativeIndex ≥ 0, let actualIndex be relativeIndex.
- Else, let actualIndex be length + relativeIndex.
- If obj.[[ContentType]] is
bigint , let numericValue be ?ToBigInt (value). - Else, let numericValue be ?
ToNumber (value). - If
IsValidIntegerIndex (obj,𝔽 (actualIndex)) isfalse , throw aRangeError exception. - Let resultArray be ?
TypedArrayCreateSameType (obj, length). - Let k be 0.
- Repeat, while k < length,
- Return resultArray.
23.2.3.37 %TypedArray% .prototype [ %Symbol.iterator% ] ( )
The initial value of the
23.2.3.38 get %TypedArray% .prototype [ %Symbol.toStringTag% ]
.prototype[%Symbol.toStringTag%] is an
- Let obj be the
this value. - If obj
is not an Object , returnundefined . - If obj does not have a [[TypedArrayName]] internal slot, return
undefined . - Let name be obj.[[TypedArrayName]].
Assert : nameis a String .- Return name.
This property has the attributes { [[Enumerable]]:
The initial value of the
23.2.4 Abstract Operations for TypedArray Objects
23.2.4.1 TypedArrayCreateFromConstructor ( ctor, argList )
The abstract operation TypedArrayCreateFromConstructor takes arguments ctor (a
- Let ta be ?
Construct (ctor, argList). - Let taRecord be ?
ValidateTypedArray (ta,seq-cst ). Assert : ta has all the internal slots mentioned inProperties of TypedArray Instances .- If the number of elements in argList is 1 and argList[0]
is a Number , then- If
IsTypedArrayOutOfBounds (taRecord) istrue , throw aTypeError exception. - Let length be
TypedArrayLength (taRecord). - If length <
ℝ (argList[0]), throw aTypeError exception.
- If
- Return ta.
23.2.4.2 TypedArrayCreateSameType ( exemplar, length )
The abstract operation TypedArrayCreateSameType takes arguments exemplar (a
- Let ctor be the intrinsic object associated with the
constructor name exemplar.[[TypedArrayName]] inTable 70 . - Let result be ?
.TypedArrayCreateFromConstructor (ctor, «𝔽 (length) ») Assert : result has [[TypedArrayName]] and [[ContentType]] internal slots.Assert : result.[[ContentType]] is exemplar.[[ContentType]].- Return result.
23.2.4.3 TypedArraySpeciesCreate ( exemplar, argList )
The abstract operation TypedArraySpeciesCreate takes arguments exemplar (a
- Let defaultCtor be the intrinsic object associated with the
constructor name exemplar.[[TypedArrayName]] inTable 70 . - Let ctor be ?
SpeciesConstructor (exemplar, defaultCtor). - Let result be ?
TypedArrayCreateFromConstructor (ctor, argList). - If result.[[ContentType]] is not exemplar.[[ContentType]], throw a
TypeError exception. - Return result.
23.2.4.4 ValidateTypedArray ( obj, order )
The abstract operation ValidateTypedArray takes arguments obj (an
- Perform ?
RequireInternalSlot (obj, [[TypedArrayName]]). Assert : obj has a [[ViewedArrayBuffer]] internal slot.- Let taRecord be
MakeTypedArrayWithBufferWitnessRecord (obj, order). - If
IsTypedArrayOutOfBounds (taRecord) istrue , throw aTypeError exception. - Return taRecord.
23.2.4.5 TypedArrayElementSize ( obj )
The abstract operation TypedArrayElementSize takes argument obj (a
- Return the Element Size value specified in
Table 70 for obj.[[TypedArrayName]].
23.2.4.6 TypedArrayElementType ( obj )
The abstract operation TypedArrayElementType takes argument obj (a
- Return the Element Type value specified in
Table 70 for obj.[[TypedArrayName]].
23.2.4.7 CompareTypedArrayElements ( x, y, comparator )
The abstract operation CompareTypedArrayElements takes arguments x (a Number or a BigInt), y (a Number or a BigInt), and comparator (a
Assert : xis a Number and yis a Number , or xis a BigInt and yis a BigInt .- If comparator is not
undefined , then - If x is
NaN and y isNaN , return+0 𝔽. - If x is
NaN , return1 𝔽. - If y is
NaN , return-1 𝔽. - If x < y, return
-1 𝔽. - If x > y, return
1 𝔽. - If x is
-0 𝔽 and y is+0 𝔽, return-1 𝔽. - If x is
+0 𝔽 and y is-0 𝔽, return1 𝔽. - Return
+0 𝔽.
23.2.5 The TypedArray Constructors
Each TypedArray
- is an intrinsic object that has the structure described below, differing only in the name used as the
constructor name instead of TypedArray, inTable 70 , except where otherwise noted. - is a function whose behaviour differs based upon the number and types of its arguments. The actual behaviour of a call of TypedArray depends upon the number and kind of arguments that are passed to it.
- is not intended to be called as a function and will throw an exception when called in that manner.
- may be used as the value of an
extendsclause of a class definition. Subclassconstructors that intend to inherit the specified TypedArray behaviour must include asupercall to the TypedArrayconstructor to create and initialize the subclass instance with the internal state necessary to support the built-in methods of%TypedArray% .prototype.
23.2.5.1 TypedArray ( ...args )
Each TypedArray
- If NewTarget is
undefined , throw aTypeError exception. - Let ctorName be the String value of the
Constructor Name value specified inTable 70 for this TypedArrayconstructor . - Let proto be
"%TypedArray.prototype%". - Let numberOfArgs be the number of elements in args.
- If numberOfArgs = 0, return ?
AllocateTypedArray (ctorName, NewTarget, proto, 0). - Let firstArg be args[0].
- If firstArg
is an Object , then- Let obj be ?
AllocateTypedArray (ctorName, NewTarget, proto). - If firstArg has a [[TypedArrayName]] internal slot, then
- Perform ?
InitializeTypedArrayFromTypedArray (obj, firstArg).
- Perform ?
- Else if firstArg has an [[ArrayBufferData]] internal slot, then
- If numberOfArgs > 1, let byteOffset be args[1]; else let byteOffset be
undefined . - If numberOfArgs > 2, let length be args[2]; else let length be
undefined . - Perform ?
InitializeTypedArrayFromArrayBuffer (obj, firstArg, byteOffset, length).
- If numberOfArgs > 1, let byteOffset be args[1]; else let byteOffset be
- Else,
Assert : firstArgis an Object and firstArg does not have either a [[TypedArrayName]] or an [[ArrayBufferData]] internal slot.- Let usingIterator be ?
GetMethod (firstArg,%Symbol.iterator% ). - If usingIterator is not
undefined , then- Let values be ?
IteratorToList (?GetIteratorFromMethod (firstArg, usingIterator)). - Perform ?
InitializeTypedArrayFromList (obj, values).
- Let values be ?
- Else,
NOTE : firstArg is not aniterable object , so assume it is already anarray-like object .- Perform ?
InitializeTypedArrayFromArrayLike (obj, firstArg).
- Return obj.
- Let obj be ?
Assert : firstArgis not an Object .- Let elementLength be ?
ToIndex (firstArg). - Return ?
AllocateTypedArray (ctorName, NewTarget, proto, elementLength).
23.2.5.1.1 AllocateTypedArray ( ctorName, newTarget, defaultProto [ , length ] )
The abstract operation AllocateTypedArray takes arguments ctorName (a String which is the name of a
- Let proto be ?
GetPrototypeFromConstructor (newTarget, defaultProto). - Let obj be
TypedArrayCreate (proto). Assert : obj.[[ViewedArrayBuffer]] isundefined .- Set obj.[[TypedArrayName]] to ctorName.
- If ctorName is either
"BigInt64Array" or"BigUint64Array" , set obj.[[ContentType]] tobigint . - Else, set obj.[[ContentType]] to
number . - If length is not present, then
- Set obj.[[ByteLength]] to 0.
- Set obj.[[ByteOffset]] to 0.
- Set obj.[[ArrayLength]] to 0.
- Else,
- Perform ?
AllocateTypedArrayBuffer (obj, length).
- Perform ?
- Return obj.
23.2.5.1.2 InitializeTypedArrayFromTypedArray ( obj, sourceArray )
The abstract operation InitializeTypedArrayFromTypedArray takes arguments obj (a
- Let sourceData be sourceArray.[[ViewedArrayBuffer]].
- Let elementType be
TypedArrayElementType (obj). - Let elementSize be
TypedArrayElementSize (obj). - Let sourceType be
TypedArrayElementType (sourceArray). - Let sourceElementSize be
TypedArrayElementSize (sourceArray). - Let sourceByteOffset be sourceArray.[[ByteOffset]].
- Let sourceRecord be
MakeTypedArrayWithBufferWitnessRecord (sourceArray,seq-cst ). - If
IsTypedArrayOutOfBounds (sourceRecord) istrue , throw aTypeError exception. - Let elementLength be
TypedArrayLength (sourceRecord). - Let byteLength be elementSize × elementLength.
- If elementType is sourceType, then
- Let data be ?
CloneArrayBuffer (sourceData, sourceByteOffset, byteLength).
- Let data be ?
- Else,
- Let data be ?
.AllocateArrayBuffer (%ArrayBuffer% , byteLength) - If sourceArray.[[ContentType]] is not obj.[[ContentType]], throw a
TypeError exception. - Let sourceByteIndex be sourceByteOffset.
- Let targetByteIndex be 0.
- Let count be elementLength.
- Repeat, while count > 0,
- Let value be
GetValueFromBuffer (sourceData, sourceByteIndex, sourceType,true ,unordered ). - Perform
SetValueInBuffer (data, targetByteIndex, elementType, value,true ,unordered ). - Set sourceByteIndex to sourceByteIndex + sourceElementSize.
- Set targetByteIndex to targetByteIndex + elementSize.
- Set count to count - 1.
- Let value be
- Let data be ?
- Set obj.[[ViewedArrayBuffer]] to data.
- Set obj.[[ByteLength]] to byteLength.
- Set obj.[[ByteOffset]] to 0.
- Set obj.[[ArrayLength]] to elementLength.
- Return
unused .
23.2.5.1.3 InitializeTypedArrayFromArrayBuffer ( obj, buffer, byteOffset, length )
The abstract operation InitializeTypedArrayFromArrayBuffer takes arguments obj (a
- Let elementSize be
TypedArrayElementSize (obj). - Let offset be ?
ToIndex (byteOffset). - If offset
modulo elementSize ≠ 0, throw aRangeError exception. - Let bufferIsFixedLength be
IsFixedLengthArrayBuffer (buffer). - If length is not
undefined , then- Let newLength be ?
ToIndex (length).
- Let newLength be ?
- If
IsDetachedBuffer (buffer) istrue , throw aTypeError exception. - Let bufferByteLength be
ArrayBufferByteLength (buffer,seq-cst ). - If length is
undefined and bufferIsFixedLength isfalse , then- If offset > bufferByteLength, throw a
RangeError exception. - Set obj.[[ByteLength]] to
auto . - Set obj.[[ArrayLength]] to
auto .
- If offset > bufferByteLength, throw a
- Else,
- If length is
undefined , then- If bufferByteLength
modulo elementSize ≠ 0, throw aRangeError exception. - Let newByteLength be bufferByteLength - offset.
- If newByteLength < 0, throw a
RangeError exception.
- If bufferByteLength
- Else,
- Let newByteLength be newLength × elementSize.
- If offset + newByteLength > bufferByteLength, throw a
RangeError exception.
- Set obj.[[ByteLength]] to newByteLength.
- Set obj.[[ArrayLength]] to newByteLength / elementSize.
- If length is
- Set obj.[[ViewedArrayBuffer]] to buffer.
- Set obj.[[ByteOffset]] to offset.
- Return
unused .
23.2.5.1.4 InitializeTypedArrayFromList ( obj, values )
The abstract operation InitializeTypedArrayFromList takes arguments obj (a
- Let length be the number of elements in values.
- Perform ?
AllocateTypedArrayBuffer (obj, length). - Let k be 0.
- Repeat, while k < length,
Assert : values is now an emptyList .- Return
unused .
23.2.5.1.5 InitializeTypedArrayFromArrayLike ( obj, arrayLike )
The abstract operation InitializeTypedArrayFromArrayLike takes arguments obj (a
- Let length be ?
LengthOfArrayLike (arrayLike). - Perform ?
AllocateTypedArrayBuffer (obj, length). - Let k be 0.
- Repeat, while k < length,
- Return
unused .
23.2.5.1.6 AllocateTypedArrayBuffer ( obj, length )
The abstract operation AllocateTypedArrayBuffer takes arguments obj (a
Assert : obj.[[ViewedArrayBuffer]] isundefined .- Let elementSize be
TypedArrayElementSize (obj). - Let byteLength be elementSize × length.
- Let data be ?
.AllocateArrayBuffer (%ArrayBuffer% , byteLength) - Set obj.[[ViewedArrayBuffer]] to data.
- Set obj.[[ByteLength]] to byteLength.
- Set obj.[[ByteOffset]] to 0.
- Set obj.[[ArrayLength]] to length.
- Return
unused .
23.2.6 Properties of the TypedArray Constructors
Each TypedArray
- has a [[Prototype]] internal slot whose value is
%TypedArray% . - has a
"length" property whose value is3 𝔽. - has a
"name" property whose value is the String value of theconstructor name specified for it inTable 70 . - has the following properties:
23.2.6.1 TypedArray.BYTES_PER_ELEMENT
The value of TypedArray.BYTES_PER_ELEMENT is the Element Size value specified in
This property has the attributes { [[Writable]]:
23.2.6.2 TypedArray.prototype
The initial value of TypedArray.prototype is the corresponding TypedArray prototype intrinsic object (
This property has the attributes { [[Writable]]:
23.2.7 Properties of the TypedArray Prototype Objects
Each TypedArray prototype object:
- has a [[Prototype]] internal slot whose value 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.
23.2.7.1 TypedArray.prototype.BYTES_PER_ELEMENT
The value of TypedArray.prototype.BYTES_PER_ELEMENT is the Element Size value specified in
This property has the attributes { [[Writable]]:
23.2.7.2 TypedArray.prototype.constructor
The initial value of the
23.2.8 Properties of TypedArray Instances
TypedArray instances are
23.3 Uint8Array Objects
A Uint8Array is a particular kind of TypedArray as described above. In addition, there are additional methods on the Uint8Array
23.3.1 Additional Properties of the Uint8Array Constructor
23.3.1.1 Uint8Array.fromBase64 ( string [ , options ] )
- If string
is not a String , throw aTypeError exception. - Let opts be ?
GetOptionsObject (options). - Let alphabet be ?
Get (opts,"alphabet" ). - If alphabet is
undefined , set alphabet to"base64" . - If alphabet is neither
"base64" nor"base64url" , throw aTypeError exception. - Let lastChunkHandling be ?
Get (opts,"lastChunkHandling" ). - If lastChunkHandling is
undefined , set lastChunkHandling to"loose" . - If lastChunkHandling is not one of
"loose" ,"strict" , or"stop-before-partial" , throw aTypeError exception. - Let result be
FromBase64 (string, alphabet, lastChunkHandling). - If result.[[Error]] is not
none , then- Throw result.[[Error]].
- Let resultLength be the number of elements in result.[[Bytes]].
- Let ta be ?
.AllocateTypedArray ("Uint8Array" ,%Uint8Array% ," , resultLength)%Uint8Array.prototype% " Assert : ta.[[ViewedArrayBuffer]].[[ArrayBufferByteLength]] is the number of elements in result.[[Bytes]].- Set the value at each index of ta.[[ViewedArrayBuffer]].[[ArrayBufferData]] to the value at the corresponding index of result.[[Bytes]].
- Return ta.
23.3.1.2 Uint8Array.fromHex ( string )
- If string
is not a String , throw aTypeError exception. - Let result be
FromHex (string). - If result.[[Error]] is not
none , then- Throw result.[[Error]].
- Let resultLength be the number of elements in result.[[Bytes]].
- Let ta be ?
.AllocateTypedArray ("Uint8Array" ,%Uint8Array% ," , resultLength)%Uint8Array.prototype% " Assert : ta.[[ViewedArrayBuffer]].[[ArrayBufferByteLength]] is the number of elements in result.[[Bytes]].- Set the value at each index of ta.[[ViewedArrayBuffer]].[[ArrayBufferData]] to the value at the corresponding index of result.[[Bytes]].
- Return ta.
23.3.2 Additional Properties of the Uint8Array Prototype Object
23.3.2.1 Uint8Array.prototype.setFromBase64 ( string [ , options ] )
- Let into be the
this value. - Perform ?
ValidateUint8Array (into). - If string
is not a String , throw aTypeError exception. - Let opts be ?
GetOptionsObject (options). - Let alphabet be ?
Get (opts,"alphabet" ). - If alphabet is
undefined , set alphabet to"base64" . - If alphabet is neither
"base64" nor"base64url" , throw aTypeError exception. - Let lastChunkHandling be ?
Get (opts,"lastChunkHandling" ). - If lastChunkHandling is
undefined , set lastChunkHandling to"loose" . - If lastChunkHandling is not one of
"loose" ,"strict" , or"stop-before-partial" , throw aTypeError exception. - Let taRecord be
MakeTypedArrayWithBufferWitnessRecord (into,seq-cst ). - If
IsTypedArrayOutOfBounds (taRecord) istrue , throw aTypeError exception. - Let byteLength be
TypedArrayLength (taRecord). - Let result be
FromBase64 (string, alphabet, lastChunkHandling, byteLength). - Let bytes be result.[[Bytes]].
- Let written be the number of elements in bytes.
NOTE :FromBase64 does not invoke any user code, so the ArrayBuffer backing into cannot have been detached or shrunk.Assert : written ≤ byteLength.- Perform
SetUint8ArrayBytes (into, bytes). - If result.[[Error]] is not
none , then- Throw result.[[Error]].
- Let resultObj be
OrdinaryObjectCreate (%Object.prototype% ). - Perform !
CreateDataPropertyOrThrow (resultObj,"read" ,𝔽 (result.[[Read]])). - Perform !
CreateDataPropertyOrThrow (resultObj,"written" ,𝔽 (written)). - Return resultObj.
23.3.2.2 Uint8Array.prototype.setFromHex ( string )
- Let into be the
this value. - Perform ?
ValidateUint8Array (into). - If string
is not a String , throw aTypeError exception. - Let taRecord be
MakeTypedArrayWithBufferWitnessRecord (into,seq-cst ). - If
IsTypedArrayOutOfBounds (taRecord) istrue , throw aTypeError exception. - Let byteLength be
TypedArrayLength (taRecord). - Let result be
FromHex (string, byteLength). - Let bytes be result.[[Bytes]].
- Let written be the number of elements in bytes.
NOTE :FromHex does not invoke any user code, so the ArrayBuffer backing into cannot have been detached or shrunk.Assert : written ≤ byteLength.- Perform
SetUint8ArrayBytes (into, bytes). - If result.[[Error]] is not
none , then- Throw result.[[Error]].
- Let resultObj be
OrdinaryObjectCreate (%Object.prototype% ). - Perform !
CreateDataPropertyOrThrow (resultObj,"read" ,𝔽 (result.[[Read]])). - Perform !
CreateDataPropertyOrThrow (resultObj,"written" ,𝔽 (written)). - Return resultObj.
23.3.2.3 Uint8Array.prototype.toBase64 ( [ options ] )
- Let obj be the
this value. - Perform ?
ValidateUint8Array (obj). - Let opts be ?
GetOptionsObject (options). - Let alphabet be ?
Get (opts,"alphabet" ). - If alphabet is
undefined , set alphabet to"base64" . - If alphabet is neither
"base64" nor"base64url" , throw aTypeError exception. - Let omitPadding be
ToBoolean (?Get (opts,"omitPadding" )). - Let toEncode be ?
GetUint8ArrayBytes (obj). - If alphabet is
"base64" , then- Let outAscii be the sequence of code points which results from encoding toEncode according to the base64 encoding specified in section 4 of RFC 4648. Padding is included if and only if omitPadding is
false .
- Let outAscii be the sequence of code points which results from encoding toEncode according to the base64 encoding specified in section 4 of RFC 4648. Padding is included if and only if omitPadding is
- Else,
- Return
CodePointsToString (outAscii).
23.3.2.4 Uint8Array.prototype.toHex ( )
- Let obj be the
this value. - Perform ?
ValidateUint8Array (obj). - Let toEncode be ?
GetUint8ArrayBytes (obj). - Let out be the empty String.
- For each byte byte of toEncode, do
- Let hex be
Number::toString (𝔽 (byte), 16). - Set hex to
StringPad (hex, 2,"0" ,start ). - Set out to the
string-concatenation of out and hex.
- Let hex be
- Return out.
23.3.3 Abstract Operations for Uint8Array Objects
23.3.3.1 ValidateUint8Array ( ta )
The abstract operation ValidateUint8Array takes argument ta (an
- Perform ?
RequireInternalSlot (ta, [[TypedArrayName]]). - If ta.[[TypedArrayName]] is not
"Uint8Array" , throw aTypeError exception. - Return
unused .
23.3.3.2 GetUint8ArrayBytes ( ta )
The abstract operation GetUint8ArrayBytes takes argument ta (a Uint8Array) and returns either a
- Let buffer be ta.[[ViewedArrayBuffer]].
- Let taRecord be
MakeTypedArrayWithBufferWitnessRecord (ta,seq-cst ). - If
IsTypedArrayOutOfBounds (taRecord) istrue , throw aTypeError exception. - Let length be
TypedArrayLength (taRecord). - Let byteOffset be ta.[[ByteOffset]].
- Let bytes be a new empty
List . - Let index be 0.
- Repeat, while index < length,
- Let byteIndex be byteOffset + index.
- Let byte be
ℝ (GetValueFromBuffer (buffer, byteIndex,uint8 ,true ,unordered )). - Append byte to bytes.
- Set index to index + 1.
- Return bytes.
23.3.3.3 SetUint8ArrayBytes ( into, bytes )
The abstract operation SetUint8ArrayBytes takes arguments into (a Uint8Array) and bytes (a
- Let offset be into.[[ByteOffset]].
- Let length be the number of elements in bytes.
- Let index be 0.
- Repeat, while index < length,
- Let byte be bytes[index].
- Let byteIndexInBuffer be index + offset.
- Perform
SetValueInBuffer (into.[[ViewedArrayBuffer]], byteIndexInBuffer,uint8 ,𝔽 (byte),true ,unordered ). - Set index to index + 1.
- Return
unused .
23.3.3.4 SkipAsciiWhitespace ( string, index )
The abstract operation SkipAsciiWhitespace takes arguments string (a String) and index (a non-negative
- Let length be the length of string.
- Repeat, while index < length,
- Let char be the code unit at index index within string.
- If char is not one of 0x0009 (TAB), 0x000A (LF), 0x000C (FF), 0x000D (CR), or 0x0020 (SPACE), then
- Return index.
- Set index to index + 1.
- Return index.
23.3.3.5 DecodeFinalBase64Chunk ( chunk, throwOnExtraBits )
The abstract operation DecodeFinalBase64Chunk takes arguments chunk (a String of length 2 or 3) and throwOnExtraBits (a Boolean) and returns either a
- Let chunkLength be the length of chunk.
- If chunkLength = 2, then
- Set chunk to the
string-concatenation of chunk and"AA" .
- Set chunk to the
- Else,
Assert : chunkLength is 3.- Set chunk to the
string-concatenation of chunk and"A" .
- Let bytes be
DecodeFullLengthBase64Chunk (chunk). - If chunkLength = 2, then
- If throwOnExtraBits is
true and bytes[1] ≠ 0, throw aSyntaxError exception. - Return « bytes[0] ».
- If throwOnExtraBits is
- If throwOnExtraBits is
true and bytes[2] ≠ 0, throw aSyntaxError exception. - Return « bytes[0], bytes[1] ».
23.3.3.6 DecodeFullLengthBase64Chunk ( chunk )
The abstract operation DecodeFullLengthBase64Chunk takes argument chunk (a String of length 4) and returns a
The standard base64 alphabet is
23.3.3.7 FromBase64 ( string, alphabet, lastChunkHandling [ , maxLength ] )
The abstract operation FromBase64 takes arguments string (a String), alphabet (
- If maxLength is not present, then
- Set maxLength to 253 - 1.
NOTE : Because the inputis a String , the length of Strings is limited to 253 - 1 characters, and the output requires no more bytes than the input has characters, this limit can never be reached. However, it is editorially convenient to use afinite value for maxLength.
NOTE : The order of validation and decoding in the algorithm below is not observable. Implementations are encouraged to perform them in whatever order is most efficient, possibly interleaving validation with decoding.- If maxLength = 0, then
- Return the
Record { [[Read]]: 0, [[Bytes]]: « », [[Error]]:none }.
- Return the
- Let read be 0.
- Let bytes be a new empty
List . - Let chunk be the empty String.
- Let chunkLength be 0.
- Let index be 0.
- Let length be the length of string.
- Repeat,
Assert : The number of elements in bytes is evenly divisible by 3.- Set index to
SkipAsciiWhitespace (string, index). - If index = length, then
- If chunkLength > 0, then
- If lastChunkHandling is
"stop-before-partial" , then- Return the
Record { [[Read]]: read, [[Bytes]]: bytes, [[Error]]:none }.
- Return the
- If lastChunkHandling is
"strict" , then- Let error be a newly created
SyntaxError object. - Return the
Record { [[Read]]: read, [[Bytes]]: bytes, [[Error]]: error }.
- Let error be a newly created
Assert : lastChunkHandling is"loose" .- If chunkLength = 1, then
- Let error be a newly created
SyntaxError object. - Return the
Record { [[Read]]: read, [[Bytes]]: bytes, [[Error]]: error }.
- Let error be a newly created
- Set bytes to the
list-concatenation of bytes and !DecodeFinalBase64Chunk (chunk,false ).
- If lastChunkHandling is
- Return the
Record { [[Read]]: length, [[Bytes]]: bytes, [[Error]]:none }.
- If chunkLength > 0, then
- Let char be the
substring of string from index to index + 1. - Set index to index + 1.
- If char is
"=" , then- If chunkLength < 2, then
- Let error be a newly created
SyntaxError object. - Return the
Record { [[Read]]: read, [[Bytes]]: bytes, [[Error]]: error }.
- Let error be a newly created
- Set index to
SkipAsciiWhitespace (string, index). - If chunkLength = 2, then
- If index = length, then
- Set char to the
substring of string from index to index + 1. - If char is
"=" , then- Set index to
SkipAsciiWhitespace (string, index + 1).
- Set index to
- If index < length, then
- Let error be a newly created
SyntaxError object. - Return the
Record { [[Read]]: read, [[Bytes]]: bytes, [[Error]]: error }.
- Let error be a newly created
- If lastChunkHandling is
"strict" , let throwOnExtraBits betrue ; else let throwOnExtraBits befalse . - Let decodeResult be
Completion (DecodeFinalBase64Chunk (chunk, throwOnExtraBits)). - If decodeResult is an
abrupt completion , then- Let error be decodeResult.[[Value]].
- Return the
Record { [[Read]]: read, [[Bytes]]: bytes, [[Error]]: error }.
- Set bytes to the
list-concatenation of bytes and ! decodeResult. - Return the
Record { [[Read]]: length, [[Bytes]]: bytes, [[Error]]:none }.
- If chunkLength < 2, then
- If alphabet is
"base64url" , then- If char is either
"+" or"/" , then- Let error be a newly created
SyntaxError object. - Return the
Record { [[Read]]: read, [[Bytes]]: bytes, [[Error]]: error }.
- Let error be a newly created
- Else if char is
"-" , then- Set char to
"+" .
- Set char to
- Else if char is
"_" , then- Set char to
"/" .
- Set char to
- If char is either
- If the sole code unit of char is not an element of the
standard base64 alphabet , then- Let error be a newly created
SyntaxError object. - Return the
Record { [[Read]]: read, [[Bytes]]: bytes, [[Error]]: error }.
- Let error be a newly created
- Let remaining be maxLength - the number of elements in bytes.
- If remaining = 1 and chunkLength = 2, or if remaining = 2 and chunkLength = 3, then
- Return the
Record { [[Read]]: read, [[Bytes]]: bytes, [[Error]]:none }.
- Return the
- Set chunk to the
string-concatenation of chunk and char. - Set chunkLength to the length of chunk.
- If chunkLength = 4, then
- Set bytes to the
list-concatenation of bytes andDecodeFullLengthBase64Chunk (chunk). - Set chunk to the empty String.
- Set chunkLength to 0.
- Set read to index.
- If the number of elements in bytes = maxLength, then
- Return the
Record { [[Read]]: read, [[Bytes]]: bytes, [[Error]]:none }.
- Return the
- Set bytes to the
23.3.3.8 FromHex ( string [ , maxLength ] )
The abstract operation FromHex takes argument string (a String) and optional argument maxLength (a non-negative
- If maxLength is not present, set maxLength to 253 - 1.
- Let length be the length of string.
- Let bytes be a new empty
List . - Let read be 0.
- If length
modulo 2 ≠ 0, then- Let error be a newly created
SyntaxError object. - Return the
Record { [[Read]]: read, [[Bytes]]: bytes, [[Error]]: error }.
- Let error be a newly created
- Repeat, while read < length and the number of elements in bytes < maxLength,
- Let hexits be the
substring of string from read to read + 2. - If hexits contains any code units which are not in
"0123456789abcdefABCDEF" , then- Let error be a newly created
SyntaxError object. - Return the
Record { [[Read]]: read, [[Bytes]]: bytes, [[Error]]: error }.
- Let error be a newly created
- Set read to read + 2.
- Let byte be the
integer value represented by hexits in base-16 notation, using the lettersA throughF anda throughf for digits with values 10 through 15. - Append byte to bytes.
- Let hexits be the
- Return the
Record { [[Read]]: read, [[Bytes]]: bytes, [[Error]]:none }.