mirror of
https://github.com/denoland/deno.git
synced 2025-08-04 02:48:24 +00:00
refactor: primordials for instanceof (#13527)
This commit is contained in:
parent
abf89f8c46
commit
8176a4d166
41 changed files with 1030 additions and 660 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue