From 3c495227bd311f594a7004837b345ec953c17e82 Mon Sep 17 00:00:00 2001 From: Idefix2020 Date: Fri, 1 Jul 2022 18:36:56 +0200 Subject: [PATCH] Better TypedArray type checking Check if the object is an instance of any TypedArray (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray#description) --- src/vs/base/common/types.ts | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/vs/base/common/types.ts b/src/vs/base/common/types.ts index 50ac38cf4075b..3e1cb2a7354c3 100644 --- a/src/vs/base/common/types.ts +++ b/src/vs/base/common/types.ts @@ -47,18 +47,9 @@ export function isObject(obj: unknown): obj is Object { * @returns whether the provided parameter is of type `Buffer` or Uint8Array dervived type */ export function isTypedArray(obj: unknown): obj is Object { + const TypedArray = Object.getPrototypeOf(Uint8Array); return typeof obj === 'object' - && (obj instanceof Uint8Array || - obj instanceof Uint16Array || - obj instanceof Uint32Array || - obj instanceof Float32Array || - obj instanceof Float64Array || - obj instanceof Int8Array || - obj instanceof Int16Array || - obj instanceof Int32Array || - obj instanceof BigInt64Array || - obj instanceof BigUint64Array || - obj instanceof Uint8ClampedArray); + && obj instanceof TypedArray; } /**