From 7d14024a9aa4875186e68ff0932eb4189d4cec4f Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Fri, 20 Dec 2024 14:37:36 +0100 Subject: [PATCH 1/2] Editorial: small cleanup after #1326 --- index.bs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/index.bs b/index.bs index 03cc3787..d296f51f 100644 --- a/index.bs +++ b/index.bs @@ -3352,8 +3352,7 @@ The following abstract operations support the implementation of the ! [$ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue$](|controller|). 1. [=list/For each=] |filledPullInto| of |filledPullIntos|, 1. Perform ! - [$ReadableByteStreamControllerCommitPullIntoDescriptor$](|controller|.[=ReadableByteStreamController/[[stream]]=], - |filledPullInto|). + [$ReadableByteStreamControllerCommitPullIntoDescriptor$](|stream|, |filledPullInto|). 1. Otherwise, 1. Assert: ! [$IsReadableStreamLocked$](|stream|) is false. 1. Perform ! [$ReadableByteStreamControllerEnqueueChunkToQueue$](|controller|, @@ -3458,18 +3457,18 @@ The following abstract operations support the implementation of the queue entry/byte length=]). 1. Let |destStart| be |pullIntoDescriptor|'s [=pull-into descriptor/byte offset=] + |pullIntoDescriptor|'s [=pull-into descriptor/bytes filled=]. - 1. Assert: ! [$CanCopyDataBlockBytes$](|pullIntoDescriptor|'s [=pull-into descriptor/buffer=], - |destStart|, |headOfQueue|'s [=readable byte stream queue entry/buffer=], + 1. Let |descriptorBuffer| be |pullIntoDescriptor|'s [=pull-into descriptor/buffer=]. + 1. Let |queueBuffer| be |headOfQueue|'s [=readable byte stream queue entry/buffer=]. + 1. Assert: ! [$CanCopyDataBlockBytes$](|descriptorBuffer|, |destStart|, |queueBuffer|, |headOfQueue|'s [=readable byte stream queue entry/byte offset=], |bytesToCopy|) is true.

If this assertion were to fail (due to a bug in this specification or its implementation), then the next step may read from or write to potentially invalid memory. The user agent should always check this assertion, and stop in an [=implementation-defined=] manner if it fails (e.g. by crashing the process, or by erroring the stream). - 1. Perform ! [$CopyDataBlockBytes$](|pullIntoDescriptor|'s [=pull-into - descriptor/buffer=].\[[ArrayBufferData]], |destStart|, - |headOfQueue|'s [=readable byte stream queue entry/buffer=].\[[ArrayBufferData]], - |headOfQueue|'s [=readable byte stream queue entry/byte offset=], |bytesToCopy|). + 1. Perform ! [$CopyDataBlockBytes$](|descriptorBuffer|.\[[ArrayBufferData]], |destStart|, + |queueBuffer|.\[[ArrayBufferData]], |headOfQueue|'s [=readable byte stream queue entry/byte + offset=], |bytesToCopy|). 1. If |headOfQueue|'s [=readable byte stream queue entry/byte length=] is |bytesToCopy|, 1. [=list/Remove=] |queue|[0]. 1. Otherwise, @@ -3716,12 +3715,11 @@ The following abstract operations support the implementation of the 1. Let |stream| be |controller|.[=ReadableByteStreamController/[[stream]]=]. 1. If ! [$ReadableStreamHasBYOBReader$](|stream|) is true, 1. Let |filledPullIntos| be a new empty [=list=]. - 1. Let |i| be 0. - 1. [=While=] |i| < ! [$ReadableStreamGetNumReadIntoRequests$](|stream|), + 1. [=While=] |filledPullIntos|'s [=list/size=] < ! + [$ReadableStreamGetNumReadIntoRequests$](|stream|), 1. Let |pullIntoDescriptor| be ! [$ReadableByteStreamControllerShiftPendingPullInto$](|controller|). 1. [=list/Append=] |pullIntoDescriptor| to |filledPullIntos|. - 1. Set |i| to |i| + 1. 1. [=list/For each=] |filledPullInto| of |filledPullIntos|, 1. Perform ! [$ReadableByteStreamControllerCommitPullIntoDescriptor$](|stream|, |filledPullInto|). From d221af03454cad65167313d37e67c736856f81bb Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Sun, 22 Dec 2024 12:48:58 +0100 Subject: [PATCH 2/2] feedback --- index.bs | 6 +++--- .../lib/abstract-ops/readable-streams.js | 13 +++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/index.bs b/index.bs index d296f51f..535dc01f 100644 --- a/index.bs +++ b/index.bs @@ -3459,16 +3459,16 @@ The following abstract operations support the implementation of the |pullIntoDescriptor|'s [=pull-into descriptor/bytes filled=]. 1. Let |descriptorBuffer| be |pullIntoDescriptor|'s [=pull-into descriptor/buffer=]. 1. Let |queueBuffer| be |headOfQueue|'s [=readable byte stream queue entry/buffer=]. + 1. Let |queueByteOffset| be |headOfQueue|'s [=readable byte stream queue entry/byte offset=]. 1. Assert: ! [$CanCopyDataBlockBytes$](|descriptorBuffer|, |destStart|, |queueBuffer|, - |headOfQueue|'s [=readable byte stream queue entry/byte offset=], |bytesToCopy|) is true. + |queueByteOffset|, |bytesToCopy|) is true.

If this assertion were to fail (due to a bug in this specification or its implementation), then the next step may read from or write to potentially invalid memory. The user agent should always check this assertion, and stop in an [=implementation-defined=] manner if it fails (e.g. by crashing the process, or by erroring the stream). 1. Perform ! [$CopyDataBlockBytes$](|descriptorBuffer|.\[[ArrayBufferData]], |destStart|, - |queueBuffer|.\[[ArrayBufferData]], |headOfQueue|'s [=readable byte stream queue entry/byte - offset=], |bytesToCopy|). + |queueBuffer|.\[[ArrayBufferData]], |queueByteOffset|, |bytesToCopy|). 1. If |headOfQueue|'s [=readable byte stream queue entry/byte length=] is |bytesToCopy|, 1. [=list/Remove=] |queue|[0]. 1. Otherwise, diff --git a/reference-implementation/lib/abstract-ops/readable-streams.js b/reference-implementation/lib/abstract-ops/readable-streams.js index 6b8ba803..cbbb3140 100644 --- a/reference-implementation/lib/abstract-ops/readable-streams.js +++ b/reference-implementation/lib/abstract-ops/readable-streams.js @@ -1362,7 +1362,7 @@ function ReadableByteStreamControllerEnqueue(controller, chunk) { ReadableByteStreamControllerEnqueueChunkToQueue(controller, transferredBuffer, byteOffset, byteLength); const filledPullIntos = ReadableByteStreamControllerProcessPullIntoDescriptorsUsingQueue(controller); for (const filledPullInto of filledPullIntos) { - ReadableByteStreamControllerCommitPullIntoDescriptor(controller._stream, filledPullInto); + ReadableByteStreamControllerCommitPullIntoDescriptor(stream, filledPullInto); } } else { assert(IsReadableStreamLocked(stream) === false); @@ -1448,9 +1448,12 @@ function ReadableByteStreamControllerFillPullIntoDescriptorFromQueue(controller, const destStart = pullIntoDescriptor.byteOffset + pullIntoDescriptor.bytesFilled; - assert(CanCopyDataBlockBytes(pullIntoDescriptor.buffer, destStart, headOfQueue.buffer, headOfQueue.byteOffset, + const descriptorBuffer = pullIntoDescriptor.buffer; + const queueBuffer = headOfQueue.buffer; + const queueByteOffset = headOfQueue.byteOffset; + assert(CanCopyDataBlockBytes(descriptorBuffer, destStart, queueBuffer, queueByteOffset, bytesToCopy)); - CopyDataBlockBytes(pullIntoDescriptor.buffer, destStart, headOfQueue.buffer, headOfQueue.byteOffset, bytesToCopy); + CopyDataBlockBytes(descriptorBuffer, destStart, queueBuffer, queueByteOffset, bytesToCopy); if (headOfQueue.byteLength === bytesToCopy) { queue.shift(); @@ -1680,11 +1683,9 @@ function ReadableByteStreamControllerRespondInClosedState(controller, firstDescr const stream = controller._stream; if (ReadableStreamHasBYOBReader(stream) === true) { const filledPullIntos = []; - let i = 0; - while (i < ReadableStreamGetNumReadIntoRequests(stream)) { + while (filledPullIntos.length < ReadableStreamGetNumReadIntoRequests(stream)) { const pullIntoDescriptor = ReadableByteStreamControllerShiftPendingPullInto(controller); filledPullIntos.push(pullIntoDescriptor); - ++i; } for (const filledPullInto of filledPullIntos) { ReadableByteStreamControllerCommitPullIntoDescriptor(stream, filledPullInto);