diff options
Diffstat (limited to 'ext/flash/01_http.js')
-rw-r--r-- | ext/flash/01_http.js | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/ext/flash/01_http.js b/ext/flash/01_http.js index 4d0112c5b..fe503ed05 100644 --- a/ext/flash/01_http.js +++ b/ext/flash/01_http.js @@ -31,11 +31,12 @@ const { PromisePrototypeCatch, PromisePrototypeThen, SafePromiseAll, + TypedArrayPrototypeGetByteLength, + TypedArrayPrototypeGetSymbolToStringTag, TypedArrayPrototypeSet, TypedArrayPrototypeSubarray, TypeError, Uint8Array, - Uint8ArrayPrototype, } = primordials; const statusCodes = { @@ -188,9 +189,15 @@ function http1Response( str += body ?? ""; } else { const head = core.encode(str); - const response = new Uint8Array(head.byteLength + bodyLen); + const response = new Uint8Array( + TypedArrayPrototypeGetByteLength(head) + bodyLen, + ); TypedArrayPrototypeSet(response, head, 0); - TypedArrayPrototypeSet(response, body, head.byteLength); + TypedArrayPrototypeSet( + response, + body, + TypedArrayPrototypeGetByteLength(head), + ); return response; } @@ -303,7 +310,7 @@ async function handleResponse( } isStreamingResponseBody = !( typeof respBody === "string" || - ObjectPrototypeIsPrototypeOf(Uint8ArrayPrototype, respBody) + TypedArrayPrototypeGetSymbolToStringTag(respBody) === "Uint8Array" ); } else { if (innerResp.body.streamOrStatic.consumed === true) { @@ -318,7 +325,9 @@ async function handleResponse( const ws = resp[_ws]; if (isStreamingResponseBody === false) { - const length = respBody.byteLength || core.byteLength(respBody); + const length = typeof respBody === "string" + ? core.byteLength(respBody) + : TypedArrayPrototypeGetByteLength(respBody); const responseStr = http1Response( method, innerResp.status ?? 200, @@ -394,8 +403,10 @@ async function handleResponse( innerResp.status ?? 200, innerResp.headerList, null, + // deno-lint-ignore prefer-primordials respBody.byteLength, ), + // deno-lint-ignore prefer-primordials respBody.byteLength, false, respondFast, @@ -722,7 +733,7 @@ function createRequestBodyStream(serverId, token) { token, ); if (!firstRead) return null; - let firstEnqueued = firstRead.byteLength == 0; + let firstEnqueued = TypedArrayPrototypeGetByteLength(firstRead) === 0; return new ReadableStream({ type: "bytes", |