@@ -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,
@@ -358,46 +359,6 @@ Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) {
358
359
return this ;
359
360
} ;
360
361
361
- ObjectDefineProperty ( Writable . prototype , 'writableBuffer' , {
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 . getBuffer ( ) ;
368
- }
369
- } ) ;
370
-
371
- ObjectDefineProperty ( Writable . prototype , 'writableEnded' , {
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 . ending : false ;
378
- }
379
- } ) ;
380
-
381
- ObjectDefineProperty ( Writable . prototype , 'writableHighWaterMark' , {
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 . highWaterMark ;
388
- }
389
- } ) ;
390
-
391
- ObjectDefineProperty ( Writable . prototype , 'writableCorked' , {
392
- // Making it explicit this property is not enumerable
393
- // because otherwise some prototype manipulation in
394
- // userland will fail
395
- enumerable : false ,
396
- get : function ( ) {
397
- return this . _writableState ? this . _writableState . corked : 0 ;
398
- }
399
- } ) ;
400
-
401
362
// If we're already writing something, then just put this
402
363
// in the queue, and wait our turn. Otherwise, call _write
403
364
// If we return false, then we need a drain event, so set that flag.
@@ -669,16 +630,6 @@ Writable.prototype.end = function(chunk, encoding, cb) {
669
630
return this ;
670
631
} ;
671
632
672
- ObjectDefineProperty ( Writable . prototype , 'writableLength' , {
673
- // Making it explicit this property is not enumerable
674
- // because otherwise some prototype manipulation in
675
- // userland will fail
676
- enumerable : false ,
677
- get ( ) {
678
- return this . _writableState . length ;
679
- }
680
- } ) ;
681
-
682
633
function needFinish ( state ) {
683
634
return ( state . ending &&
684
635
state . length === 0 &&
@@ -762,44 +713,60 @@ function onCorkedFinish(corkReq, state, err) {
762
713
state . corkedRequestsFree . next = corkReq ;
763
714
}
764
715
765
- ObjectDefineProperty ( Writable . prototype , 'destroyed' , {
766
- // Making it explicit this property is not enumerable
767
- // because otherwise some prototype manipulation in
768
- // userland will fail
769
- enumerable : false ,
770
- get ( ) {
771
- if ( this . _writableState === undefined ) {
772
- return false ;
716
+ ObjectDefineProperties ( Writable . prototype , {
717
+
718
+ destroyed : {
719
+ get ( ) {
720
+ return this . _writableState ? this . _writableState . destroyed : false ;
721
+ } ,
722
+ set ( value ) {
723
+ // Backward compatibility, the user is explicitly managing destroyed
724
+ if ( this . _writableState ) {
725
+ this . _writableState . destroyed = value ;
726
+ }
773
727
}
774
- return this . _writableState . destroyed ;
775
728
} ,
776
- set ( value ) {
777
- // We ignore the value if the stream
778
- // has not been initialized yet
779
- if ( ! this . _writableState ) {
780
- return ;
729
+
730
+ writableFinished : {
731
+ get ( ) {
732
+ return this . _writableState ? this . _writableState . finished : false ;
781
733
}
734
+ } ,
782
735
783
- // Backward compatibility, the user is explicitly
784
- // managing destroyed
785
- this . _writableState . destroyed = value ;
786
- }
787
- } ) ;
736
+ writableObjectMode : {
737
+ get ( ) {
738
+ return this . _writableState ? this . _writableState . objectMode : false ;
739
+ }
740
+ } ,
788
741
789
- ObjectDefineProperty ( Writable . prototype , 'writableObjectMode' , {
790
- enumerable : false ,
791
- get ( ) {
792
- return this . _writableState ? this . _writableState . objectMode : false ;
793
- }
794
- } ) ;
742
+ writableBuffer : {
743
+ get ( ) {
744
+ return this . _writableState && this . _writableState . getBuffer ( ) ;
745
+ }
746
+ } ,
747
+
748
+ writableEnded : {
749
+ get ( ) {
750
+ return this . _writableState ? this . _writableState . ending : false ;
751
+ }
752
+ } ,
753
+
754
+ writableHighWaterMark : {
755
+ get ( ) {
756
+ return this . _writableState && this . _writableState . highWaterMark ;
757
+ }
758
+ } ,
795
759
796
- ObjectDefineProperty ( Writable . prototype , 'writableFinished' , {
797
- // Making it explicit this property is not enumerable
798
- // because otherwise some prototype manipulation in
799
- // userland will fail
800
- enumerable : false ,
801
- get ( ) {
802
- return this . _writableState ? this . _writableState . finished : false ;
760
+ writableCorked : {
761
+ get ( ) {
762
+ return this . _writableState ? this . _writableState . corked : 0 ;
763
+ }
764
+ } ,
765
+
766
+ writableLength : {
767
+ get ( ) {
768
+ return this . _writableState && this . _writableState . length ;
769
+ }
803
770
}
804
771
} ) ;
805
772
0 commit comments