23.2.3 %TypedArray% 原型对象的属性
%TypedArray% 原型对象:
- 具有 [[Prototype]] 内部槽,其值是 %Object.prototype%。
- 是 %TypedArray.prototype%。
- 是普通对象。
- 不具有 [[ViewedArrayBuffer]],也不具有任何其他 TypedArray 实例对象特有的内部槽。
23.2.3.1 %TypedArray%.prototype.at ( index )
- 令 obj 为 this value。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 length 为 TypedArrayLength(taRecord)。
- 令 k 为 ? ToAbsoluteIndex(index, length)。
- 如果 k < 0 或 k ≥ length,则返回 undefined。
- 返回 TypedArrayGetElement(obj, 𝔽(k))。
23.2.3.2 get %TypedArray%.prototype.buffer
%TypedArray%.prototype.buffer 是访问器属性,其 set 访问器函数为 undefined。其 get 访问器函数在调用时执行以下步骤:
- 令 obj 为 this value。
- 执行 ? RequireInternalSlot(obj, [[TypedArrayName]])。
- 断言:obj 具有 [[ViewedArrayBuffer]] 内部槽。
- 令 buffer 为 obj.[[ViewedArrayBuffer]]。
- 返回 buffer。
23.2.3.3 get %TypedArray%.prototype.byteLength
%TypedArray%.prototype.byteLength 是访问器属性,其 set 访问器函数为 undefined。其 get 访问器函数在调用时执行以下步骤:
- 令 obj 为 this value。
- 执行 ? RequireInternalSlot(obj, [[TypedArrayName]])。
- 断言:obj 具有 [[ViewedArrayBuffer]] 内部槽。
- 令 taRecord 为 MakeTypedArrayWithBufferWitnessRecord(obj, seq-cst)。
- 如果 IsTypedArrayOutOfBounds(taRecord) 是 true,则返回 +0𝔽。
- 令 size 为 TypedArrayByteLength(taRecord)。
- 返回 𝔽(size)。
23.2.3.4 get %TypedArray%.prototype.byteOffset
%TypedArray%.prototype.byteOffset 是访问器属性,其 set 访问器函数为 undefined。其 get 访问器函数在调用时执行以下步骤:
- 令 obj 为 this value。
- 执行 ? RequireInternalSlot(obj, [[TypedArrayName]])。
- 断言:obj 具有 [[ViewedArrayBuffer]] 内部槽。
- 令 taRecord 为 MakeTypedArrayWithBufferWitnessRecord(obj, seq-cst)。
- 如果 IsTypedArrayOutOfBounds(taRecord) 是 true,则返回 +0𝔽。
- 令 offset 为 obj.[[ByteOffset]]。
- 返回 𝔽(offset)。
23.2.3.5 %TypedArray%.prototype.constructor
%TypedArray%.prototype.constructor 的初始值是 %TypedArray%。
23.2.3.6 %TypedArray%.prototype.copyWithin ( target, start [ , end ] )
此方法参数的解释和使用方式与 23.1.3.4 中定义的 Array.prototype.copyWithin 相同。
调用时,此方法执行以下步骤:
- 令 obj 为 this value。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 length 为 TypedArrayLength(taRecord)。
- 令 targetIndex 为 ? ToClampedIndex(target, length)。
- 令 startIndex 为 ? ToClampedIndex(start, length)。
- 如果 end 是 undefined,则令 endIndex 为 length;否则令 endIndex 为 ? ToClampedIndex(end, length)。
- 令 count 为 min(endIndex - startIndex, length - targetIndex)。
- 如果 count > 0,则
- 注:复制必须以保留源数据位级编码的方式执行。
- 令 buffer 为 obj.[[ViewedArrayBuffer]]。
- 将 taRecord 设置为 ? ValidateTypedArrayBounds(obj, seq-cst)。
- 将 length 设置为 TypedArrayLength(taRecord)。
- 注:上述步骤的副作用可能已经减小了 obj 的大小,在这种情况下,应使用仍然适用的最长前缀继续复制。
- 将 count 设置为 min(count, length - startIndex, length - targetIndex)。
- 令 elementSize 为 TypedArrayElementSize(obj)。
- 令 byteOffset 为 obj.[[ByteOffset]]。
- 令 toByteIndex 为 (targetIndex × elementSize) + byteOffset。
- 令 fromByteIndex 为 (startIndex × elementSize) + byteOffset。
- 令 countBytes 为 count × elementSize。
- 如果 fromByteIndex < toByteIndex 且 toByteIndex < fromByteIndex + countBytes,则
- 令 direction 为 -1。
- 将 fromByteIndex 设置为 fromByteIndex + countBytes - 1。
- 将 toByteIndex 设置为 toByteIndex + countBytes - 1。
- 否则,
- 令 direction 为 1。
- 当 countBytes > 0 时,重复执行,
- 断言:fromByteIndex ≥ 0 且 toByteIndex ≥ 0。
- 令 value 为 GetValueFromBuffer(buffer, fromByteIndex, uint8, true, unordered)。
- 执行 SetValueInBuffer(buffer, toByteIndex, uint8, value, true, unordered)。
- 将 fromByteIndex 设置为 fromByteIndex + direction。
- 将 toByteIndex 设置为 toByteIndex + direction。
- 将 countBytes 设置为 countBytes - 1。
- 返回 obj。
23.2.3.7 %TypedArray%.prototype.entries ( )
调用时,此方法执行以下步骤:
- 令 obj 为 this value。
- 执行 ? ValidateTypedArray(obj, seq-cst)。
- 返回 CreateArrayIterator(obj, key+value)。
23.2.3.8 %TypedArray%.prototype.every ( callback [ , thisArg ] )
此方法参数的解释和使用方式与 23.1.3.6 中定义的 Array.prototype.every 相同。
调用时,此方法执行以下步骤:
- 令 obj 为 this value。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 length 为 TypedArrayLength(taRecord)。
- 如果 IsCallable(callback) 是 false,则抛出 TypeError 异常。
- 令 k 为 0。
- 当 k < length 时,重复执行,
- 令 kValue 为 TypedArrayGetElement(obj, 𝔽(k))。
- 令 testResult 为 ToBoolean(? Call(callback, thisArg, « kValue, 𝔽(k), obj »))。
- 如果 testResult 是 false,则返回 false。
- 将 k 设置为 k + 1。
- 返回 true。
此方法不是通用方法。this value 必须是具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.9 %TypedArray%.prototype.fill ( value [ , start [ , end ] ] )
此方法参数的解释和使用方式与 23.1.3.7 中定义的 Array.prototype.fill 相同。
调用时,此方法执行以下步骤:
- 令 obj 为 this value。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 length 为 TypedArrayLength(taRecord)。
- 如果 obj.[[ContentType]] 是 bigint,则将 value 设置为 ? ToBigInt(value)。
- 否则,将 value 设置为 ? ToNumber(value)。
- 令 startIndex 为 ? ToClampedIndex(start, length)。
- 如果 end 是 undefined,则令 endIndex 为 length;否则令 endIndex 为 ? ToClampedIndex(end, length)。
- 将 taRecord 设置为 ? ValidateTypedArrayBounds(obj, seq-cst)。
- 将 length 设置为 TypedArrayLength(taRecord)。
- 将 endIndex 设置为 min(endIndex, length)。
- 令 k 为 startIndex。
- 当 k < endIndex 时,重复执行,
- 执行 ! TypedArraySetElement(obj, 𝔽(k), value)。
- 将 k 设置为 k + 1。
- 返回 obj。
23.2.3.10 %TypedArray%.prototype.filter ( callback [ , thisArg ] )
此方法参数的解释和使用方式与 23.1.3.8 中定义的 Array.prototype.filter 相同。
调用时,此方法执行以下步骤:
- 令 obj 为 this value。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 length 为 TypedArrayLength(taRecord)。
- 如果 IsCallable(callback) 是 false,则抛出 TypeError 异常。
- 令 kept 为新的空 List。
- 令 captured 为 0。
- 令 k 为 0。
- 当 k < length 时,重复执行,
- 令 kValue 为 TypedArrayGetElement(obj, 𝔽(k))。
- 令 selected 为 ToBoolean(? Call(callback, thisArg, « kValue, 𝔽(k), obj »))。
- 如果 selected 是 true,则
- 将 kValue 追加到 kept。
- 将 captured 设置为 captured + 1。
- 将 k 设置为 k + 1。
- 令 result 为 ? TypedArraySpeciesCreate(obj, « 𝔽(captured) »)。
- 令 n 为 0。
- 对 kept 的每个元素 element,执行
- 执行 ! TypedArraySetElement(result, 𝔽(n), element)。
- 将 n 设置为 n + 1。
- 返回 result。
此方法不是通用方法。this value 必须是具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.11 %TypedArray%.prototype.find ( predicate [ , thisArg ] )
此方法参数的解释和使用方式与 23.1.3.9 中定义的 Array.prototype.find 相同。
调用时,此方法执行以下步骤:
- 令 obj 为 this value。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 length 为 TypedArrayLength(taRecord)。
- 令 findRecord 为 ? FindViaPredicate(obj, length, ascending, predicate, thisArg)。
- 返回 findRecord.[[Value]]。
此方法不是通用方法。this value 必须是具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.12 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] )
此方法参数的解释和使用方式与 23.1.3.10 中定义的 Array.prototype.findIndex 相同。
调用时,此方法执行以下步骤:
- 令 obj 为 this value。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 length 为 TypedArrayLength(taRecord)。
- 令 findRecord 为 ? FindViaPredicate(obj, length, ascending, predicate, thisArg)。
- 返回 findRecord.[[Index]]。
此方法不是通用方法。this value 必须是具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.13 %TypedArray%.prototype.findLast ( predicate [ , thisArg ] )
此方法参数的解释和使用方式与 23.1.3.11 中定义的 Array.prototype.findLast 相同。
调用时,此方法执行以下步骤:
- 令 obj 为 this value。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 length 为 TypedArrayLength(taRecord)。
- 令 findRecord 为 ? FindViaPredicate(obj, length, descending, predicate, thisArg)。
- 返回 findRecord.[[Value]]。
此方法不是通用方法。this value 必须是具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.14 %TypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] )
此方法参数的解释和使用方式与 23.1.3.12 中定义的 Array.prototype.findLastIndex 相同。
调用时,此方法执行以下步骤:
- 令 obj 为 this value。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 length 为 TypedArrayLength(taRecord)。
- 令 findRecord 为 ? FindViaPredicate(obj, length, descending, predicate, thisArg)。
- 返回 findRecord.[[Index]]。
此方法不是通用方法。this value 必须是具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.15 %TypedArray%.prototype.forEach ( callback [ , thisArg ] )
此方法参数的解释和使用方式与 23.1.3.15 中定义的 Array.prototype.forEach 相同。
调用时,此方法执行以下步骤:
- 令 obj 为 this value。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 length 为 TypedArrayLength(taRecord)。
- 如果 IsCallable(callback) 是 false,则抛出 TypeError 异常。
- 令 k 为 0。
- 当 k < length 时,重复执行,
- 令 kValue 为 TypedArrayGetElement(obj, 𝔽(k))。
- 执行 ? Call(callback, thisArg, « kValue, 𝔽(k), obj »)。
- 将 k 设置为 k + 1。
- 返回 undefined。
此方法不是通用方法。this value 必须是具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.16 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] )
此方法参数的解释和使用方式与 23.1.3.16 中定义的 Array.prototype.includes 相同。
调用时,此方法执行以下步骤:
- 令 obj 为 this value。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 length 为 TypedArrayLength(taRecord)。
- 如果 length = 0,则返回 false。
- 令 k 为 ? ToClampedIndex(fromIndex, length)。
- 当 k < length 时,重复执行,
- 令 elementK 为 TypedArrayGetElement(obj, 𝔽(k))。
- 如果 SameValueZero(searchElement, elementK) 是 true,则返回 true。
- 将 k 设置为 k + 1。
- 返回 false。
此方法不是通用方法。this value 必须是具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.17 %TypedArray%.prototype.indexOf ( searchElement [ , fromIndex ] )
此方法参数的解释和使用方式与 23.1.3.17 中定义的 Array.prototype.indexOf 相同。
调用时,此方法执行以下步骤:
- 令 obj 为 this value。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 length 为 TypedArrayLength(taRecord)。
- 如果 length = 0,则返回 -1𝔽。
- 令 k 为 ? ToClampedIndex(fromIndex, length)。
- 当 k < length 时,重复执行,
- 令 propertyKey 为 ! ToString(𝔽(k))。
- 令 kPresent 为 ! HasProperty(obj, propertyKey)。
- 如果 kPresent 是 true,则
- 令 elementK 为 TypedArrayGetElement(obj, 𝔽(k))。
- 如果 IsStrictlyEqual(searchElement, elementK) 是 true,则返回 𝔽(k)。
- 将 k 设置为 k + 1。
- 返回 -1𝔽。
此方法不是通用方法。this value 必须是具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.18 %TypedArray%.prototype.join ( separator )
此方法参数的解释和使用方式与 23.1.3.18 中定义的 Array.prototype.join 相同。
调用时,此方法执行以下步骤:
- 令 obj 为 this value。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 length 为 TypedArrayLength(taRecord)。
- 如果 separator 是 undefined,则令 separatorString 为 ","。
- 否则,令 separatorString 为 ? ToString(separator)。
- 令 result 为空 String。
- 令 k 为 0。
- 当 k < length 时,重复执行,
- 如果 k > 0,则将 result 设置为 result 和 separatorString 的字符串连接。
- 令 element 为 TypedArrayGetElement(obj, 𝔽(k))。
- 如果 element 不是 undefined,则
- 令 elementString 为 ! ToString(element)。
- 将 result 设置为 result 和 elementString 的字符串连接。
- 将 k 设置为 k + 1。
- 返回 result。
此方法不是通用方法。this value 必须是具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.19 %TypedArray%.prototype.keys ( )
调用时,此方法执行以下步骤:
- 令 obj 为 this value。
- 执行 ? ValidateTypedArray(obj, seq-cst)。
- 返回 CreateArrayIterator(obj, key)。
23.2.3.20 %TypedArray%.prototype.lastIndexOf ( searchElement [ , fromIndex ] )
此方法参数的解释和使用方式与 23.1.3.20 中定义的 Array.prototype.lastIndexOf 相同。
调用时,此方法执行以下步骤:
- 令 obj 为 this value。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 length 为 TypedArrayLength(taRecord)。
- 如果 length = 0,则返回 -1𝔽。
- 如果不存在 fromIndex,则令 k 为 length - 1;否则令 k 为 min(? ToAbsoluteIndex(fromIndex, length), length - 1)。
- 当 k ≥ 0 时,重复执行,
- 令 propertyKey 为 ! ToString(𝔽(k))。
- 令 kPresent 为 ! HasProperty(obj, propertyKey)。
- 如果 kPresent 是 true,则
- 令 elementK 为 TypedArrayGetElement(obj, 𝔽(k))。
- 如果 IsStrictlyEqual(searchElement, elementK) 是 true,则返回 𝔽(k)。
- 将 k 设置为 k - 1。
- 返回 -1𝔽。
此方法不是通用方法。this value 必须是具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.21 get %TypedArray%.prototype.length
%TypedArray%.prototype.length 是访问器属性,其 set 访问器函数为 undefined。其 get 访问器函数在调用时执行以下步骤:
- 令 obj 为 this value。
- 执行 ? RequireInternalSlot(obj, [[TypedArrayName]])。
- 断言:obj 具有 [[ViewedArrayBuffer]] 和 [[ArrayLength]] 内部槽。
- 令 taRecord 为 MakeTypedArrayWithBufferWitnessRecord(obj, seq-cst)。
- 如果 IsTypedArrayOutOfBounds(taRecord) 是 true,则返回 +0𝔽。
- 令 length 为 TypedArrayLength(taRecord)。
- 返回 𝔽(length)。
此函数不是通用函数。this value 必须是具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.22 %TypedArray%.prototype.map ( callback [ , thisArg ] )
此方法参数的解释和使用方式与 23.1.3.21 中定义的 Array.prototype.map 相同。
调用时,此方法执行以下步骤:
- 令 obj 为 this value。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 length 为 TypedArrayLength(taRecord)。
- 如果 IsCallable(callback) 是 false,则抛出 TypeError 异常。
- 令 result 为 ? TypedArraySpeciesCreate(obj, « 𝔽(length) »)。
- 令 k 为 0。
- 当 k < length 时,重复执行,
- 令 kValue 为 TypedArrayGetElement(obj, 𝔽(k))。
- 令 mappedValue 为 ? Call(callback, thisArg, « kValue, 𝔽(k), obj »)。
- 执行 ? TypedArraySetElement(result, 𝔽(k), mappedValue)。
- 将 k 设置为 k + 1。
- 返回 result。
此方法不是通用方法。this value 必须是具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.23 %TypedArray%.prototype.reduce ( callback [ , initialValue ] )
此方法参数的解释和使用方式与 23.1.3.24 中定义的 Array.prototype.reduce 相同。
调用时,此方法执行以下步骤:
- 令 obj 为 this value。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 length 为 TypedArrayLength(taRecord)。
- 如果 IsCallable(callback) 是 false,则抛出 TypeError 异常。
- 如果 length = 0 且不存在 initialValue,则抛出 TypeError 异常。
- 令 k 为 0。
- 令 accumulator 为 undefined。
- 如果存在 initialValue,则
- 将 accumulator 设置为 initialValue。
- 否则,
- 将 accumulator 设置为 TypedArrayGetElement(obj, 𝔽(k))。
- 将 k 设置为 k + 1。
- 当 k < length 时,重复执行,
- 令 kValue 为 TypedArrayGetElement(obj, 𝔽(k))。
- 将 accumulator 设置为 ? Call(callback, undefined, « accumulator, kValue, 𝔽(k), obj »)。
- 将 k 设置为 k + 1。
- 返回 accumulator。
此方法不是通用方法。this value 必须是具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.24 %TypedArray%.prototype.reduceRight ( callback [ , initialValue ] )
此方法参数的解释和使用方式与 23.1.3.25 中定义的 Array.prototype.reduceRight 相同。
调用时,此方法执行以下步骤:
- 令 obj 为 this value。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 length 为 TypedArrayLength(taRecord)。
- 如果 IsCallable(callback) 是 false,则抛出 TypeError 异常。
- 如果 length = 0 且不存在 initialValue,则抛出 TypeError 异常。
- 令 k 为 length - 1。
- 令 accumulator 为 undefined。
- 如果存在 initialValue,则
- 将 accumulator 设置为 initialValue。
- 否则,
- 将 accumulator 设置为 TypedArrayGetElement(obj, 𝔽(k))。
- 将 k 设置为 k - 1。
- 当 k ≥ 0 时,重复执行,
- 令 kValue 为 TypedArrayGetElement(obj, 𝔽(k))。
- 将 accumulator 设置为 ? Call(callback, undefined, « accumulator, kValue, 𝔽(k), obj »)。
- 将 k 设置为 k - 1。
- 返回 accumulator。
此方法不是通用方法。this value 必须是具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.25 %TypedArray%.prototype.reverse ( )
此方法参数的解释和使用方式与 23.1.3.26 中定义的 Array.prototype.reverse 相同。
调用时,此方法执行以下步骤:
- 令 obj 为 this value。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 length 为 TypedArrayLength(taRecord)。
- 令 middle 为 floor(length / 2)。
- 令 lower 为 0。
- 当 lower ≠ middle 时,重复执行,
- 令 upper 为 length - lower - 1。
- 令 lowerValue 为 TypedArrayGetElement(obj, 𝔽(lower))。
- 令 upperValue 为 TypedArrayGetElement(obj, 𝔽(upper))。
- 执行 ! TypedArraySetElement(obj, 𝔽(lower), upperValue)。
- 执行 ! TypedArraySetElement(obj, 𝔽(upper), lowerValue)。
- 将 lower 设置为 lower + 1。
- 返回 obj。
此方法不是通用方法。this value 必须是具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.26 %TypedArray%.prototype.set ( source [ , offset ] )
此方法从 source 读取值,并在此 TypedArray 中设置多个值。具体细节取决于 source 的类型。可选的 offset 值表示此 TypedArray 中写入值的第一个元素索引。如果省略,则假定为 0。
调用时,它执行以下步骤:
- 令 target 为 this value。
- 执行 ? RequireInternalSlot(target, [[TypedArrayName]])。
- 断言:target 具有 [[ViewedArrayBuffer]] 内部槽。
- 令 targetOffset 为 ? ToIntegerOrInfinity(offset)。
- 如果 targetOffset < 0,则抛出 RangeError 异常。
- 如果 source 是具有 [[TypedArrayName]] 内部槽的 Object,则
- 执行 ? SetTypedArrayFromTypedArray(target, targetOffset, source)。
- 否则,
- 执行 ? SetTypedArrayFromArrayLike(target, targetOffset, source)。
- 返回 undefined。
此方法不是通用方法。this value 必须是具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.26.1 SetTypedArrayFromArrayLike ( target, targetOffset, source )
抽象操作 SetTypedArrayFromArrayLike,接收参数 target (TypedArray)、targetOffset ((非负整数 或 +∞)) 和 source (an ECMAScript language value, but not a TypedArray);返回值:(正常完成 (值:unused) 或 抛出完成)。 它从 source 读取值,从索引 targetOffset 开始在 target 中设置多个值。 调用时执行以下步骤:
- 令 targetRecord 为 ? ValidateTypedArrayBounds(target, seq-cst)。
- 令 targetLength 为 TypedArrayLength(targetRecord)。
- 将 source 设置为 ? ToObject(source)。
- 令 sourceLength 为 ? LengthOfArrayLike(source)。
- 如果 targetOffset = +∞,则抛出 RangeError 异常。
- 如果 sourceLength + targetOffset > targetLength,则抛出 RangeError 异常。
- 令 k 为 0。
- 当 k < sourceLength 时,重复执行,
- 令 propertyKey 为 ! ToString(𝔽(k))。
- 令 value 为 ? Get(source, propertyKey)。
- 令 targetIndex 为 𝔽(targetOffset + k)。
- 执行 ? TypedArraySetElement(target, targetIndex, value)。
- 将 k 设置为 k + 1。
- 返回 unused。
23.2.3.26.2 SetTypedArrayFromTypedArray ( target, targetOffset, source )
抽象操作 SetTypedArrayFromTypedArray,接收参数 target (TypedArray)、targetOffset ((非负整数 或 +∞)) 和 source (TypedArray);返回值:(正常完成 (值:unused) 或 抛出完成)。 它从 source 读取值,从索引 targetOffset 开始在 target 中设置多个值。 调用时执行以下步骤:
- 令 targetBuffer 为 target.[[ViewedArrayBuffer]]。
- 令 targetRecord 为 ? ValidateTypedArrayBounds(target, seq-cst)。
- 令 targetLength 为 TypedArrayLength(targetRecord)。
- 令 sourceBuffer 为 source.[[ViewedArrayBuffer]]。
- 令 sourceRecord 为 ? ValidateTypedArrayBounds(source, seq-cst)。
- 令 sourceLength 为 TypedArrayLength(sourceRecord)。
- 令 targetType 为 TypedArrayElementType(target)。
- 令 targetElementSize 为 TypedArrayElementSize(target)。
- 令 targetByteOffset 为 target.[[ByteOffset]]。
- 令 sourceType 为 TypedArrayElementType(source)。
- 令 sourceElementSize 为 TypedArrayElementSize(source)。
- 令 sourceByteOffset 为 source.[[ByteOffset]]。
- 如果 targetOffset = +∞,则抛出 RangeError 异常。
- 如果 sourceLength + targetOffset > targetLength,则抛出 RangeError 异常。
- 如果 target.[[ContentType]] 不是 source.[[ContentType]],则抛出 TypeError 异常。
- 如果 IsSharedArrayBuffer(sourceBuffer) 是 true、IsSharedArrayBuffer(targetBuffer) 是 true,并且 sourceBuffer.[[ArrayBufferData]] 是 targetBuffer.[[ArrayBufferData]],则令 sameSharedArrayBuffer 为 true;否则令 sameSharedArrayBuffer 为 false。
- 如果 SameValue(sourceBuffer, targetBuffer) 是 true 或 sameSharedArrayBuffer 是 true,则
- 令 sourceByteLength 为 TypedArrayByteLength(sourceRecord)。
- 将 sourceBuffer 设置为 ? CloneArrayBuffer(sourceBuffer, sourceByteOffset, sourceByteLength)。
- 令 sourceByteIndex 为 0。
- 否则,
- 令 sourceByteIndex 为 sourceByteOffset。
- 令 targetByteIndex 为 (targetOffset × targetElementSize) + targetByteOffset。
- 令 limit 为 targetByteIndex + (targetElementSize × sourceLength)。
- 如果 sourceType 是 targetType,则
- 注:传输必须以保留源数据位级编码的方式执行。
- 当 targetByteIndex < limit 时,重复执行,
- 令 value 为 GetValueFromBuffer(sourceBuffer, sourceByteIndex, uint8, true, unordered)。
- 执行 SetValueInBuffer(targetBuffer, targetByteIndex, uint8, value, true, unordered)。
- 将 sourceByteIndex 设置为 sourceByteIndex + 1。
- 将 targetByteIndex 设置为 targetByteIndex + 1。
- 否则,
- 当 targetByteIndex < limit 时,重复执行,
- 令 value 为 GetValueFromBuffer(sourceBuffer, sourceByteIndex, sourceType, true, unordered)。
- 执行 SetValueInBuffer(targetBuffer, targetByteIndex, targetType, value, true, unordered)。
- 将 sourceByteIndex 设置为 sourceByteIndex + sourceElementSize。
- 将 targetByteIndex 设置为 targetByteIndex + targetElementSize。
- 返回 unused。
23.2.3.27 %TypedArray%.prototype.slice ( start, end )
此方法参数的解释和使用方式与 23.1.3.28 中定义的 Array.prototype.slice 相同。
调用时,此方法执行以下步骤:
- 令 obj 为 this value。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 sourceArrayLength 为 TypedArrayLength(taRecord)。
- 令 startIndex 为 ? ToClampedIndex(start, sourceArrayLength)。
- 如果 end 是 undefined,则令 endIndex 为 sourceArrayLength;否则令 endIndex 为 ? ToClampedIndex(end, sourceArrayLength)。
- 令 countBytes 为 max(endIndex - startIndex, 0)。
- 令 resultArray 为 ? TypedArraySpeciesCreate(obj, « 𝔽(countBytes) »)。
- 如果 countBytes > 0,则
- 将 taRecord 设置为 ? ValidateTypedArrayBounds(obj, seq-cst)。
- 将 endIndex 设置为 min(endIndex, TypedArrayLength(taRecord))。
- 将 countBytes 设置为 max(endIndex - startIndex, 0)。
- 令 sourceType 为 TypedArrayElementType(obj)。
- 令 targetType 为 TypedArrayElementType(resultArray)。
- 如果 sourceType 是 targetType,则
- 注:传输必须以保留源数据位级编码的方式执行。
- 令 sourceBuffer 为 obj.[[ViewedArrayBuffer]]。
- 令 targetBuffer 为 resultArray.[[ViewedArrayBuffer]]。
- 令 elementSize 为 TypedArrayElementSize(obj)。
- 令 sourceByteOffset 为 obj.[[ByteOffset]]。
- 令 sourceByteIndex 为 (startIndex × elementSize) + sourceByteOffset。
- 令 targetByteIndex 为 resultArray.[[ByteOffset]]。
- 令 endByteIndex 为 targetByteIndex + (countBytes × elementSize)。
- 当 targetByteIndex < endByteIndex 时,重复执行,
- 令 value 为 GetValueFromBuffer(sourceBuffer, sourceByteIndex, uint8, true, unordered)。
- 执行 SetValueInBuffer(targetBuffer, targetByteIndex, uint8, value, true, unordered)。
- 将 sourceByteIndex 设置为 sourceByteIndex + 1。
- 将 targetByteIndex 设置为 targetByteIndex + 1。
- 否则,
- 令 n 为 0。
- 令 k 为 startIndex。
- 当 k < endIndex 时,重复执行,
- 令 kValue 为 TypedArrayGetElement(obj, 𝔽(k))。
- 执行 ! TypedArraySetElement(resultArray, 𝔽(n), kValue)。
- 将 k 设置为 k + 1。
- 将 n 设置为 n + 1。
- 返回 resultArray。
此方法不是通用方法。this value 必须是具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.28 %TypedArray%.prototype.some ( callback [ , thisArg ] )
此方法参数的解释和使用方式与 23.1.3.29 中定义的 Array.prototype.some 相同。
调用时,此方法执行以下步骤:
- 令 obj 为 this value。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 length 为 TypedArrayLength(taRecord)。
- 如果 IsCallable(callback) 是 false,则抛出 TypeError 异常。
- 令 k 为 0。
- 当 k < length 时,重复执行,
- 令 kValue 为 TypedArrayGetElement(obj, 𝔽(k))。
- 令 testResult 为 ToBoolean(? Call(callback, thisArg, « kValue, 𝔽(k), obj »))。
- 如果 testResult 是 true,则返回 true。
- 将 k 设置为 k + 1。
- 返回 false。
此方法不是通用方法。this value 必须是具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.29 %TypedArray%.prototype.sort ( comparator )
这是一个独立的方法,除下述内容外,它实现与 23.1.3.30 中定义的 Array.prototype.sort 相同的要求。实现可以利用 this value 是具有固定长度且整数索引属性不稀疏的对象这一事实来优化此方法。
此方法不是通用方法。this value 必须是具有 [[TypedArrayName]] 内部槽的对象。
调用时,它执行以下步骤:
- 如果 comparator 不是 undefined 且 IsCallable(comparator) 是 false,则抛出 TypeError 异常。
- 令 obj 为 this value。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 length 为 TypedArrayLength(taRecord)。
- 注:以下闭包执行数值比较,而不是 23.1.3.30 中使用的字符串比较。
- 令 sortCompare 为参数为 (x, y) 的新 Abstract Closure,它捕获 comparator,并在被调用时执行以下步骤:
- 返回 ? CompareTypedArrayElements(x, y, comparator)。
- 令 sortedList 为 ? SortIndexedProperties(obj, length, sortCompare, read-through-holes)。
- 令 j 为 0。
- 当 j < length 时,重复执行,
- 执行 ! TypedArraySetElement(obj, 𝔽(j), sortedList[j])。
- 将 j 设置为 j + 1。
- 返回 obj。
注
由于 NaN 始终比较为大于任何其他值(参见 CompareTypedArrayElements),因此在未提供 comparator 时,NaN 属性值总是排序到结果末尾。
23.2.3.30 %TypedArray%.prototype.subarray ( start, end )
此方法返回新的 TypedArray,其元素类型与此 TypedArray 的元素类型相同,其 ArrayBuffer 是此 TypedArray 的 ArrayBuffer,并引用从 start(包含)到 end(不包含)区间内的元素。如果 start 或 end 为负,则它表示从数组末尾而不是开头起算的索引。
调用时,它执行以下步骤:
- 令 obj 为 this value。
- 执行 ? RequireInternalSlot(obj, [[TypedArrayName]])。
- 断言:obj 具有 [[ViewedArrayBuffer]] 内部槽。
- 令 buffer 为 obj.[[ViewedArrayBuffer]]。
- 令 sourceRecord 为 MakeTypedArrayWithBufferWitnessRecord(obj, seq-cst)。
- 如果 IsTypedArrayOutOfBounds(sourceRecord) 是 true,则
- 令 sourceLength 为 0。
- 否则,
- 令 sourceLength 为 TypedArrayLength(sourceRecord)。
- 令 startIndex 为 ? ToClampedIndex(start, sourceLength)。
- 令 elementSize 为 TypedArrayElementSize(obj)。
- 令 sourceByteOffset 为 obj.[[ByteOffset]]。
- 令 beginByteOffset 为 sourceByteOffset + (startIndex × elementSize)。
- 如果 obj.[[ArrayLength]] 是 auto 且 end 是 undefined,则
- 返回 ? TypedArraySpeciesCreate(obj, « buffer, 𝔽(beginByteOffset) »)。
- 如果 end 是 undefined,则令 endIndex 为 sourceLength;否则令 endIndex 为 ? ToClampedIndex(end, sourceLength)。
- 令 newLength 为 max(endIndex - startIndex, 0)。
- 返回 ? TypedArraySpeciesCreate(obj, « buffer, 𝔽(beginByteOffset), 𝔽(newLength) »)。
此方法不是通用方法。this value 必须是具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.31 %TypedArray%.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )
这是一个独立的方法,它实现与 23.1.3.32 中定义的 Array.prototype.toLocaleString 相同的算法,但使用 TypedArrayLength 替代对 "length" 执行 [[Get]]。当底层缓冲区不可调整大小时,可以利用 this value 具有固定长度且其整数索引属性不稀疏这一事实优化该算法的实现。不过,此类优化不得对算法规定的行为引入任何可观察的变化。
此方法不是通用方法。在求值该算法之前,会以 this value 和 seq-cst 作为参数调用 ValidateTypedArray。如果其结果是突然完成,则会抛出该异常,而不是求值该算法。
注
如果 ECMAScript 实现包含 ECMA-402 国际化 API,则此方法基于 ECMA-402 中的 Array.prototype.toLocaleString 算法。
23.2.3.32 %TypedArray%.prototype.toReversed ( )
调用时,此方法执行以下步骤:
- 令 obj 为 this value。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 length 为 TypedArrayLength(taRecord)。
- 令 resultArray 为 ? TypedArrayCreateSameType(obj, length)。
- 令 k 为 0。
- 当 k < length 时,重复执行,
- 令 from 为 length - k - 1。
- 令 fromValue 为 TypedArrayGetElement(obj, 𝔽(from))。
- 执行 ! TypedArraySetElement(resultArray, 𝔽(k), fromValue)。
- 将 k 设置为 k + 1。
- 返回 resultArray。
23.2.3.33 %TypedArray%.prototype.toSorted ( comparator )
调用时,此方法执行以下步骤:
- 如果 comparator 不是 undefined 且 IsCallable(comparator) 是 false,则抛出 TypeError 异常。
- 令 obj 为 this value。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 length 为 TypedArrayLength(taRecord)。
- 令 resultArray 为 ? TypedArrayCreateSameType(obj, length)。
- 注:以下闭包执行数值比较,而不是 23.1.3.34 中使用的字符串比较。
- 令 sortCompare 为参数为 (x, y) 的新 Abstract Closure,它捕获 comparator,并在被调用时执行以下步骤:
- 返回 ? CompareTypedArrayElements(x, y, comparator)。
- 令 sortedList 为 ? SortIndexedProperties(obj, length, sortCompare, read-through-holes)。
- 令 j 为 0。
- 当 j < length 时,重复执行,
- 执行 ! TypedArraySetElement(resultArray, 𝔽(j), sortedList[j])。
- 将 j 设置为 j + 1。
- 返回 resultArray。
23.2.3.34 %TypedArray%.prototype.toString ( )
"toString" 属性的初始值是 23.1.3.36 中定义的 %Array.prototype.toString%。
23.2.3.35 %TypedArray%.prototype.values ( )
调用时,此方法执行以下步骤:
- 令 obj 为 this value。
- 执行 ? ValidateTypedArray(obj, seq-cst)。
- 返回 CreateArrayIterator(obj, value)。
23.2.3.36 %TypedArray%.prototype.with ( index, value )
调用时,此方法执行以下步骤:
- 令 obj 为 this value。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 length 为 TypedArrayLength(taRecord)。
- 令 actualIndex 为 ? ToAbsoluteIndex(index, length)。
- 如果 obj.[[ContentType]] 是 bigint,则令 numericValue 为 ? ToBigInt(value)。
- 否则,令 numericValue 为 ? ToNumber(value)。
- 如果 IsValidIntegerIndex(obj, 𝔽(actualIndex)) 是 false,则抛出 RangeError 异常。
- 令 resultArray 为 ? TypedArrayCreateSameType(obj, length)。
- 令 k 为 0。
- 当 k < length 时,重复执行,
- 如果 k = actualIndex,则令 fromValue 为 numericValue。
- 否则,令 fromValue 为 TypedArrayGetElement(obj, 𝔽(k))。
- 执行 ! TypedArraySetElement(resultArray, 𝔽(k), fromValue)。
- 将 k 设置为 k + 1。
- 返回 resultArray。
23.2.3.37 %TypedArray%.prototype [ %Symbol.iterator% ] ( )
%Symbol.iterator% 属性的初始值是 23.2.3.35 中定义的 %TypedArray.prototype.values%。
23.2.3.38 get %TypedArray%.prototype [ %Symbol.toStringTag% ]
%TypedArray%.prototype[%Symbol.toStringTag%] 是访问器属性,其 set 访问器函数为 undefined。其 get 访问器函数在调用时执行以下步骤:
- 令 obj 为 this value。
- 如果 obj 不是 Object,则返回 undefined。
- 如果 obj 不具有 [[TypedArrayName]] 内部槽,则返回 undefined。
- 令 name 为 obj.[[TypedArrayName]]。
- 断言:name 是 String。
- 返回 name。
此属性具有特性 { [[Enumerable]]: false, [[Configurable]]: true }。
此函数的 "name" 属性的初始值是 "get [Symbol.toStringTag]"。