Skip to content

Commit b2028cb

Browse files
authored
fix Array#at support/polyfill queried for TypedArrays
1 parent 0992c34 commit b2028cb

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

src/arraylike-at.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const TypedArrayProto: {at?: typeof arrayLikeAt} = Reflect.getPrototypeOf(Int8Array) || {}
1+
const TypedArray = Reflect.getPrototypeOf(Int8Array) as Int8ArrayConstructor|null
22

33
export function arrayLikeAt<T>(this: ArrayLike<T>, i: number): T | void {
44
const l = this.length
@@ -14,21 +14,27 @@ export function isSupported(): boolean {
1414
typeof Array.prototype.at === 'function' &&
1515
'at' in String.prototype &&
1616
typeof String.prototype.at === 'function' &&
17-
'at' in TypedArrayProto &&
18-
typeof TypedArrayProto.at === 'function'
17+
typeof TypedArray === 'function' &&
18+
'at' in TypedArray.prototype &&
19+
typeof TypedArray.prototype.at === 'function'
1920
)
2021
}
2122

2223
/*#__PURE__*/
2324
export function isPolyfilled(): boolean {
24-
return Array.prototype.at === arrayLikeAt && String.prototype.at === arrayLikeAt && TypedArrayProto.at === arrayLikeAt
25+
return (
26+
Array.prototype.at === arrayLikeAt &&
27+
String.prototype.at === arrayLikeAt &&
28+
typeof TypedArray === 'function' &&
29+
TypedArray.prototype.at === arrayLikeAt
30+
)
2531
}
2632

2733
export function apply(): void {
2834
if (!isSupported()) {
2935
const defn = {value: arrayLikeAt, writable: true, configurable: true}
3036
Object.defineProperty(Array.prototype, 'at', defn)
3137
Object.defineProperty(String.prototype, 'at', defn)
32-
Object.defineProperty(TypedArrayProto, 'at', defn)
38+
Object.defineProperty(TypedArray, 'at', defn)
3339
}
3440
}

0 commit comments

Comments
 (0)