@@ -29,6 +29,7 @@ const { |
29 | 29 | Array, |
30 | 30 | FunctionPrototype, |
31 | 31 | ObjectDefineProperty, |
| 32 | + ObjectDefineProperties, |
32 | 33 | ObjectSetPrototypeOf, |
33 | 34 | Symbol, |
34 | 35 | SymbolHasInstance, |
@@ -348,46 +349,6 @@ Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) { |
348 | 349 | return this; |
349 | 350 | }; |
350 | 351 |
|
351 | | -ObjectDefineProperty(Writable.prototype, 'writableBuffer', { |
352 | | - // Making it explicit this property is not enumerable |
353 | | - // because otherwise some prototype manipulation in |
354 | | - // userland will fail |
355 | | - enumerable: false, |
356 | | - get: function() { |
357 | | - return this._writableState && this._writableState.getBuffer(); |
358 | | - } |
359 | | -}); |
360 | | - |
361 | | -ObjectDefineProperty(Writable.prototype, 'writableEnded', { |
362 | | - // Making it explicit this property is not enumerable |
363 | | - // because otherwise some prototype manipulation in |
364 | | - // userland will fail |
365 | | - enumerable: false, |
366 | | - get: function() { |
367 | | - return this._writableState ? this._writableState.ending : false; |
368 | | - } |
369 | | -}); |
370 | | - |
371 | | -ObjectDefineProperty(Writable.prototype, 'writableHighWaterMark', { |
372 | | - // Making it explicit this property is not enumerable |
373 | | - // because otherwise some prototype manipulation in |
374 | | - // userland will fail |
375 | | - enumerable: false, |
376 | | - get: function() { |
377 | | - return this._writableState && this._writableState.highWaterMark; |
378 | | - } |
379 | | -}); |
380 | | - |
381 | | -ObjectDefineProperty(Writable.prototype, 'writableCorked', { |
382 | | - // Making it explicit this property is not enumerable |
383 | | - // because otherwise some prototype manipulation in |
384 | | - // userland will fail |
385 | | - enumerable: false, |
386 | | - get: function() { |
387 | | - return this._writableState ? this._writableState.corked : 0; |
388 | | - } |
389 | | -}); |
390 | | - |
391 | 352 | // If we're already writing something, then just put this |
392 | 353 | // in the queue, and wait our turn. Otherwise, call _write |
393 | 354 | // If we return false, then we need a drain event, so set that flag. |
@@ -636,16 +597,6 @@ Writable.prototype.end = function(chunk, encoding, cb) { |
636 | 597 | return this; |
637 | 598 | }; |
638 | 599 |
|
639 | | -ObjectDefineProperty(Writable.prototype, 'writableLength', { |
640 | | - // Making it explicit this property is not enumerable |
641 | | - // because otherwise some prototype manipulation in |
642 | | - // userland will fail |
643 | | - enumerable: false, |
644 | | - get() { |
645 | | - return this._writableState.length; |
646 | | - } |
647 | | -}); |
648 | | - |
649 | 600 | function needFinish(state) { |
650 | 601 | return (state.ending && |
651 | 602 | state.length === 0 && |
@@ -727,44 +678,60 @@ function onCorkedFinish(corkReq, state, err) { |
727 | 678 | state.corkedRequestsFree.next = corkReq; |
728 | 679 | } |
729 | 680 |
|
730 | | -ObjectDefineProperty(Writable.prototype, 'destroyed', { |
731 | | - // Making it explicit this property is not enumerable |
732 | | - // because otherwise some prototype manipulation in |
733 | | - // userland will fail |
734 | | - enumerable: false, |
735 | | - get() { |
736 | | - if (this._writableState === undefined) { |
737 | | - return false; |
| 681 | +ObjectDefineProperties(Writable.prototype, { |
| 682 | + |
| 683 | + destroyed: { |
| 684 | + get() { |
| 685 | + return this._writableState ? this._writableState.destroyed : false; |
| 686 | + }, |
| 687 | + set(value) { |
| 688 | + // Backward compatibility, the user is explicitly managing destroyed |
| 689 | + if (this._writableState) { |
| 690 | + this._writableState.destroyed = value; |
| 691 | + } |
738 | 692 | } |
739 | | - return this._writableState.destroyed; |
740 | 693 | }, |
741 | | - set(value) { |
742 | | - // We ignore the value if the stream |
743 | | - // has not been initialized yet |
744 | | - if (!this._writableState) { |
745 | | - return; |
| 694 | + |
| 695 | + writableFinished: { |
| 696 | + get() { |
| 697 | + return this._writableState ? this._writableState.finished : false; |
746 | 698 | } |
| 699 | + }, |
747 | 700 |
|
748 | | - // Backward compatibility, the user is explicitly |
749 | | - // managing destroyed |
750 | | - this._writableState.destroyed = value; |
751 | | - } |
752 | | -}); |
| 701 | + writableObjectMode: { |
| 702 | + get() { |
| 703 | + return this._writableState ? this._writableState.objectMode : false; |
| 704 | + } |
| 705 | + }, |
753 | 706 |
|
754 | | -ObjectDefineProperty(Writable.prototype, 'writableObjectMode', { |
755 | | - enumerable: false, |
756 | | - get() { |
757 | | - return this._writableState ? this._writableState.objectMode : false; |
758 | | - } |
759 | | -}); |
| 707 | + writableBuffer: { |
| 708 | + get() { |
| 709 | + return this._writableState && this._writableState.getBuffer(); |
| 710 | + } |
| 711 | + }, |
| 712 | + |
| 713 | + writableEnded: { |
| 714 | + get() { |
| 715 | + return this._writableState ? this._writableState.ending : false; |
| 716 | + } |
| 717 | + }, |
| 718 | + |
| 719 | + writableHighWaterMark: { |
| 720 | + get() { |
| 721 | + return this._writableState && this._writableState.highWaterMark; |
| 722 | + } |
| 723 | + }, |
760 | 724 |
|
761 | | -ObjectDefineProperty(Writable.prototype, 'writableFinished', { |
762 | | - // Making it explicit this property is not enumerable |
763 | | - // because otherwise some prototype manipulation in |
764 | | - // userland will fail |
765 | | - enumerable: false, |
766 | | - get() { |
767 | | - return this._writableState ? this._writableState.finished : false; |
| 725 | + writableCorked: { |
| 726 | + get() { |
| 727 | + return this._writableState ? this._writableState.corked : 0; |
| 728 | + } |
| 729 | + }, |
| 730 | + |
| 731 | + writableLength: { |
| 732 | + get() { |
| 733 | + return this._writableState && this._writableState.length; |
| 734 | + } |
768 | 735 | } |
769 | 736 | }); |
770 | 737 |
|
|