0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 17:34:47 -05:00

fix(ext/fetch): reject immediately on aborted signal (#16190)

Enabled the following test:

edc428e8e2/fetch/api/abort/general.any.js (L185-L201)
This commit is contained in:
Marcos Casagrande 2022-10-08 22:08:47 +02:00 committed by GitHub
parent 1fc1ae0005
commit cc3e2b9b1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 42 deletions

View file

@ -31,6 +31,7 @@
readableStreamClose, readableStreamClose,
readableStreamDisturb, readableStreamDisturb,
readableStreamCollectIntoUint8Array, readableStreamCollectIntoUint8Array,
readableStreamThrowIfErrored,
createProxy, createProxy,
ReadableStreamPrototype, ReadableStreamPrototype,
} = globalThis.__bootstrap.streams; } = globalThis.__bootstrap.streams;
@ -41,7 +42,6 @@
JSONParse, JSONParse,
ObjectDefineProperties, ObjectDefineProperties,
ObjectPrototypeIsPrototypeOf, ObjectPrototypeIsPrototypeOf,
PromiseResolve,
TypedArrayPrototypeSlice, TypedArrayPrototypeSlice,
TypeError, TypeError,
Uint8Array, Uint8Array,
@ -147,6 +147,7 @@
this.streamOrStatic, this.streamOrStatic,
) )
) { ) {
readableStreamThrowIfErrored(this.stream);
return readableStreamCollectIntoUint8Array(this.stream); return readableStreamCollectIntoUint8Array(this.stream);
} else { } else {
this.streamOrStatic.consumed = true; this.streamOrStatic.consumed = true;
@ -222,11 +223,17 @@
* @returns {void} * @returns {void}
*/ */
function mixinBody(prototype, bodySymbol, mimeTypeSymbol) { function mixinBody(prototype, bodySymbol, mimeTypeSymbol) {
function consumeBody(object) { async function consumeBody(object, type) {
if (object[bodySymbol] !== null) { webidl.assertBranded(object, prototype);
return object[bodySymbol].consume();
} const body = object[bodySymbol] !== null
return PromiseResolve(new Uint8Array()); ? await object[bodySymbol].consume()
: new Uint8Array();
const mimeType = type === "Blob" || type === "FormData"
? object[mimeTypeSymbol]
: null;
return packageData(body, type, mimeType);
} }
/** @type {PropertyDescriptorMap} */ /** @type {PropertyDescriptorMap} */
@ -262,10 +269,8 @@
}, },
arrayBuffer: { arrayBuffer: {
/** @returns {Promise<ArrayBuffer>} */ /** @returns {Promise<ArrayBuffer>} */
value: async function arrayBuffer() { value: function arrayBuffer() {
webidl.assertBranded(this, prototype); return consumeBody(this, "ArrayBuffer");
const body = await consumeBody(this);
return packageData(body, "ArrayBuffer");
}, },
writable: true, writable: true,
configurable: true, configurable: true,
@ -273,10 +278,8 @@
}, },
blob: { blob: {
/** @returns {Promise<Blob>} */ /** @returns {Promise<Blob>} */
value: async function blob() { value: function blob() {
webidl.assertBranded(this, prototype); return consumeBody(this, "Blob");
const body = await consumeBody(this);
return packageData(body, "Blob", this[mimeTypeSymbol]);
}, },
writable: true, writable: true,
configurable: true, configurable: true,
@ -284,10 +287,8 @@
}, },
formData: { formData: {
/** @returns {Promise<FormData>} */ /** @returns {Promise<FormData>} */
value: async function formData() { value: function formData() {
webidl.assertBranded(this, prototype); return consumeBody(this, "FormData");
const body = await consumeBody(this);
return packageData(body, "FormData", this[mimeTypeSymbol]);
}, },
writable: true, writable: true,
configurable: true, configurable: true,
@ -295,10 +296,8 @@
}, },
json: { json: {
/** @returns {Promise<any>} */ /** @returns {Promise<any>} */
value: async function json() { value: function json() {
webidl.assertBranded(this, prototype); return consumeBody(this, "JSON");
const body = await consumeBody(this);
return packageData(body, "JSON");
}, },
writable: true, writable: true,
configurable: true, configurable: true,
@ -306,10 +305,8 @@
}, },
text: { text: {
/** @returns {Promise<string>} */ /** @returns {Promise<string>} */
value: async function text() { value: function text() {
webidl.assertBranded(this, prototype); return consumeBody(this, "text");
const body = await consumeBody(this);
return packageData(body, "text");
}, },
writable: true, writable: true,
configurable: true, configurable: true,

View file

@ -6057,6 +6057,7 @@
readableStreamForRidUnrefable, readableStreamForRidUnrefable,
readableStreamForRidUnrefableRef, readableStreamForRidUnrefableRef,
readableStreamForRidUnrefableUnref, readableStreamForRidUnrefableUnref,
readableStreamThrowIfErrored,
getReadableStreamResourceBacking, getReadableStreamResourceBacking,
Deferred, Deferred,
// Exposed in global runtime scope // Exposed in global runtime scope

View file

@ -3209,24 +3209,10 @@
"WorkerGlobalScope interface: calling fetch(RequestInfo, optional RequestInit) on self with too few arguments must throw TypeError" "WorkerGlobalScope interface: calling fetch(RequestInfo, optional RequestInit) on self with too few arguments must throw TypeError"
], ],
"abort": { "abort": {
"general.any.html": [
"response.arrayBuffer() rejects if already aborted",
"response.blob() rejects if already aborted",
"response.formData() rejects if already aborted",
"response.json() rejects if already aborted",
"response.text() rejects if already aborted",
"Call text() twice on aborted response"
],
"general.any.worker.html": [
"response.arrayBuffer() rejects if already aborted",
"response.blob() rejects if already aborted",
"response.formData() rejects if already aborted",
"response.json() rejects if already aborted",
"response.text() rejects if already aborted",
"Call text() twice on aborted response"
],
"request.any.html": true, "request.any.html": true,
"request.any.worker.html": true, "request.any.worker.html": true,
"general.any.html": true,
"general.any.worker.html": true,
"cache.https.any.html": false, "cache.https.any.html": false,
"cache.https.any.worker.html": false "cache.https.any.worker.html": false
} }