diff options
Diffstat (limited to 'cli/js/web')
-rw-r--r-- | cli/js/web/body.ts | 16 | ||||
-rw-r--r-- | cli/js/web/fetch.ts | 18 |
2 files changed, 20 insertions, 14 deletions
diff --git a/cli/js/web/body.ts b/cli/js/web/body.ts index ed21fa0ec..03c35848a 100644 --- a/cli/js/web/body.ts +++ b/cli/js/web/body.ts @@ -306,7 +306,7 @@ export class Body implements domTypes.Body { return JSON.parse(raw); } - public async arrayBuffer(): Promise<ArrayBuffer> { + public arrayBuffer(): Promise<ArrayBuffer> { if ( this._bodySource instanceof Int8Array || this._bodySource instanceof Int16Array || @@ -318,20 +318,24 @@ export class Body implements domTypes.Body { this._bodySource instanceof Float32Array || this._bodySource instanceof Float64Array ) { - return this._bodySource.buffer as ArrayBuffer; + return Promise.resolve(this._bodySource.buffer as ArrayBuffer); } else if (this._bodySource instanceof ArrayBuffer) { - return this._bodySource; + return Promise.resolve(this._bodySource); } else if (typeof this._bodySource === "string") { const enc = new TextEncoder(); - return enc.encode(this._bodySource).buffer as ArrayBuffer; + return Promise.resolve( + enc.encode(this._bodySource).buffer as ArrayBuffer + ); } else if (this._bodySource instanceof ReadableStream) { // @ts-ignore return bufferFromStream(this._bodySource.getReader()); } else if (this._bodySource instanceof FormData) { const enc = new TextEncoder(); - return enc.encode(this._bodySource.toString()).buffer as ArrayBuffer; + return Promise.resolve( + enc.encode(this._bodySource.toString()).buffer as ArrayBuffer + ); } else if (!this._bodySource) { - return new ArrayBuffer(0); + return Promise.resolve(new ArrayBuffer(0)); } throw new Error( `Body type not yet implemented: ${this._bodySource.constructor.name}` diff --git a/cli/js/web/fetch.ts b/cli/js/web/fetch.ts index 7ab68d2e4..62e5d7928 100644 --- a/cli/js/web/fetch.ts +++ b/cli/js/web/fetch.ts @@ -60,6 +60,7 @@ class Body implements domTypes.Body, domTypes.ReadableStream, io.ReadCloser { return this._data; } + // eslint-disable-next-line require-await async arrayBuffer(): Promise<ArrayBuffer> { // If we've already bufferred the response, just return it. if (this._data != null) { @@ -223,11 +224,12 @@ class Body implements domTypes.Body, domTypes.ReadableStream, io.ReadCloser { return read(this.rid, p); } - close(): void { + close(): Promise<void> { close(this.rid); + return Promise.resolve(); } - async cancel(): Promise<void> { + cancel(): Promise<void> { return notImplemented(); } @@ -346,7 +348,7 @@ export class Response implements domTypes.Response { return false; } - async arrayBuffer(): Promise<ArrayBuffer> { + arrayBuffer(): Promise<ArrayBuffer> { /* You have to do the null check here and not in the function because * otherwise TS complains about this.body potentially being null */ if (this.bodyViewable() || this.body == null) { @@ -355,14 +357,14 @@ export class Response implements domTypes.Response { return this.body.arrayBuffer(); } - async blob(): Promise<domTypes.Blob> { + blob(): Promise<domTypes.Blob> { if (this.bodyViewable() || this.body == null) { return Promise.reject(new Error("Response body is null")); } return this.body.blob(); } - async formData(): Promise<domTypes.FormData> { + formData(): Promise<domTypes.FormData> { if (this.bodyViewable() || this.body == null) { return Promise.reject(new Error("Response body is null")); } @@ -370,14 +372,14 @@ export class Response implements domTypes.Response { } // eslint-disable-next-line @typescript-eslint/no-explicit-any - async json(): Promise<any> { + json(): Promise<any> { if (this.bodyViewable() || this.body == null) { return Promise.reject(new Error("Response body is null")); } return this.body.json(); } - async text(): Promise<string> { + text(): Promise<string> { if (this.bodyViewable() || this.body == null) { return Promise.reject(new Error("Response body is null")); } @@ -437,7 +439,7 @@ export class Response implements domTypes.Response { } } -async function sendFetchReq( +function sendFetchReq( url: string, method: string | null, headers: domTypes.Headers | null, |