23.2.3 %TypedArray% 原型对象的属性
%TypedArray% 原型对象:
- 有一个 [[Prototype]] 内部槽,其值为 %Object.prototype%。
- 是 %TypedArray.prototype%。
- 是一个普通对象。
- 没有 [[ViewedArrayBuffer]] 或任何其他特定于 TypedArray 实例对象的内部槽。
23.2.3.1 %TypedArray%.prototype.at ( index )
- 令 obj 为 this 值。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 len 为 TypedArrayLength(taRecord)。
- 令 relativeIndex 为 ? ToIntegerOrInfinity(index)。
- 如果 relativeIndex ≥ 0,则
- 令 k 为 relativeIndex。
- 否则,
- 令 k 为 len + relativeIndex。
- 如果 k < 0 或 k ≥ len,返回 undefined。
- 返回 ! Get(obj, ! ToString(𝔽(k)))。
23.2.3.2 get %TypedArray%.prototype.buffer
%TypedArray%.prototype.buffer 是一个访问器属性,其 set 访问器函数为 undefined。它的 get 访问器函数在被调用时执行以下步骤:
- 令 obj 为 this 值。
- 执行 ? 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 值。
- 执行 ? 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 值。
- 执行 ? 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 值。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 len 为 TypedArrayLength(taRecord)。
- 令 relativeTarget 为 ? ToIntegerOrInfinity(target)。
- 如果 relativeTarget = -∞,令 targetIndex 为 0。
- 否则如果 relativeTarget < 0,令 targetIndex 为 max(len + relativeTarget, 0)。
- 否则,令 targetIndex 为 min(relativeTarget, len)。
- 令 relativeStart 为 ? ToIntegerOrInfinity(start)。
- 如果 relativeStart = -∞,令 startIndex 为 0。
- 否则如果 relativeStart < 0,令 startIndex 为 max(len + relativeStart, 0)。
- 否则,令 startIndex 为 min(relativeStart, len)。
- 如果 end 是 undefined,令 relativeEnd 为 len;否则令 relativeEnd 为 ? ToIntegerOrInfinity(end)。
- 如果 relativeEnd = -∞,令 endIndex 为 0。
- 否则如果 relativeEnd < 0,令 endIndex 为 max(len + relativeEnd, 0)。
- 否则,令 endIndex 为 min(relativeEnd, len)。
- 令 count 为 min(endIndex - startIndex, len - targetIndex)。
- 如果 count > 0,则
- 注:复制必须以保留源数据位级编码的方式执行。
- 令 buffer 为 obj.[[ViewedArrayBuffer]]。
- 将 taRecord 设置为 MakeTypedArrayWithBufferWitnessRecord(obj, seq-cst)。
- 如果 IsTypedArrayOutOfBounds(taRecord) 是 true,抛出 TypeError 异常。
- 将 len 设置为 TypedArrayLength(taRecord)。
- 注:上述步骤的副作用可能减小了 obj 的大小,在这种情况下复制应按仍适用的最长前缀继续进行。
- 将 count 设置为 min(count, len - startIndex, len - 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 时,
- 令 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 值。
- 执行 ? 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 值。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 len 为 TypedArrayLength(taRecord)。
- 如果 IsCallable(callback) 是 false,抛出 TypeError 异常。
- 令 k 为 0。
- 重复,当 k < len 时,
- 令 propertyKey 为 ! ToString(𝔽(k))。
- 令 kValue 为 ! Get(obj, propertyKey)。
- 令 testResult 为 ToBoolean(? Call(callback, thisArg, « kValue, 𝔽(k), obj »))。
- 如果 testResult 是 false,返回 false。
- 将 k 设置为 k + 1。
- 返回 true。
此方法不是泛型的。this 值必须是一个具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.9 %TypedArray%.prototype.fill ( value [ , start [ , end ] ] )
此方法的参数解释和使用方式与 23.1.3.7 中定义的 Array.prototype.fill 相同。
此方法在被调用时执行以下步骤:
- 令 obj 为 this 值。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 len 为 TypedArrayLength(taRecord)。
- 如果 obj.[[ContentType]] 是 bigint,将 value 设置为 ? ToBigInt(value)。
- 否则,将 value 设置为 ? ToNumber(value)。
- 令 relativeStart 为 ? ToIntegerOrInfinity(start)。
- 如果 relativeStart = -∞,令 startIndex 为 0。
- 否则如果 relativeStart < 0,令 startIndex 为 max(len + relativeStart, 0)。
- 否则,令 startIndex 为 min(relativeStart, len)。
- 如果 end 是 undefined,令 relativeEnd 为 len;否则令 relativeEnd 为 ? ToIntegerOrInfinity(end)。
- 如果 relativeEnd = -∞,令 endIndex 为 0。
- 否则如果 relativeEnd < 0,令 endIndex 为 max(len + relativeEnd, 0)。
- 否则,令 endIndex 为 min(relativeEnd, len)。
- 将 taRecord 设置为 MakeTypedArrayWithBufferWitnessRecord(obj, seq-cst)。
- 如果 IsTypedArrayOutOfBounds(taRecord) 是 true,抛出 TypeError 异常。
- 将 len 设置为 TypedArrayLength(taRecord)。
- 将 endIndex 设置为 min(endIndex, len)。
- 令 k 为 startIndex。
- 重复,当 k < endIndex 时,
- 令 propertyKey 为 ! ToString(𝔽(k))。
- 执行 ! Set(obj, propertyKey, value, true)。
- 将 k 设置为 k + 1。
- 返回 obj。
23.2.3.10 %TypedArray%.prototype.filter ( callback [ , thisArg ] )
此方法的参数解释和使用方式与 23.1.3.8 中定义的 Array.prototype.filter 相同。
此方法在被调用时执行以下步骤:
- 令 obj 为 this 值。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 len 为 TypedArrayLength(taRecord)。
- 如果 IsCallable(callback) 是 false,抛出 TypeError 异常。
- 令 kept 为一个新的空 List。
- 令 captured 为 0。
- 令 k 为 0。
- 重复,当 k < len 时,
- 令 propertyKey 为 ! ToString(𝔽(k))。
- 令 kValue 为 ! Get(obj, propertyKey)。
- 令 selected 为 ToBoolean(? Call(callback, thisArg, « kValue, 𝔽(k), obj »))。
- 如果 selected 是 true,则
- 将 kValue 追加到 kept。
- 将 captured 设置为 captured + 1。
- 将 k 设置为 k + 1。
- 令 resultTypedArray 为 ? TypedArraySpeciesCreate(obj, « 𝔽(captured) »)。
- 令 n 为 0。
- 对于 kept 的每个元素 e,执行
- 执行 ! Set(resultTypedArray, ! ToString(𝔽(n)), e, true)。
- 将 n 设置为 n + 1。
- 返回 resultTypedArray。
此方法不是泛型的。this 值必须是一个具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.11 %TypedArray%.prototype.find ( predicate [ , thisArg ] )
此方法的参数解释和使用方式与 23.1.3.9 中定义的 Array.prototype.find 相同。
此方法在被调用时执行以下步骤:
- 令 obj 为 this 值。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 len 为 TypedArrayLength(taRecord)。
- 令 findRec 为 ? FindViaPredicate(obj, len, ascending, predicate, thisArg)。
- 返回 findRec.[[Value]]。
此方法不是泛型的。this 值必须是一个具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.12 %TypedArray%.prototype.findIndex ( predicate [ , thisArg ] )
此方法的参数解释和使用方式与 23.1.3.10 中定义的 Array.prototype.findIndex 相同。
此方法在被调用时执行以下步骤:
- 令 obj 为 this 值。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 len 为 TypedArrayLength(taRecord)。
- 令 findRec 为 ? FindViaPredicate(obj, len, ascending, predicate, thisArg)。
- 返回 findRec.[[Index]]。
此方法不是泛型的。this 值必须是一个具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.13 %TypedArray%.prototype.findLast ( predicate [ , thisArg ] )
此方法的参数解释和使用方式与 23.1.3.11 中定义的 Array.prototype.findLast 相同。
此方法在被调用时执行以下步骤:
- 令 obj 为 this 值。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 len 为 TypedArrayLength(taRecord)。
- 令 findRec 为 ? FindViaPredicate(obj, len, descending, predicate, thisArg)。
- 返回 findRec.[[Value]]。
此方法不是泛型的。this 值必须是一个具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.14 %TypedArray%.prototype.findLastIndex ( predicate [ , thisArg ] )
此方法的参数解释和使用方式与 23.1.3.12 中定义的 Array.prototype.findLastIndex 相同。
此方法在被调用时执行以下步骤:
- 令 obj 为 this 值。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 len 为 TypedArrayLength(taRecord)。
- 令 findRec 为 ? FindViaPredicate(obj, len, descending, predicate, thisArg)。
- 返回 findRec.[[Index]]。
此方法不是泛型的。this 值必须是一个具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.15 %TypedArray%.prototype.forEach ( callback [ , thisArg ] )
此方法的参数解释和使用方式与 23.1.3.15 中定义的 Array.prototype.forEach 相同。
此方法在被调用时执行以下步骤:
- 令 obj 为 this 值。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 len 为 TypedArrayLength(taRecord)。
- 如果 IsCallable(callback) 是 false,抛出 TypeError 异常。
- 令 k 为 0。
- 重复,当 k < len 时,
- 令 propertyKey 为 ! ToString(𝔽(k))。
- 令 kValue 为 ! Get(obj, propertyKey)。
- 执行 ? Call(callback, thisArg, « kValue, 𝔽(k), obj »)。
- 将 k 设置为 k + 1。
- 返回 undefined。
此方法不是泛型的。this 值必须是一个具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.16 %TypedArray%.prototype.includes ( searchElement [ , fromIndex ] )
此方法的参数解释和使用方式与 23.1.3.16 中定义的 Array.prototype.includes 相同。
此方法在被调用时执行以下步骤:
- 令 obj 为 this 值。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 len 为 TypedArrayLength(taRecord)。
- 如果 len = 0,返回 false。
- 令 n 为 ? ToIntegerOrInfinity(fromIndex)。
- 断言:如果 fromIndex 是 undefined,则 n 为 0。
- 如果 n = +∞,返回 false。
- 如果 n = -∞,将 n 设置为 0。
- 如果 n ≥ 0,则
- 令 k 为 n。
- 否则,
- 令 k 为 len + n。
- 如果 k < 0,将 k 设置为 0。
- 重复,当 k < len 时,
- 令 elementK 为 ! Get(obj, ! ToString(𝔽(k)))。
- 如果 SameValueZero(searchElement, elementK) 是 true,返回 true。
- 将 k 设置为 k + 1。
- 返回 false。
此方法不是泛型的。this 值必须是一个具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.17 %TypedArray%.prototype.indexOf ( searchElement [ , fromIndex ] )
此方法的参数解释和使用方式与 23.1.3.17 中定义的 Array.prototype.indexOf 相同。
此方法在被调用时执行以下步骤:
- 令 obj 为 this 值。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 len 为 TypedArrayLength(taRecord)。
- 如果 len = 0,返回 -1𝔽。
- 令 n 为 ? ToIntegerOrInfinity(fromIndex)。
- 断言:如果 fromIndex 是 undefined,则 n 为 0。
- 如果 n = +∞,返回 -1𝔽。
- 如果 n = -∞,将 n 设置为 0。
- 如果 n ≥ 0,则
- 令 k 为 n。
- 否则,
- 令 k 为 len + n。
- 如果 k < 0,将 k 设置为 0。
- 重复,当 k < len 时,
- 令 propertyKey 为 ! ToString(𝔽(k))。
- 令 kPresent 为 ! HasProperty(obj, propertyKey)。
- 如果 kPresent 是 true,则
- 令 elementK 为 ! Get(obj, propertyKey)。
- 如果 IsStrictlyEqual(searchElement, elementK) 是 true,返回 𝔽(k)。
- 将 k 设置为 k + 1。
- 返回 -1𝔽。
此方法不是泛型的。this 值必须是一个具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.18 %TypedArray%.prototype.join ( separator )
此方法的参数解释和使用方式与 23.1.3.18 中定义的 Array.prototype.join 相同。
此方法在被调用时执行以下步骤:
- 令 obj 为 this 值。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 len 为 TypedArrayLength(taRecord)。
- 如果 separator 是 undefined,令 sep 为 ","。
- 否则,令 sep 为 ? ToString(separator)。
- 令 result 为空 String。
- 令 k 为 0。
- 重复,当 k < len 时,
- 如果 k > 0,将 result 设置为 result 与 sep 的字符串拼接。
- 令 element 为 ! Get(obj, ! ToString(𝔽(k)))。
- 如果 element 不是 undefined,则
- 令 elementStr 为 ! ToString(element)。
- 将 result 设置为 result 与 elementStr 的字符串拼接。
- 将 k 设置为 k + 1。
- 返回 result。
此方法不是泛型的。this 值必须是一个具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.19 %TypedArray%.prototype.keys ( )
此方法在被调用时执行以下步骤:
- 令 obj 为 this 值。
- 执行 ? 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 值。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 len 为 TypedArrayLength(taRecord)。
- 如果 len = 0,返回 -1𝔽。
- 如果 fromIndex 存在,令 n 为 ? ToIntegerOrInfinity(fromIndex);否则令 n 为 len - 1。
- 如果 n = -∞,返回 -1𝔽。
- 如果 n ≥ 0,则
- 令 k 为 min(n, len - 1)。
- 否则,
- 令 k 为 len + n。
- 重复,当 k ≥ 0 时,
- 令 propertyKey 为 ! ToString(𝔽(k))。
- 令 kPresent 为 ! HasProperty(obj, propertyKey)。
- 如果 kPresent 是 true,则
- 令 elementK 为 ! Get(obj, propertyKey)。
- 如果 IsStrictlyEqual(searchElement, elementK) 是 true,返回 𝔽(k)。
- 将 k 设置为 k - 1。
- 返回 -1𝔽。
此方法不是泛型的。this 值必须是一个具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.21 get %TypedArray%.prototype.length
%TypedArray%.prototype.length 是一个访问器属性,其 set 访问器函数为 undefined。它的 get 访问器函数在被调用时执行以下步骤:
- 令 obj 为 this 值。
- 执行 ? RequireInternalSlot(obj, [[TypedArrayName]])。
- 断言:obj 有 [[ViewedArrayBuffer]] 和 [[ArrayLength]] 内部槽。
- 令 taRecord 为 MakeTypedArrayWithBufferWitnessRecord(obj, seq-cst)。
- 如果 IsTypedArrayOutOfBounds(taRecord) 是 true,返回 +0𝔽。
- 令 length 为 TypedArrayLength(taRecord)。
- 返回 𝔽(length)。
此函数不是泛型的。this 值必须是一个具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.22 %TypedArray%.prototype.map ( callback [ , thisArg ] )
此方法的参数解释和使用方式与 23.1.3.21 中定义的 Array.prototype.map 相同。
此方法在被调用时执行以下步骤:
- 令 obj 为 this 值。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 len 为 TypedArrayLength(taRecord)。
- 如果 IsCallable(callback) 是 false,抛出 TypeError 异常。
- 令 resultTypedArray 为 ? TypedArraySpeciesCreate(obj, « 𝔽(len) »)。
- 令 k 为 0。
- 重复,当 k < len 时,
- 令 propertyKey 为 ! ToString(𝔽(k))。
- 令 kValue 为 ! Get(obj, propertyKey)。
- 令 mappedValue 为 ? Call(callback, thisArg, « kValue, 𝔽(k), obj »)。
- 执行 ? Set(resultTypedArray, propertyKey, mappedValue, true)。
- 将 k 设置为 k + 1。
- 返回 resultTypedArray。
此方法不是泛型的。this 值必须是一个具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.23 %TypedArray%.prototype.reduce ( callback [ , initialValue ] )
此方法的参数解释和使用方式与 23.1.3.24 中定义的 Array.prototype.reduce 相同。
此方法在被调用时执行以下步骤:
- 令 obj 为 this 值。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 len 为 TypedArrayLength(taRecord)。
- 如果 IsCallable(callback) 是 false,抛出 TypeError 异常。
- 如果 len = 0 且 initialValue 不存在,抛出 TypeError 异常。
- 令 k 为 0。
- 令 accumulator 为 undefined。
- 如果 initialValue 存在,则
- 将 accumulator 设置为 initialValue。
- 否则,
- 令 propertyKey 为 ! ToString(𝔽(k))。
- 将 accumulator 设置为 ! Get(obj, propertyKey)。
- 将 k 设置为 k + 1。
- 重复,当 k < len 时,
- 令 propertyKey 为 ! ToString(𝔽(k))。
- 令 kValue 为 ! Get(obj, propertyKey)。
- 将 accumulator 设置为 ? Call(callback, undefined, « accumulator, kValue, 𝔽(k), obj »)。
- 将 k 设置为 k + 1。
- 返回 accumulator。
此方法不是泛型的。this 值必须是一个具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.24 %TypedArray%.prototype.reduceRight ( callback [ , initialValue ] )
此方法的参数解释和使用方式与 23.1.3.25 中定义的 Array.prototype.reduceRight 相同。
此方法在被调用时执行以下步骤:
- 令 obj 为 this 值。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 len 为 TypedArrayLength(taRecord)。
- 如果 IsCallable(callback) 是 false,抛出 TypeError 异常。
- 如果 len = 0 且 initialValue 不存在,抛出 TypeError 异常。
- 令 k 为 len - 1。
- 令 accumulator 为 undefined。
- 如果 initialValue 存在,则
- 将 accumulator 设置为 initialValue。
- 否则,
- 令 propertyKey 为 ! ToString(𝔽(k))。
- 将 accumulator 设置为 ! Get(obj, propertyKey)。
- 将 k 设置为 k - 1。
- 重复,当 k ≥ 0 时,
- 令 propertyKey 为 ! ToString(𝔽(k))。
- 令 kValue 为 ! Get(obj, propertyKey)。
- 将 accumulator 设置为 ? Call(callback, undefined, « accumulator, kValue, 𝔽(k), obj »)。
- 将 k 设置为 k - 1。
- 返回 accumulator。
此方法不是泛型的。this 值必须是一个具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.25 %TypedArray%.prototype.reverse ( )
此方法的参数解释和使用方式与 23.1.3.26 中定义的 Array.prototype.reverse 相同。
此方法在被调用时执行以下步骤:
- 令 obj 为 this 值。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 len 为 TypedArrayLength(taRecord)。
- 令 middle 为 floor(len / 2)。
- 令 lower 为 0。
- 重复,当 lower ≠ middle 时,
- 令 upper 为 len - lower - 1。
- 令 upperP 为 ! ToString(𝔽(upper))。
- 令 lowerP 为 ! ToString(𝔽(lower))。
- 令 lowerValue 为 ! Get(obj, lowerP)。
- 令 upperValue 为 ! Get(obj, upperP)。
- 执行 ! Set(obj, lowerP, upperValue, true)。
- 执行 ! Set(obj, upperP, lowerValue, true)。
- 将 lower 设置为 lower + 1。
- 返回 obj。
此方法不是泛型的。this 值必须是一个具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.26 %TypedArray%.prototype.set ( source [ , offset ] )
此方法在此 TypedArray 中设置多个值,从 source 读取值。细节取决于 source 的类型。可选的 offset 值指示在此 TypedArray 中写入值的第一个元素索引。如果省略,则假定为 0。
它在被调用时执行以下步骤:
- 令 target 为 this 值。
- 执行 ? RequireInternalSlot(target, [[TypedArrayName]])。
- 断言:target 有 [[ViewedArrayBuffer]] 内部槽。
- 令 targetOffset 为 ? ToIntegerOrInfinity(offset)。
- 如果 targetOffset < 0,抛出 RangeError 异常。
- 如果 source 是一个具有 [[TypedArrayName]] 内部槽的 Object,则
- 执行 ? SetTypedArrayFromTypedArray(target, targetOffset, source)。
- 否则,
- 执行 ? SetTypedArrayFromArrayLike(target, targetOffset, source)。
- 返回 undefined。
此方法不是泛型的。this 值必须是一个具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.26.1 SetTypedArrayFromArrayLike ( target, targetOffset, source )
The abstract operation SetTypedArrayFromArrayLike takes arguments target (一个 TypedArray,), targetOffset (一个非负整数或 +∞,), and source (一个 ECMAScript 语言值,但不是 TypedArray,) and returns 要么是一个包含 unused 的正常完成,要么是一个抛出完成. 它从 source 读取值,从索引 targetOffset 开始在 target 中设置多个值。 It performs the following steps when called:
- 令 targetRecord 为 MakeTypedArrayWithBufferWitnessRecord(target, seq-cst)。
- 如果 IsTypedArrayOutOfBounds(targetRecord) 是 true,抛出 TypeError 异常。
- 令 targetLength 为 TypedArrayLength(targetRecord)。
- 令 src 为 ? ToObject(source)。
- 令 srcLength 为 ? LengthOfArrayLike(src)。
- 如果 targetOffset = +∞,抛出 RangeError 异常。
- 如果 srcLength + targetOffset > targetLength,抛出 RangeError 异常。
- 令 k 为 0。
- 重复,当 k < srcLength 时,
- 令 propertyKey 为 ! ToString(𝔽(k))。
- 令 value 为 ? Get(src, propertyKey)。
- 令 targetIndex 为 𝔽(targetOffset + k)。
- 执行 ? TypedArraySetElement(target, targetIndex, value)。
- 将 k 设置为 k + 1。
- 返回 unused。
23.2.3.26.2 SetTypedArrayFromTypedArray ( target, targetOffset, source )
The abstract operation SetTypedArrayFromTypedArray takes arguments target (一个 TypedArray,), targetOffset (一个非负整数或 +∞,), and source (一个 TypedArray,) and returns 要么是一个包含 unused 的正常完成,要么是一个抛出完成. 它从 source 读取值,从索引 targetOffset 开始在 target 中设置多个值。 It performs the following steps when called:
- 令 targetBuffer 为 target.[[ViewedArrayBuffer]]。
- 令 targetRecord 为 MakeTypedArrayWithBufferWitnessRecord(target, seq-cst)。
- 如果 IsTypedArrayOutOfBounds(targetRecord) 是 true,抛出 TypeError 异常。
- 令 targetLength 为 TypedArrayLength(targetRecord)。
- 令 srcBuffer 为 source.[[ViewedArrayBuffer]]。
- 令 srcRecord 为 MakeTypedArrayWithBufferWitnessRecord(source, seq-cst)。
- 如果 IsTypedArrayOutOfBounds(srcRecord) 是 true,抛出 TypeError 异常。
- 令 srcLength 为 TypedArrayLength(srcRecord)。
- 令 targetType 为 TypedArrayElementType(target)。
- 令 targetElementSize 为 TypedArrayElementSize(target)。
- 令 targetByteOffset 为 target.[[ByteOffset]]。
- 令 srcType 为 TypedArrayElementType(source)。
- 令 srcElementSize 为 TypedArrayElementSize(source)。
- 令 srcByteOffset 为 source.[[ByteOffset]]。
- 如果 targetOffset = +∞,抛出 RangeError 异常。
- 如果 srcLength + targetOffset > targetLength,抛出 RangeError 异常。
- 如果 target.[[ContentType]] 不是 source.[[ContentType]],抛出 TypeError 异常。
- 如果 IsSharedArrayBuffer(srcBuffer) 是 true,IsSharedArrayBuffer(targetBuffer) 是 true,并且 srcBuffer.[[ArrayBufferData]] 是 targetBuffer.[[ArrayBufferData]],令 sameSharedArrayBuffer 为 true;否则令 sameSharedArrayBuffer 为 false。
- 如果 SameValue(srcBuffer, targetBuffer) 是 true 或 sameSharedArrayBuffer 是 true,则
- 令 srcByteLength 为 TypedArrayByteLength(srcRecord)。
- 将 srcBuffer 设置为 ? CloneArrayBuffer(srcBuffer, srcByteOffset, srcByteLength)。
- 令 srcByteIndex 为 0。
- 否则,
- 令 srcByteIndex 为 srcByteOffset。
- 令 targetByteIndex 为 (targetOffset × targetElementSize) + targetByteOffset。
- 令 limit 为 targetByteIndex + (targetElementSize × srcLength)。
- 如果 srcType 是 targetType,则
- 注:传输必须以保留源数据位级编码的方式执行。
- 重复,当 targetByteIndex < limit 时,
- 令 value 为 GetValueFromBuffer(srcBuffer, srcByteIndex, uint8, true, unordered)。
- 执行 SetValueInBuffer(targetBuffer, targetByteIndex, uint8, value, true, unordered)。
- 将 srcByteIndex 设置为 srcByteIndex + 1。
- 将 targetByteIndex 设置为 targetByteIndex + 1。
- 否则,
- 重复,当 targetByteIndex < limit 时,
- 令 value 为 GetValueFromBuffer(srcBuffer, srcByteIndex, srcType, true, unordered)。
- 执行 SetValueInBuffer(targetBuffer, targetByteIndex, targetType, value, true, unordered)。
- 将 srcByteIndex 设置为 srcByteIndex + srcElementSize。
- 将 targetByteIndex 设置为 targetByteIndex + targetElementSize。
- 返回 unused。
23.2.3.27 %TypedArray%.prototype.slice ( start, end )
此方法的参数解释和使用方式与 23.1.3.28 中定义的 Array.prototype.slice 相同。
此方法在被调用时执行以下步骤:
- 令 obj 为 this 值。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 srcArrayLength 为 TypedArrayLength(taRecord)。
- 令 relativeStart 为 ? ToIntegerOrInfinity(start)。
- 如果 relativeStart = -∞,令 startIndex 为 0。
- 否则如果 relativeStart < 0,令 startIndex 为 max(srcArrayLength + relativeStart, 0)。
- 否则,令 startIndex 为 min(relativeStart, srcArrayLength)。
- 如果 end 是 undefined,令 relativeEnd 为 srcArrayLength;否则令 relativeEnd 为 ? ToIntegerOrInfinity(end)。
- 如果 relativeEnd = -∞,令 endIndex 为 0。
- 否则如果 relativeEnd < 0,令 endIndex 为 max(srcArrayLength + relativeEnd, 0)。
- 否则,令 endIndex 为 min(relativeEnd, srcArrayLength)。
- 令 countBytes 为 max(endIndex - startIndex, 0)。
- 令 resultArray 为 ? TypedArraySpeciesCreate(obj, « 𝔽(countBytes) »)。
- 如果 countBytes > 0,则
- 将 taRecord 设置为 MakeTypedArrayWithBufferWitnessRecord(obj, seq-cst)。
- 如果 IsTypedArrayOutOfBounds(taRecord) 是 true,抛出 TypeError 异常。
- 将 endIndex 设置为 min(endIndex, TypedArrayLength(taRecord))。
- 将 countBytes 设置为 max(endIndex - startIndex, 0)。
- 令 srcType 为 TypedArrayElementType(obj)。
- 令 targetType 为 TypedArrayElementType(resultArray)。
- 如果 srcType 是 targetType,则
- 注:传输必须以保留源数据位级编码的方式执行。
- 令 srcBuffer 为 obj.[[ViewedArrayBuffer]]。
- 令 targetBuffer 为 resultArray.[[ViewedArrayBuffer]]。
- 令 elementSize 为 TypedArrayElementSize(obj)。
- 令 srcByteOffset 为 obj.[[ByteOffset]]。
- 令 srcByteIndex 为 (startIndex × elementSize) + srcByteOffset。
- 令 targetByteIndex 为 resultArray.[[ByteOffset]]。
- 令 endByteIndex 为 targetByteIndex + (countBytes × elementSize)。
- 重复,当 targetByteIndex < endByteIndex 时,
- 令 value 为 GetValueFromBuffer(srcBuffer, srcByteIndex, uint8, true, unordered)。
- 执行 SetValueInBuffer(targetBuffer, targetByteIndex, uint8, value, true, unordered)。
- 将 srcByteIndex 设置为 srcByteIndex + 1。
- 将 targetByteIndex 设置为 targetByteIndex + 1。
- 否则,
- 令 n 为 0。
- 令 k 为 startIndex。
- 重复,当 k < endIndex 时,
- 令 propertyKey 为 ! ToString(𝔽(k))。
- 令 kValue 为 ! Get(obj, propertyKey)。
- 执行 ! Set(resultArray, ! ToString(𝔽(n)), kValue, true)。
- 将 k 设置为 k + 1。
- 将 n 设置为 n + 1。
- 返回 resultArray。
此方法不是泛型的。this 值必须是一个具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.28 %TypedArray%.prototype.some ( callback [ , thisArg ] )
此方法的参数解释和使用方式与 23.1.3.29 中定义的 Array.prototype.some 相同。
此方法在被调用时执行以下步骤:
- 令 obj 为 this 值。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 len 为 TypedArrayLength(taRecord)。
- 如果 IsCallable(callback) 是 false,抛出 TypeError 异常。
- 令 k 为 0。
- 重复,当 k < len 时,
- 令 propertyKey 为 ! ToString(𝔽(k))。
- 令 kValue 为 ! Get(obj, propertyKey)。
- 令 testResult 为 ToBoolean(? Call(callback, thisArg, « kValue, 𝔽(k), obj »))。
- 如果 testResult 是 true,返回 true。
- 将 k 设置为 k + 1。
- 返回 false。
此方法不是泛型的。this 值必须是一个具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.29 %TypedArray%.prototype.sort ( comparator )
这是一个不同的方法,除下文所述外,它实现与 23.1.3.30 中定义的 Array.prototype.sort 相同的要求。此方法的实现可以基于以下事实进行优化:this 值是一个具有固定长度且其整数索引属性不稀疏的对象。
此方法不是泛型的。this 值必须是一个具有 [[TypedArrayName]] 内部槽的对象。
它在被调用时执行以下步骤:
- 如果 comparator 不是 undefined 且 IsCallable(comparator) 是 false,抛出 TypeError 异常。
- 令 obj 为 this 值。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 len 为 TypedArrayLength(taRecord)。
- 注:下面的闭包执行数值比较,而不是 23.1.3.30 中使用的字符串比较。
- 令 sortCompare 为一个新的 Abstract Closure,其参数为 (x, y),捕获 comparator,并在被调用时执行以下步骤:
- 返回 ? CompareTypedArrayElements(x, y, comparator)。
- 令 sortedList 为 ? SortIndexedProperties(obj, len, sortCompare, read-through-holes)。
- 令 j 为 0。
- 重复,当 j < len 时,
- 执行 ! Set(obj, ! ToString(𝔽(j)), sortedList[j], true)。
- 将 j 设置为 j + 1。
- 返回 obj。
Note
因为 NaN 总是比较为大于任何其他值(见 CompareTypedArrayElements),所以当未提供 comparator 时,NaN 属性值总是排序到结果末尾。
23.2.3.30 %TypedArray%.prototype.subarray ( start, end )
此方法返回一个新的 TypedArray,其元素类型是此 TypedArray 的元素类型,其 ArrayBuffer 是此 TypedArray 的 ArrayBuffer,并引用从 start(包含)到 end(不包含)区间内的元素。如果 start 或 end 为负,则它引用的是从数组末尾开始的索引,而不是从开头开始。
它在被调用时执行以下步骤:
- 令 obj 为 this 值。
- 执行 ? RequireInternalSlot(obj, [[TypedArrayName]])。
- 断言:obj 有 [[ViewedArrayBuffer]] 内部槽。
- 令 buffer 为 obj.[[ViewedArrayBuffer]]。
- 令 srcRecord 为 MakeTypedArrayWithBufferWitnessRecord(obj, seq-cst)。
- 如果 IsTypedArrayOutOfBounds(srcRecord) 是 true,则
- 令 srcLength 为 0。
- 否则,
- 令 srcLength 为 TypedArrayLength(srcRecord)。
- 令 relativeStart 为 ? ToIntegerOrInfinity(start)。
- 如果 relativeStart = -∞,令 startIndex 为 0。
- 否则如果 relativeStart < 0,令 startIndex 为 max(srcLength + relativeStart, 0)。
- 否则,令 startIndex 为 min(relativeStart, srcLength)。
- 令 elementSize 为 TypedArrayElementSize(obj)。
- 令 srcByteOffset 为 obj.[[ByteOffset]]。
- 令 beginByteOffset 为 srcByteOffset + (startIndex × elementSize)。
- 如果 obj.[[ArrayLength]] 是 auto 且 end 是 undefined,则
- 令 argumentsList 为 « buffer, 𝔽(beginByteOffset) »。
- 否则,
- 如果 end 是 undefined,令 relativeEnd 为 srcLength;否则令 relativeEnd 为 ? ToIntegerOrInfinity(end)。
- 如果 relativeEnd = -∞,令 endIndex 为 0。
- 否则如果 relativeEnd < 0,令 endIndex 为 max(srcLength + relativeEnd, 0)。
- 否则,令 endIndex 为 min(relativeEnd, srcLength)。
- 令 newLength 为 max(endIndex - startIndex, 0)。
- 令 argumentsList 为 « buffer, 𝔽(beginByteOffset), 𝔽(newLength) »。
- 返回 ? TypedArraySpeciesCreate(obj, argumentsList)。
此方法不是泛型的。this 值必须是一个具有 [[TypedArrayName]] 内部槽的对象。
23.2.3.31 %TypedArray%.prototype.toLocaleString ( [ reserved1 [ , reserved2 ] ] )
这是一个不同的方法,它实现与 23.1.3.32 中定义的 Array.prototype.toLocaleString 相同的算法,不同之处在于调用 TypedArrayLength 代替执行对 "length" 的 [[Get]]。在底层缓冲区不可调整大小时,可以基于以下事实优化该算法的实现:this 值具有固定长度且其整数索引属性不稀疏。然而,此类优化不得在算法的指定行为中引入任何可观察变化。
此方法不是泛型的。在求值该算法之前,会以 this 值和 seq-cst 作为参数调用 ValidateTypedArray。如果其结果是一个 abrupt completion,则抛出该异常,而不是求值该算法。
Note
如果 ECMAScript 实现包含 ECMA-402 国际化 API,则此方法基于 ECMA-402 规范中的 Array.prototype.toLocaleString 算法。
23.2.3.32 %TypedArray%.prototype.toReversed ( )
此方法在被调用时执行以下步骤:
- 令 obj 为 this 值。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 len 为 TypedArrayLength(taRecord)。
- 令 resultArray 为 ? TypedArrayCreateSameType(obj, len)。
- 令 k 为 0。
- 重复,当 k < len 时,
- 令 from 为 ! ToString(𝔽(len - k - 1))。
- 令 propertyKey 为 ! ToString(𝔽(k))。
- 令 fromValue 为 ! Get(obj, from)。
- 执行 ! Set(resultArray, propertyKey, fromValue, true)。
- 将 k 设置为 k + 1。
- 返回 resultArray。
23.2.3.33 %TypedArray%.prototype.toSorted ( comparator )
此方法在被调用时执行以下步骤:
- 如果 comparator 不是 undefined 且 IsCallable(comparator) 是 false,抛出 TypeError 异常。
- 令 obj 为 this 值。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 len 为 TypedArrayLength(taRecord)。
- 令 resultArray 为 ? TypedArrayCreateSameType(obj, len)。
- 注:下面的闭包执行数值比较,而不是 23.1.3.34 中使用的字符串比较。
- 令 sortCompare 为一个新的 Abstract Closure,其参数为 (x, y),捕获 comparator,并在被调用时执行以下步骤:
- 返回 ? CompareTypedArrayElements(x, y, comparator)。
- 令 sortedList 为 ? SortIndexedProperties(obj, len, sortCompare, read-through-holes)。
- 令 j 为 0。
- 重复,当 j < len 时,
- 执行 ! Set(resultArray, ! ToString(𝔽(j)), sortedList[j], true)。
- 将 j 设置为 j + 1。
- 返回 resultArray。
23.2.3.34 %TypedArray%.prototype.toString ( )
"toString" 属性的初始值为 %Array.prototype.toString%,定义见 23.1.3.36。
23.2.3.35 %TypedArray%.prototype.values ( )
此方法在被调用时执行以下步骤:
- 令 obj 为 this 值。
- 执行 ? ValidateTypedArray(obj, seq-cst)。
- 返回 CreateArrayIterator(obj, value)。
23.2.3.36 %TypedArray%.prototype.with ( index, value )
此方法在被调用时执行以下步骤:
- 令 obj 为 this 值。
- 令 taRecord 为 ? ValidateTypedArray(obj, seq-cst)。
- 令 len 为 TypedArrayLength(taRecord)。
- 令 relativeIndex 为 ? ToIntegerOrInfinity(index)。
- 如果 relativeIndex ≥ 0,令 actualIndex 为 relativeIndex。
- 否则,令 actualIndex 为 len + relativeIndex。
- 如果 obj.[[ContentType]] 是 bigint,令 numericValue 为 ? ToBigInt(value)。
- 否则,令 numericValue 为 ? ToNumber(value)。
- 如果 IsValidIntegerIndex(obj, 𝔽(actualIndex)) 是 false,抛出 RangeError 异常。
- 令 resultArray 为 ? TypedArrayCreateSameType(obj, len)。
- 令 k 为 0。
- 重复,当 k < len 时,
- 令 propertyKey 为 ! ToString(𝔽(k))。
- 如果 k = actualIndex,令 fromValue 为 numericValue。
- 否则,令 fromValue 为 ! Get(obj, propertyKey)。
- 执行 ! Set(resultArray, propertyKey, fromValue, true)。
- 将 k 设置为 k + 1。
- 返回 resultArray。
23.2.3.37 %TypedArray%.prototype [ %Symbol.iterator% ] ( )
%Symbol.iterator% 属性的初始值为 %TypedArray.prototype.values%,定义见 23.2.3.35。
23.2.3.38 get %TypedArray%.prototype [ %Symbol.toStringTag% ]
%TypedArray%.prototype[%Symbol.toStringTag%] 是一个访问器属性,其 set 访问器函数为 undefined。它的 get 访问器函数在被调用时执行以下步骤:
- 令 obj 为 this 值。
- 如果 obj 不是 Object,返回 undefined。
- 如果 obj 没有 [[TypedArrayName]] 内部槽,返回 undefined。
- 令 name 为 obj.[[TypedArrayName]]。
- 断言:name 是一个 String。
- 返回 name。
此属性具有特性 { [[Enumerable]]: false, [[Configurable]]: true }。
此函数的 "name" 属性的初始值为 "get [Symbol.toStringTag]"。
23.2.4 TypedArray 对象的抽象操作
23.2.4.1 TypedArrayCreateFromConstructor ( constructor, argumentList )
The abstract operation TypedArrayCreateFromConstructor takes arguments constructor (一个构造器,) and argumentList (一个 ECMAScript 语言值 List,) and returns 要么是一个包含 TypedArray 的正常完成,要么是一个抛出完成. 它用于指定使用构造器函数创建一个新的 TypedArray。 It performs the following steps when called:
- 令 newTypedArray 为 ? Construct(constructor, argumentList)。
- 令 taRecord 为 ? ValidateTypedArray(newTypedArray, seq-cst)。
- 断言:newTypedArray 具有 TypedArray 实例的属性 中提到的所有内部槽。
- 如果 argumentList 中的元素数量为 1,且 argumentList[0] 是 Number,则
- 如果 IsTypedArrayOutOfBounds(taRecord) 是 true,抛出 TypeError 异常。
- 令 length 为 TypedArrayLength(taRecord)。
- 如果 length < ℝ(argumentList[0]),抛出 TypeError 异常。
- 返回 newTypedArray。
23.2.4.2 TypedArrayCreateSameType ( exemplar, length )
The abstract operation TypedArrayCreateSameType takes arguments exemplar (一个 TypedArray,) and length (一个非负整数,) and returns 要么是一个包含 TypedArray 的正常完成,要么是一个抛出完成. 它用于指定使用从 exemplar 派生的构造器函数创建一个新的 TypedArray。与可以通过使用 %Symbol.species% 构造自定义 TypedArray 子类的 TypedArraySpeciesCreate 不同,此操作始终使用内置 TypedArray 构造器之一。 It performs the following steps when called:
- 令 constructor 为 Table 70 中与构造器名称 exemplar.[[TypedArrayName]] 关联的内在对象。
- 令 result 为 ? TypedArrayCreateFromConstructor(constructor, « 𝔽(length) »)。
- 断言:result 具有 [[TypedArrayName]] 和 [[ContentType]] 内部槽。
- 断言:result.[[ContentType]] 是 exemplar.[[ContentType]]。
- 返回 result。
23.2.4.3 TypedArraySpeciesCreate ( exemplar, argumentList )
The abstract operation TypedArraySpeciesCreate takes arguments exemplar (一个 TypedArray,) and argumentList (一个 ECMAScript 语言值 List,) and returns 要么是一个包含 TypedArray 的正常完成,要么是一个抛出完成. 它用于指定使用从 exemplar 派生的构造器函数创建一个新的 TypedArray。与可以通过使用 %Symbol.species% 创建非 Array 对象的 ArraySpeciesCreate 不同,此操作强制要求该构造器函数创建一个真正的 TypedArray。 It performs the following steps when called:
- 令 defaultConstructor 为 Table 70 中与构造器名称 exemplar.[[TypedArrayName]] 关联的内在对象。
- 令 constructor 为 ? SpeciesConstructor(exemplar, defaultConstructor)。
- 令 result 为 ? TypedArrayCreateFromConstructor(constructor, argumentList)。
- 如果 result.[[ContentType]] 不是 exemplar.[[ContentType]],抛出 TypeError 异常。
- 返回 result。
23.2.4.4 ValidateTypedArray ( obj, order )
The abstract operation ValidateTypedArray takes arguments obj (一个 ECMAScript 语言值,) and order (seq-cst 或 unordered,) and returns 要么是一个包含 TypedArray With Buffer Witness Record 的正常完成,要么是一个抛出完成. It performs the following steps when called:
- 执行 ? RequireInternalSlot(obj, [[TypedArrayName]])。
- 断言:obj 有 [[ViewedArrayBuffer]] 内部槽。
- 令 taRecord 为 MakeTypedArrayWithBufferWitnessRecord(obj, order)。
- 如果 IsTypedArrayOutOfBounds(taRecord) 是 true,抛出 TypeError 异常。
- 返回 taRecord。
23.2.4.5 TypedArrayElementSize ( obj )
The abstract operation TypedArrayElementSize takes argument obj (一个 TypedArray,) and returns 一个非负整数. It performs the following steps when called:
- 返回 Table 70 中为 obj.[[TypedArrayName]] 指定的 Element Size 值。
23.2.4.6 TypedArrayElementType ( obj )
The abstract operation TypedArrayElementType takes argument obj (一个 TypedArray,) and returns 一个 TypedArray 元素类型. It performs the following steps when called:
- 返回 Table 70 中为 obj.[[TypedArrayName]] 指定的 Element Type 值。
23.2.4.7 CompareTypedArrayElements ( x, y, comparator )
The abstract operation CompareTypedArrayElements takes arguments x (一个 Number 或 BigInt,), y (一个 Number 或 BigInt,), and comparator (一个函数对象或 undefined,) and returns 要么是一个包含 Number 的正常完成,要么是一个 abrupt completion. It performs the following steps when called:
- 断言:x 是 Number 且 y 是 Number,或者 x 是 BigInt 且 y 是 BigInt。
- 如果 comparator 不是 undefined,则
- 令 result 为 ? ToNumber(? Call(comparator, undefined, « x, y »))。
- 如果 result 是 NaN,返回 +0𝔽。
- 返回 result。
- 如果 x 是 NaN 且 y 是 NaN,返回 +0𝔽。
- 如果 x 是 NaN,返回 1𝔽。
- 如果 y 是 NaN,返回 -1𝔽。
- 如果 x < y,返回 -1𝔽。
- 如果 x > y,返回 1𝔽。
- 如果 x 是 -0𝔽 且 y 是 +0𝔽,返回 -1𝔽。
- 如果 x 是 +0𝔽 且 y 是 -0𝔽,返回 1𝔽。
- 返回 +0𝔽。
Note
此操作执行数值比较,而不是
23.1.3.30.2 中使用的字符串比较。