From 36ad5e44020a8bd48546e5a8bdb7db9c2f40dc52 Mon Sep 17 00:00:00 2001 From: Marcos Casagrande Date: Thu, 18 Jun 2020 20:39:29 +0200 Subject: refactor(cli/web): use isTypedArray method (#6369) --- cli/js/web/body.ts | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) (limited to 'cli/js/web') diff --git a/cli/js/web/body.ts b/cli/js/web/body.ts index 672b7de5a..6e376de37 100644 --- a/cli/js/web/body.ts +++ b/cli/js/web/body.ts @@ -3,7 +3,11 @@ import * as encoding from "./text_encoding.ts"; import * as domTypes from "./dom_types.d.ts"; import { ReadableStreamImpl } from "./streams/readable_stream.ts"; import { isReadableStreamDisturbed } from "./streams/internals.ts"; -import { getHeaderValueParams, hasHeaderValueOf } from "./util.ts"; +import { + getHeaderValueParams, + hasHeaderValueOf, + isTypedArray, +} from "./util.ts"; import { MultipartParser } from "./fetch/multipart.ts"; // only namespace imports work for now, plucking out what we need @@ -11,17 +15,7 @@ const { TextEncoder, TextDecoder } = encoding; const DenoBlob = blob.DenoBlob; function validateBodyType(owner: Body, bodySource: BodyInit | null): boolean { - if ( - bodySource instanceof Int8Array || - bodySource instanceof Int16Array || - bodySource instanceof Int32Array || - bodySource instanceof Uint8Array || - bodySource instanceof Uint16Array || - bodySource instanceof Uint32Array || - bodySource instanceof Uint8ClampedArray || - bodySource instanceof Float32Array || - bodySource instanceof Float64Array - ) { + if (isTypedArray(bodySource)) { return true; } else if (bodySource instanceof ArrayBuffer) { return true; @@ -188,17 +182,7 @@ export class Body implements domTypes.Body { } public arrayBuffer(): Promise { - if ( - this._bodySource instanceof Int8Array || - this._bodySource instanceof Int16Array || - this._bodySource instanceof Int32Array || - this._bodySource instanceof Uint8Array || - this._bodySource instanceof Uint16Array || - this._bodySource instanceof Uint32Array || - this._bodySource instanceof Uint8ClampedArray || - this._bodySource instanceof Float32Array || - this._bodySource instanceof Float64Array - ) { + if (isTypedArray(this._bodySource)) { return Promise.resolve(this._bodySource.buffer as ArrayBuffer); } else if (this._bodySource instanceof ArrayBuffer) { return Promise.resolve(this._bodySource); -- cgit v1.2.3