refactor(cli/web): use isTypedArray method (#6369)

This commit is contained in:
Marcos Casagrande 2020-06-18 20:39:29 +02:00 committed by GitHub
parent 70147ee564
commit 36ad5e4402
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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);