| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -431,7 +431,7 @@ function readableAddChunkUnshiftObjectMode(stream, state, chunk) { | |||
| 431 | 431 | function readableAddChunkUnshiftValue(stream, state, chunk) { | |
| 432 | 432 | if ((state[kState] & kEndEmitted) !== 0) | |
| 433 | 433 | errorOrDestroy(stream, new ERR_STREAM_UNSHIFT_AFTER_END_EVENT()); | |
| 434 | - else if (state.destroyed || state.errored) | ||
| 434 | + else if ((state[kState] & (kDestroyed | kErrored)) !== 0) | ||
| 435 | 435 | return false; | |
| 436 | 436 | else | |
| 437 | 437 | addChunk(stream, state, chunk, true); | |
@@ -608,7 +608,7 @@ function computeNewHighWaterMark(n) { | |||
| 608 | 608 | // This function is designed to be inlinable, so please take care when making | |
| 609 | 609 | // changes to the function body. | |
| 610 | 610 | function howMuchToRead(n, state) { | |
| 611 | - if (n <= 0 || (state.length === 0 && state.ended)) | ||
| 611 | + if (n <= 0 || (state.length === 0 && (state[kState] & kEnded) !== 0)) | ||
| 612 | 612 | return 0; | |
| 613 | 613 | if ((state[kState] & kObjectMode) !== 0) | |
| 614 | 614 | return 1; | |
@@ -652,7 +652,7 @@ Readable.prototype.read = function(n) { | |||
| 652 | 652 | state.length >= state.highWaterMark : | |
| 653 | 653 | state.length > 0) || | |
| 654 | 654 | (state[kState] & kEnded) !== 0)) { | |
| 655 | - debug('read: emitReadable', state.length, (state[kState] & kEnded) !== 0); | ||
| 655 | + debug('read: emitReadable'); | ||
| 656 | 656 | if (state.length === 0 && (state[kState] & kEnded) !== 0) | |
| 657 | 657 | endReadable(this); | |
| 658 | 658 | else | |
@@ -810,7 +810,7 @@ function emitReadable(stream) { | |||
| 810 | 810 | function emitReadable_(stream) { | |
| 811 | 811 | const state = stream._readableState; | |
| 812 | 812 | debug('emitReadable_'); | |
| 813 | - if ((state[kState] & (kDestroyed | kErrored)) === 0 && (state.length || state.ended)) { | ||
| 813 | + if ((state[kState] & (kDestroyed | kErrored)) === 0 && (state.length || (state[kState] & kEnded) !== 0)) { | ||
| 814 | 814 | stream.emit('readable'); | |
| 815 | 815 | state[kState] &= ~kEmittedReadable; | |
| 816 | 816 | } | |
@@ -891,7 +891,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) { | |||
| 891 | 891 | const state = this._readableState; | |
| 892 | 892 | ||
| 893 | 893 | if (state.pipes.length === 1) { | |
| 894 | - if (!state.multiAwaitDrain) { | ||
| 894 | + if ((state[kState] & kMultiAwaitDrain) === 0) { | ||
| 895 | 895 | state[kState] |= kMultiAwaitDrain; | |
| 896 | 896 | state.awaitDrainWriters = new SafeSet( | |
| 897 | 897 | state.awaitDrainWriters ? [state.awaitDrainWriters] : [], | |
@@ -907,7 +907,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) { | |||
| 907 | 907 | dest !== process.stderr; | |
| 908 | 908 | ||
| 909 | 909 | const endFn = doEnd ? onend : unpipe; | |
| 910 | - if (state.endEmitted) | ||
| 910 | + if ((state[kState] & kEndEmitted) !== 0) | ||
| 911 | 911 | process.nextTick(endFn); | |
| 912 | 912 | else | |
| 913 | 913 | src.once('end', endFn); | |
@@ -966,7 +966,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) { | |||
| 966 | 966 | if (state.pipes.length === 1 && state.pipes[0] === dest) { | |
| 967 | 967 | debug('false write response, pause', 0); | |
| 968 | 968 | state.awaitDrainWriters = dest; | |
| 969 | - state.multiAwaitDrain = false; | ||
| 969 | + state[kState] &= ~kMultiAwaitDrain; | ||
| 970 | 970 | } else if (state.pipes.length > 1 && state.pipes.includes(dest)) { | |
| 971 | 971 | debug('false write response, pause', state.awaitDrainWriters.size); | |
| 972 | 972 | state.awaitDrainWriters.add(dest); | |
@@ -1038,7 +1038,7 @@ Readable.prototype.pipe = function(dest, pipeOpts) { | |||
| 1038 | 1038 | ||
| 1039 | 1039 | if (dest.writableNeedDrain === true) { | |
| 1040 | 1040 | pause(); | |
| 1041 | - } else if (!state.flowing) { | ||
| 1041 | + } else if ((state[kState] & kFlowing) === 0) { | ||
| 1042 | 1042 | debug('pipe resume'); | |
| 1043 | 1043 | src.resume(); | |
| 1044 | 1044 | } | |
@@ -1056,7 +1056,7 @@ function pipeOnDrain(src, dest) { | |||
| 1056 | 1056 | if (state.awaitDrainWriters === dest) { | |
| 1057 | 1057 | debug('pipeOnDrain', 1); | |
| 1058 | 1058 | state.awaitDrainWriters = null; | |
| 1059 | - } else if (state.multiAwaitDrain) { | ||
| 1059 | + } else if ((state[kState] & kMultiAwaitDrain) !== 0) { | ||
| 1060 | 1060 | debug('pipeOnDrain', state.awaitDrainWriters.size); | |
| 1061 | 1061 | state.awaitDrainWriters.delete(dest); | |
| 1062 | 1062 | } | |
@@ -1111,20 +1111,20 @@ Readable.prototype.on = function(ev, fn) { | |||
| 1111 | 1111 | if (ev === 'data') { | |
| 1112 | 1112 | // Update readableListening so that resume() may be a no-op | |
| 1113 | 1113 | // a few lines down. This is needed to support once('readable'). | |
| 1114 | - state.readableListening = this.listenerCount('readable') > 0; | ||
| 1114 | + state[kState] |= this.listenerCount('readable') > 0 ? kReadableListening : 0; | ||
| 1115 | 1115 | ||
| 1116 | 1116 | // Try start flowing on next tick if stream isn't explicitly paused. | |
| 1117 | - if (state.flowing !== false) | ||
| 1117 | + if ((state[kState] & (kHasFlowing | kFlowing)) !== kHasFlowing) { | ||
| 1118 | 1118 | this.resume(); | |
| 1119 | + } | ||
| 1119 | 1120 | } else if (ev === 'readable') { | |
| 1120 | - if (!state.endEmitted && !state.readableListening) { | ||
| 1121 | - state.readableListening = state.needReadable = true; | ||
| 1122 | - state.flowing = false; | ||
| 1123 | - state.emittedReadable = false; | ||
| 1124 | - debug('on readable', state.length, state.reading); | ||
| 1121 | + if ((state[kState] & (kEndEmitted | kReadableListening)) === 0) { | ||
| 1122 | + state[kState] |= kReadableListening | kNeedReadable | kHasFlowing; | ||
| 1123 | + state[kState] &= ~(kFlowing | kEmittedReadable); | ||
| 1124 | + debug('on readable'); | ||
| 1125 | 1125 | if (state.length) { | |
| 1126 | 1126 | emitReadable(this); | |
| 1127 | - } else if (!state.reading) { | ||
| 1127 | + } else if ((state[kState] & kReading) === 0) { | ||
| 1128 | 1128 | process.nextTick(nReadingNextTick, this); | |
| 1129 | 1129 | } | |
| 1130 | 1130 | } | |
@@ -1171,7 +1171,12 @@ Readable.prototype.removeAllListeners = function(ev) { | |||
| 1171 | 1171 | ||
| 1172 | 1172 | function updateReadableListening(self) { | |
| 1173 | 1173 | const state = self._readableState; | |
| 1174 | - state.readableListening = self.listenerCount('readable') > 0; | ||
| 1174 | + | ||
| 1175 | + if (self.listenerCount('readable') > 0) { | ||
| 1176 | + state[kState] |= kReadableListening; | ||
| 1177 | + } else { | ||
| 1178 | + state[kState] &= ~kReadableListening; | ||
| 1179 | + } | ||
| 1175 | 1180 | ||
| 1176 | 1181 | if ((state[kState] & (kHasPaused | kPaused | kResumeScheduled)) === (kHasPaused | kResumeScheduled)) { | |
| 1177 | 1182 | // Flowing needs to be set to true now, otherwise | |
@@ -1201,7 +1206,7 @@ Readable.prototype.resume = function() { | |||
| 1201 | 1206 | // for readable, but we still have to call | |
| 1202 | 1207 | // resume(). | |
| 1203 | 1208 | state[kState] |= kHasFlowing; | |
| 1204 | - if (!state.readableListening) { | ||
| 1209 | + if ((state[kState] & kReadableListening) === 0) { | ||
| 1205 | 1210 | state[kState] |= kFlowing; | |
| 1206 | 1211 | } else { | |
| 1207 | 1212 | state[kState] &= ~kFlowing; | |
@@ -1214,8 +1219,8 @@ Readable.prototype.resume = function() { | |||
| 1214 | 1219 | }; | |
| 1215 | 1220 | ||
| 1216 | 1221 | function resume(stream, state) { | |
| 1217 | - if (!state.resumeScheduled) { | ||
| 1218 | - state.resumeScheduled = true; | ||
| 1222 | + if ((state[kState] & kResumeScheduled) === 0) { | ||
| 1223 | + state[kState] |= kResumeScheduled; | ||
| 1219 | 1224 | process.nextTick(resume_, stream, state); | |
| 1220 | 1225 | } | |
| 1221 | 1226 | } | |
@@ -1236,7 +1241,7 @@ function resume_(stream, state) { | |||
| 1236 | 1241 | Readable.prototype.pause = function() { | |
| 1237 | 1242 | const state = this._readableState; | |
| 1238 | 1243 | debug('call pause'); | |
| 1239 | - if (state.flowing !== false) { | ||
| 1244 | + if ((state[kState] & (kHasFlowing | kFlowing)) !== kHasFlowing) { | ||
| 1240 | 1245 | debug('pause'); | |
| 1241 | 1246 | state[kState] |= kHasFlowing; | |
| 1242 | 1247 | state[kState] &= ~kFlowing; | |
@@ -1651,20 +1656,19 @@ function fromList(n, state) { | |||
| 1651 | 1656 | function endReadable(stream) { | |
| 1652 | 1657 | const state = stream._readableState; | |
| 1653 | 1658 | ||
| 1654 | - debug('endReadable', (state[kState] & kEndEmitted) !== 0); | ||
| 1659 | + debug('endReadable'); | ||
| 1655 | 1660 | if ((state[kState] & kEndEmitted) === 0) { | |
| 1656 | 1661 | state[kState] |= kEnded; | |
| 1657 | 1662 | process.nextTick(endReadableNT, state, stream); | |
| 1658 | 1663 | } | |
| 1659 | 1664 | } | |
| 1660 | 1665 | ||
| 1661 | 1666 | function endReadableNT(state, stream) { | |
| 1662 | - debug('endReadableNT', state.endEmitted, state.length); | ||
| 1667 | + debug('endReadableNT'); | ||
| 1663 | 1668 | ||
| 1664 | 1669 | // Check that we didn't get one last unshift. | |
| 1665 | - if (!state.errored && !state.closeEmitted && | ||
| 1666 | - !state.endEmitted && state.length === 0) { | ||
| 1667 | - state.endEmitted = true; | ||
| 1670 | + if ((state[kState] & (kErrored | kCloseEmitted | kEndEmitted)) === 0 && state.length === 0) { | ||
| 1671 | + state[kState] |= kEndEmitted; | ||
| 1668 | 1672 | stream.emit('end'); | |
| 1669 | 1673 | ||
| 1670 | 1674 | if (stream.writable && stream.allowHalfOpen === false) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments