@@ -2647,13 +2647,22 @@ function readableByteStreamControllerEnqueue(controller, chunk) {
2647
2647
) ;
2648
2648
}
2649
2649
2650
- firstPendingPullInto . buffer =
2651
- transferArrayBuffer ( firstPendingPullInto . buffer ) ;
2652
- }
2650
+ readableByteStreamControllerInvalidateBYOBRequest ( controller ) ;
2653
2651
2654
- readableByteStreamControllerInvalidateBYOBRequest ( controller ) ;
2652
+ firstPendingPullInto . buffer = transferArrayBuffer (
2653
+ firstPendingPullInto . buffer
2654
+ ) ;
2655
+
2656
+ if ( firstPendingPullInto . type === 'none' ) {
2657
+ readableByteStreamControllerEnqueueDetachedPullIntoToQueue (
2658
+ controller ,
2659
+ firstPendingPullInto
2660
+ ) ;
2661
+ }
2662
+ }
2655
2663
2656
2664
if ( readableStreamHasDefaultReader ( stream ) ) {
2665
+ readableByteStreamControllerProcessReadRequestsUsingQueue ( controller ) ;
2657
2666
if ( ! readableStreamGetNumReadRequests ( stream ) ) {
2658
2667
readableByteStreamControllerEnqueueChunkToQueue (
2659
2668
controller ,
@@ -2662,6 +2671,10 @@ function readableByteStreamControllerEnqueue(controller, chunk) {
2662
2671
byteLength ) ;
2663
2672
} else {
2664
2673
assert ( ! queue . length ) ;
2674
+ if ( pendingPullIntos . length ) {
2675
+ assert ( pendingPullIntos [ 0 ] . type === 'default' ) ;
2676
+ readableByteStreamControllerShiftPendingPullInto ( controller ) ;
2677
+ }
2665
2678
const transferredView =
2666
2679
new Uint8Array ( transferredBuffer , byteOffset , byteLength ) ;
2667
2680
readableStreamFulfillReadRequest ( stream , transferredView , false ) ;
@@ -2984,25 +2997,56 @@ function readableByteStreamControllerCancelSteps(controller, reason) {
2984
2997
return result ;
2985
2998
}
2986
2999
3000
+ function readableByteStreamControllerFillReadRequestFromQueue ( controller , readRequest ) {
3001
+ const {
3002
+ queue,
3003
+ queueTotalSize,
3004
+ } = controller [ kState ] ;
3005
+ assert ( queueTotalSize > 0 ) ;
3006
+ const {
3007
+ buffer,
3008
+ byteOffset,
3009
+ byteLength,
3010
+ } = ArrayPrototypeShift ( queue ) ;
3011
+
3012
+ controller [ kState ] . queueTotalSize -= byteLength ;
3013
+ readableByteStreamControllerHandleQueueDrain ( controller ) ;
3014
+ const view = new Uint8Array ( buffer , byteOffset , byteLength ) ;
3015
+ readRequest [ kChunk ] ( view ) ;
3016
+ }
3017
+
3018
+ function readableByteStreamControllerProcessReadRequestsUsingQueue ( controller ) {
3019
+ const {
3020
+ stream,
3021
+ queueTotalSize,
3022
+ } = controller [ kState ] ;
3023
+ const { reader } = stream [ kState ] ;
3024
+ assert ( isReadableStreamDefaultReader ( reader ) ) ;
3025
+
3026
+ while ( reader [ kState ] . readRequests . length > 0 ) {
3027
+ if ( queueTotalSize === 0 ) {
3028
+ return ;
3029
+ }
3030
+ readableByteStreamControllerFillReadRequestFromQueue (
3031
+ controller ,
3032
+ ArrayPrototypeShift ( reader [ kState ] . readRequests ) ,
3033
+ ) ;
3034
+ }
3035
+ }
3036
+
2987
3037
function readableByteStreamControllerPullSteps ( controller , readRequest ) {
2988
3038
const {
2989
3039
pendingPullIntos,
2990
- queue,
2991
3040
queueTotalSize,
2992
3041
stream,
2993
3042
} = controller [ kState ] ;
2994
3043
assert ( readableStreamHasDefaultReader ( stream ) ) ;
2995
3044
if ( queueTotalSize ) {
2996
3045
assert ( ! readableStreamGetNumReadRequests ( stream ) ) ;
2997
- const {
2998
- buffer,
2999
- byteOffset,
3000
- byteLength,
3001
- } = ArrayPrototypeShift ( queue ) ;
3002
- controller [ kState ] . queueTotalSize -= byteLength ;
3003
- readableByteStreamControllerHandleQueueDrain ( controller ) ;
3004
- const view = new Uint8Array ( buffer , byteOffset , byteLength ) ;
3005
- readRequest [ kChunk ] ( view ) ;
3046
+ readableByteStreamControllerFillReadRequestFromQueue (
3047
+ controller ,
3048
+ readRequest
3049
+ ) ;
3006
3050
return ;
3007
3051
}
3008
3052
const {
0 commit comments