diff options
author | Marcos Casagrande <marcoscvp90@gmail.com> | 2020-06-18 20:39:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-18 14:39:29 -0400 |
commit | 36ad5e44020a8bd48546e5a8bdb7db9c2f40dc52 (patch) | |
tree | a0c9300fd61afaeb91c21e0b96856973fcb78c97 /cli/js | |
parent | 70147ee56418c3d67a29070c01746a44d353e855 (diff) |
refactor(cli/web): use isTypedArray method (#6369)
Diffstat (limited to 'cli/js')
-rw-r--r-- | cli/js/web/body.ts | 30 |
1 files changed, 7 insertions, 23 deletions
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<ArrayBuffer> { - 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); |