summaryrefslogtreecommitdiff
path: root/ext/fetch/26_fetch.js
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2022-01-27 13:36:36 +0100
committerGitHub <noreply@github.com>2022-01-27 13:36:36 +0100
commit884143218fad0e18f7553aaf079d52de703f7601 (patch)
tree9b9e9d30ea647041438ef8fa974b8d4234cabf73 /ext/fetch/26_fetch.js
parentdcf8f144ab0516936bfa4e93357d71f1732d880e (diff)
refactor: update runtime code for primordial checks for "instanceof" (#13497)
Diffstat (limited to 'ext/fetch/26_fetch.js')
-rw-r--r--ext/fetch/26_fetch.js46
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;
}