@@ -73,6 +73,7 @@ const { |
73 | 73 | const { validateObject } = require('internal/validators'); |
74 | 74 |
|
75 | 75 | const kPaused = Symbol('kPaused'); |
| 76 | +const kState = Symbol('kState'); |
76 | 77 |
|
77 | 78 | const { StringDecoder } = require('string_decoder'); |
78 | 79 | const from = require('internal/streams/from'); |
@@ -107,10 +108,10 @@ const kDataEmitted = 1 << 18; |
107 | 108 | function makeBitMapDescriptor(bit) { |
108 | 109 | return { |
109 | 110 | enumerable: false, |
110 | | - get() { return (this.state & bit) !== 0; }, |
| 111 | + get() { return (this[kState] & bit) !== 0; }, |
111 | 112 | set(value) { |
112 | | - if (value) this.state |= bit; |
113 | | - else this.state &= ~bit; |
| 113 | + if (value) this[kState] |= bit; |
| 114 | + else this[kState] &= ~bit; |
114 | 115 | }, |
115 | 116 | }; |
116 | 117 | } |
@@ -163,13 +164,13 @@ function ReadableState(options, stream, isDuplex) { |
163 | 164 |
|
164 | 165 | // Bit map field to store ReadableState more effciently with 1 bit per field |
165 | 166 | // instead of a V8 slot per field. |
166 | | - this.state = kEmitClose | kAutoDestroy | kConstructed | kSync; |
| 167 | + this[kState] = kEmitClose | kAutoDestroy | kConstructed | kSync; |
167 | 168 | // Object stream flag. Used to make read(n) ignore n and to |
168 | 169 | // make all the buffer merging and length checks go away. |
169 | | - if (options && options.objectMode) this.state |= kObjectMode; |
| 170 | + if (options && options.objectMode) this[kState] |= kObjectMode; |
170 | 171 |
|
171 | 172 | if (isDuplex && options && options.readableObjectMode) |
172 | | - this.state |= kObjectMode; |
| 173 | + this[kState] |= kObjectMode; |
173 | 174 |
|
174 | 175 | // The point at which it stops calling _read() to fill the buffer |
175 | 176 | // Note: 0 is a valid value, means "don't call _read preemptively ever" |
@@ -188,10 +189,10 @@ function ReadableState(options, stream, isDuplex) { |
188 | 189 | this[kPaused] = null; |
189 | 190 |
|
190 | 191 | // Should close be emitted on destroy. Defaults to true. |
191 | | - if (options && options.emitClose === false) this.state &= ~kEmitClose; |
| 192 | + if (options && options.emitClose === false) this[kState] &= ~kEmitClose; |
192 | 193 |
|
193 | 194 | // Should .destroy() be called after 'end' (and potentially 'finish'). |
194 | | - if (options && options.autoDestroy === false) this.state &= ~kAutoDestroy; |
| 195 | + if (options && options.autoDestroy === false) this[kState] &= ~kAutoDestroy; |
195 | 196 |
|
196 | 197 |
|
197 | 198 | // Indicates whether the stream has errored. When true no further |
@@ -296,7 +297,7 @@ function readableAddChunk(stream, chunk, encoding, addToFront) { |
296 | 297 | const state = stream._readableState; |
297 | 298 |
|
298 | 299 | let err; |
299 | | - if ((state.state & kObjectMode) === 0) { |
| 300 | + if ((state[kState] & kObjectMode) === 0) { |
300 | 301 | if (typeof chunk === 'string') { |
301 | 302 | encoding = encoding || state.defaultEncoding; |
302 | 303 | if (state.encoding !== encoding) { |
@@ -323,11 +324,11 @@ function readableAddChunk(stream, chunk, encoding, addToFront) { |
323 | 324 | if (err) { |
324 | 325 | errorOrDestroy(stream, err); |
325 | 326 | } else if (chunk === null) { |
326 | | - state.state &= ~kReading; |
| 327 | + state[kState] &= ~kReading; |
327 | 328 | onEofChunk(stream, state); |
328 | | - } else if (((state.state & kObjectMode) !== 0) || (chunk && chunk.length > 0)) { |
| 329 | + } else if (((state[kState] & kObjectMode) !== 0) || (chunk && chunk.length > 0)) { |
329 | 330 | if (addToFront) { |
330 | | - if ((state.state & kEndEmitted) !== 0) |
| 331 | + if ((state[kState] & kEndEmitted) !== 0) |
331 | 332 | errorOrDestroy(stream, new ERR_STREAM_UNSHIFT_AFTER_END_EVENT()); |
332 | 333 | else if (state.destroyed || state.errored) |
333 | 334 | return false; |
@@ -338,7 +339,7 @@ function readableAddChunk(stream, chunk, encoding, addToFront) { |
338 | 339 | } else if (state.destroyed || state.errored) { |
339 | 340 | return false; |
340 | 341 | } else { |
341 | | - state.state &= ~kReading; |
| 342 | + state[kState] &= ~kReading; |
342 | 343 | if (state.decoder && !encoding) { |
343 | 344 | chunk = state.decoder.write(chunk); |
344 | 345 | if (state.objectMode || chunk.length !== 0) |
@@ -350,7 +351,7 @@ function readableAddChunk(stream, chunk, encoding, addToFront) { |
350 | 351 | } |
351 | 352 | } |
352 | 353 | } else if (!addToFront) { |
353 | | - state.state &= ~kReading; |
| 354 | + state[kState] &= ~kReading; |
354 | 355 | maybeReadMore(stream, state); |
355 | 356 | } |
356 | 357 |
|
@@ -366,7 +367,7 @@ function addChunk(stream, state, chunk, addToFront) { |
366 | 367 | stream.listenerCount('data') > 0) { |
367 | 368 | // Use the guard to avoid creating `Set()` repeatedly |
368 | 369 | // when we have multiple pipes. |
369 | | - if ((state.state & kMultiAwaitDrain) !== 0) { |
| 370 | + if ((state[kState] & kMultiAwaitDrain) !== 0) { |
370 | 371 | state.awaitDrainWriters.clear(); |
371 | 372 | } else { |
372 | 373 | state.awaitDrainWriters = null; |
@@ -382,7 +383,7 @@ function addChunk(stream, state, chunk, addToFront) { |
382 | 383 | else |
383 | 384 | state.buffer.push(chunk); |
384 | 385 |
|
385 | | - if ((state.state & kNeedReadable) !== 0) |
| 386 | + if ((state[kState] & kNeedReadable) !== 0) |
386 | 387 | emitReadable(stream); |
387 | 388 | } |
388 | 389 | maybeReadMore(stream, state); |
@@ -437,7 +438,7 @@ function computeNewHighWaterMark(n) { |
437 | 438 | function howMuchToRead(n, state) { |
438 | 439 | if (n <= 0 || (state.length === 0 && state.ended)) |
439 | 440 | return 0; |
440 | | - if ((state.state & kObjectMode) !== 0) |
| 441 | + if ((state[kState] & kObjectMode) !== 0) |
441 | 442 | return 1; |
442 | 443 | if (NumberIsNaN(n)) { |
443 | 444 | // Only flow one buffer at a time. |
@@ -468,7 +469,7 @@ Readable.prototype.read = function(n) { |
468 | 469 | state.highWaterMark = computeNewHighWaterMark(n); |
469 | 470 |
|
470 | 471 | if (n !== 0) |
471 | | - state.state &= ~kEmittedReadable; |
| 472 | + state[kState] &= ~kEmittedReadable; |
472 | 473 |
|
473 | 474 | // If we're doing read(0) to trigger a readable event, but we |
474 | 475 | // already have a bunch of data in the buffer, then just trigger |
@@ -519,7 +520,7 @@ Readable.prototype.read = function(n) { |
519 | 520 | // 3. Actually pull the requested chunks out of the buffer and return. |
520 | 521 |
|
521 | 522 | // if we need a readable event, then we need to do some reading. |
522 | | - let doRead = (state.state & kNeedReadable) !== 0; |
| 523 | + let doRead = (state[kState] & kNeedReadable) !== 0; |
523 | 524 | debug('need readable', doRead); |
524 | 525 |
|
525 | 526 | // If we currently have less than the highWaterMark, then also read some. |
@@ -537,18 +538,18 @@ Readable.prototype.read = function(n) { |
537 | 538 | debug('reading, ended or constructing', doRead); |
538 | 539 | } else if (doRead) { |
539 | 540 | debug('do read'); |
540 | | - state.state |= kReading | kSync; |
| 541 | + state[kState] |= kReading | kSync; |
541 | 542 | // If the length is currently zero, then we *need* a readable event. |
542 | 543 | if (state.length === 0) |
543 | | - state.state |= kNeedReadable; |
| 544 | + state[kState] |= kNeedReadable; |
544 | 545 |
|
545 | 546 | // Call internal read method |
546 | 547 | try { |
547 | 548 | this._read(state.highWaterMark); |
548 | 549 | } catch (err) { |
549 | 550 | errorOrDestroy(this, err); |
550 | 551 | } |
551 | | - state.state &= ~kSync; |
| 552 | + state[kState] &= ~kSync; |
552 | 553 |
|
553 | 554 | // If _read pushed data synchronously, then `reading` will be false, |
554 | 555 | // and we need to re-evaluate how much data we can return to the user. |
|