diff options
author | Luca Casonato <hello@lcas.dev> | 2022-09-30 07:54:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-30 07:54:12 +0200 |
commit | 20c7300412bdb487fc758577d6256bbcf96efd12 (patch) | |
tree | 2dcd218a6095a2ad143fb27e304391b5fe64cf27 /ext/web/06_streams.js | |
parent | 38f544538b337074cbce317e67859a69bb23684c (diff) |
refactor(ext/http): remove op_http_read (#16096)
We can use Resource::read_return & op_read instead. This allows HTTP
request bodies to participate in FastStream.
To make this work, `readableStreamForRid` required a change to allow non
auto-closing resources to be handled. This required some minor changes
in our FastStream paths in ext/http and ext/flash.
Diffstat (limited to 'ext/web/06_streams.js')
-rw-r--r-- | ext/web/06_streams.js | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/ext/web/06_streams.js b/ext/web/06_streams.js index cbf781b53..412c58c3c 100644 --- a/ext/web/06_streams.js +++ b/ext/web/06_streams.js @@ -654,11 +654,12 @@ * read directly from the underlying resource if they so choose (FastStream). * * @param {number} rid The resource ID to read from. + * @param {boolean=} autoClose If the resource should be auto-closed when the stream closes. Defaults to true. * @returns {ReadableStream<Uint8Array>} */ - function readableStreamForRid(rid) { + function readableStreamForRid(rid, autoClose = true) { const stream = webidl.createBranded(ReadableStream); - stream[_maybeRid] = rid; + stream[_resourceBacking] = { rid, autoClose }; const underlyingSource = { type: "bytes", async pull(controller) { @@ -666,7 +667,7 @@ try { const bytesRead = await core.read(rid, v); if (bytesRead === 0) { - core.tryClose(rid); + if (autoClose) core.tryClose(rid); controller.close(); controller.byobRequest.respond(0); } else { @@ -674,11 +675,11 @@ } } catch (e) { controller.error(e); - core.tryClose(rid); + if (autoClose) core.tryClose(rid); } }, cancel() { - core.tryClose(rid); + if (autoClose) core.tryClose(rid); }, autoAllocateChunkSize: DEFAULT_CHUNK_SIZE, }; @@ -761,8 +762,8 @@ } } - function getReadableStreamRid(stream) { - return stream[_maybeRid]; + function getReadableStreamResourceBacking(stream) { + return stream[_resourceBacking]; } /** @@ -4424,7 +4425,7 @@ WeakMapPrototypeSet(countSizeFunctionWeakMap, globalObject, size); } - const _maybeRid = Symbol("[[maybeRid]]"); + const _resourceBacking = Symbol("[[resourceBacking]]"); /** @template R */ class ReadableStream { /** @type {ReadableStreamDefaultController | ReadableByteStreamController} */ @@ -4439,8 +4440,8 @@ [_state]; /** @type {any} */ [_storedError]; - /** @type {number | null} */ - [_maybeRid] = null; + /** @type {{ rid: number, autoClose: boolean } | null} */ + [_resourceBacking] = null; /** * @param {UnderlyingSource<R>=} underlyingSource @@ -5986,7 +5987,7 @@ readableStreamForRidUnrefable, readableStreamForRidUnrefableRef, readableStreamForRidUnrefableUnref, - getReadableStreamRid, + getReadableStreamResourceBacking, Deferred, // Exposed in global runtime scope ByteLengthQueuingStrategy, |