| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 63321ee commit de4ca2c
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -757,13 +757,15 @@ function writableStreamClose(stream) { | |||
| 757 | 757 | return promise; | |
| 758 | 758 | } | |
| 759 | 759 | ||
| 760 | - function writableStreamUpdateBackpressure(stream, backpressure) { | ||
| 761 | - const streamState = stream[kState]; | ||
| 762 | - assert(streamState.state === 'writable'); | ||
| 763 | - assert(!streamState.closeQueuedOrInFlight); | ||
| 764 | - const { | ||
| 765 | - writer, | ||
| 766 | - } = streamState; | ||
| 760 | + // Callers invoke this only in the 'writable' state with no close queued or | ||
| 761 | + // in flight (the two conditions the spec's assertions check), so the | ||
| 762 | + // backpressure value is derived here from the desired size instead of being | ||
| 763 | + // computed and passed in by each caller. | ||
| 764 | + function writableStreamUpdateBackpressure(controller, streamState) { | ||
| 765 | + const controllerState = controller[kState]; | ||
| 766 | + const backpressure = | ||
| 767 | + controllerState.highWaterMark - controllerState.queueTotalSize <= 0; | ||
| 768 | + const writer = streamState.writer; | ||
| 767 | 769 | if (writer !== undefined && streamState.backpressure !== backpressure) { | |
| 768 | 770 | if (backpressure) { | |
| 769 | 771 | // The spec replaces [[readyPromise]] with a fresh pending promise; | |
@@ -1100,9 +1102,7 @@ function writableStreamDefaultControllerWrite(controller, chunk, chunkSize) { | |||
| 1100 | 1102 | const streamState = stream[kState]; | |
| 1101 | 1103 | if (!streamState.closeQueuedOrInFlight && | |
| 1102 | 1104 | streamState.state === 'writable') { | |
| 1103 | - writableStreamUpdateBackpressure( | ||
| 1104 | - stream, | ||
| 1105 | - writableStreamDefaultControllerGetBackpressure(controller)); | ||
| 1105 | + writableStreamUpdateBackpressure(controller, streamState); | ||
| 1106 | 1106 | } | |
| 1107 | 1107 | writableStreamDefaultControllerAdvanceQueueIfNeeded(controller); | |
| 1108 | 1108 | } | |
@@ -1128,9 +1128,7 @@ function writableStreamDefaultControllerProcessWrite(controller, chunk) { | |||
| 1128 | 1128 | dequeueValue(controller); | |
| 1129 | 1129 | if (!streamState.closeQueuedOrInFlight && | |
| 1130 | 1130 | state === 'writable') { | |
| 1131 | - writableStreamUpdateBackpressure( | ||
| 1132 | - stream, | ||
| 1133 | - writableStreamDefaultControllerGetBackpressure(controller)); | ||
| 1131 | + writableStreamUpdateBackpressure(controller, streamState); | ||
| 1134 | 1132 | } | |
| 1135 | 1133 | writableStreamDefaultControllerAdvanceQueueIfNeeded(controller); | |
| 1136 | 1134 | }; | |
@@ -1229,10 +1227,6 @@ function writableStreamDefaultControllerClearAlgorithms(controller) { | |||
| 1229 | 1227 | controller[kState].sizeAlgorithm = undefined; | |
| 1230 | 1228 | } | |
| 1231 | 1229 | ||
| 1232 | - function writableStreamDefaultControllerGetBackpressure(controller) { | ||
| 1233 | - return writableStreamDefaultControllerGetDesiredSize(controller) <= 0; | ||
| 1234 | - } | ||
| 1235 | - | ||
| 1236 | 1230 | function writableStreamDefaultControllerAdvanceQueueIfNeeded(controller) { | |
| 1237 | 1231 | const { | |
| 1238 | 1232 | queue, | |
@@ -1317,9 +1311,7 @@ function setupWritableStreamDefaultController( | |||
| 1317 | 1311 | }; | |
| 1318 | 1312 | stream[kState].controller = controller; | |
| 1319 | 1313 | ||
| 1320 | - writableStreamUpdateBackpressure( | ||
| 1321 | - stream, | ||
| 1322 | - writableStreamDefaultControllerGetBackpressure(controller)); | ||
| 1314 | + writableStreamUpdateBackpressure(controller, stream[kState]); | ||
| 1323 | 1315 | ||
| 1324 | 1316 | const startResult = startAlgorithm(); | |
| 1325 | 1317 | ||
@@ -1402,7 +1394,6 @@ module.exports = { | |||
| 1402 | 1394 | writableStreamDefaultControllerError, | |
| 1403 | 1395 | writableStreamDefaultControllerClose, | |
| 1404 | 1396 | writableStreamDefaultControllerClearAlgorithms, | |
| 1405 | - writableStreamDefaultControllerGetBackpressure, | ||
| 1406 | 1397 | writableStreamDefaultControllerAdvanceQueueIfNeeded, | |
| 1407 | 1398 | setupWritableStreamDefaultControllerFromSink, | |
| 1408 | 1399 | setupWritableStreamDefaultController, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments