diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-02-01 18:06:11 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-01 18:06:11 +0100 |
commit | 8176a4d1663529fb8aeebf7734c4994fa1d583f4 (patch) | |
tree | 94c7d6eb2679e641f59cf78640340f5b7af0022e /ext/fetch/26_fetch.js | |
parent | abf89f8c4675ed78c992fafd6d758bf4bfca8a1a (diff) |
refactor: primordials for instanceof (#13527)
Diffstat (limited to 'ext/fetch/26_fetch.js')
-rw-r--r-- | ext/fetch/26_fetch.js | 46 |
1 files changed, 33 insertions, 13 deletions
diff --git a/ext/fetch/26_fetch.js b/ext/fetch/26_fetch.js index c6fc9197b..0c58bbf97 100644 --- a/ext/fetch/26_fetch.js +++ b/ext/fetch/26_fetch.js @@ -15,7 +15,9 @@ const core = window.Deno.core; const webidl = window.__bootstrap.webidl; const { byteLowerCase } = window.__bootstrap.infra; - const { errorReadableStream } = window.__bootstrap.streams; + const { BlobPrototype } = window.__bootstrap.file; + const { errorReadableStream, ReadableStreamPrototype } = + window.__bootstrap.streams; const { InnerBody, extractBody } = window.__bootstrap.fetchBody; const { toInnerRequest, @@ -32,6 +34,7 @@ ArrayPrototypeSplice, ArrayPrototypeFilter, ArrayPrototypeIncludes, + ObjectPrototypeIsPrototypeOf, Promise, PromisePrototypeThen, PromisePrototypeCatch, @@ -41,6 +44,7 @@ TypedArrayPrototypeSubarray, TypeError, Uint8Array, + Uint8ArrayPrototype, WeakMap, WeakMapPrototypeDelete, WeakMapPrototypeGet, @@ -172,8 +176,16 @@ let reqBody = null; if (req.body !== null) { - if (req.body.streamOrStatic instanceof ReadableStream) { - if (req.body.length === null || req.body.source instanceof Blob) { + if ( + ObjectPrototypeIsPrototypeOf( + ReadableStreamPrototype, + req.body.streamOrStatic, + ) + ) { + if ( + req.body.length === null || + ObjectPrototypeIsPrototypeOf(BlobPrototype, req.body.source) + ) { reqBody = req.body.stream; } else { const reader = req.body.stream.getReader(); @@ -196,14 +208,19 @@ } } - const { requestRid, requestBodyRid, cancelHandleRid } = opFetch({ - method: req.method, - url: req.currentUrl(), - headers: req.headerList, - clientRid: req.clientRid, - hasBody: reqBody !== null, - bodyLength: req.body?.length, - }, reqBody instanceof Uint8Array ? reqBody : null); + const { requestRid, requestBodyRid, cancelHandleRid } = opFetch( + { + method: req.method, + url: req.currentUrl(), + headers: req.headerList, + clientRid: req.clientRid, + hasBody: reqBody !== null, + bodyLength: req.body?.length, + }, + ObjectPrototypeIsPrototypeOf(Uint8ArrayPrototype, reqBody) + ? reqBody + : null, + ); function onAbort() { if (cancelHandleRid !== null) { @@ -216,7 +233,10 @@ terminator[abortSignal.add](onAbort); if (requestBodyRid !== null) { - if (reqBody === null || !(reqBody instanceof ReadableStream)) { + if ( + reqBody === null || + !ObjectPrototypeIsPrototypeOf(ReadableStreamPrototype, reqBody) + ) { throw new TypeError("Unreachable"); } const reader = reqBody.getReader(); @@ -231,7 +251,7 @@ }, ); if (done) break; - if (!(value instanceof Uint8Array)) { + if (!ObjectPrototypeIsPrototypeOf(Uint8ArrayPrototype, value)) { await reader.cancel("value not a Uint8Array"); break; } |