27
27
'use strict' ;
28
28
29
29
const {
30
- ObjectDefineProperty ,
30
+ ObjectDefineProperties ,
31
31
ObjectKeys,
32
32
ObjectSetPrototypeOf,
33
33
} = primordials ;
@@ -70,63 +70,60 @@ function Duplex(options) {
70
70
}
71
71
}
72
72
73
- ObjectDefineProperty ( Duplex . prototype , 'writableHighWaterMark' , {
74
- // Making it explicit this property is not enumerable
75
- // because otherwise some prototype manipulation in
76
- // userland will fail
77
- enumerable : false ,
78
- get ( ) {
79
- return this . _writableState && this . _writableState . highWaterMark ;
80
- }
81
- } ) ;
73
+ ObjectDefineProperties ( Duplex . prototype , {
82
74
83
- ObjectDefineProperty ( Duplex . prototype , 'writableBuffer' , {
84
- // Making it explicit this property is not enumerable
85
- // because otherwise some prototype manipulation in
86
- // userland will fail
87
- enumerable : false ,
88
- get : function ( ) {
89
- return this . _writableState && this . _writableState . getBuffer ( ) ;
90
- }
91
- } ) ;
75
+ destroyed : {
76
+ get ( ) {
77
+ if ( this . _readableState === undefined ||
78
+ this . _writableState === undefined ) {
79
+ return false ;
80
+ }
81
+ return this . _readableState . destroyed && this . _writableState . destroyed ;
82
+ } ,
83
+ set ( value ) {
84
+ // Backward compatibility, the user is explicitly
85
+ // managing destroyed
86
+ if ( this . _readableState && this . _writableState ) {
87
+ this . _readableState . destroyed = value ;
88
+ this . _writableState . destroyed = value ;
89
+ }
90
+ }
91
+ } ,
92
92
93
- ObjectDefineProperty ( Duplex . prototype , 'writableLength' , {
94
- // Making it explicit this property is not enumerable
95
- // because otherwise some prototype manipulation in
96
- // userland will fail
97
- enumerable : false ,
98
- get ( ) {
99
- return this . _writableState && this . _writableState . length ;
100
- }
101
- } ) ;
93
+ writableHighWaterMark : {
94
+ get ( ) {
95
+ return this . _writableState && this . _writableState . highWaterMark ;
96
+ }
97
+ } ,
102
98
103
- ObjectDefineProperty ( Duplex . prototype , 'writableFinished' , {
104
- // Making it explicit this property is not enumerable
105
- // because otherwise some prototype manipulation in
106
- // userland will fail
107
- enumerable : false ,
108
- get ( ) {
109
- return this . _writableState ? this . _writableState . finished : false ;
110
- }
111
- } ) ;
99
+ writableBuffer : {
100
+ get ( ) {
101
+ return this . _writableState && this . _writableState . getBuffer ( ) ;
102
+ }
103
+ } ,
112
104
113
- ObjectDefineProperty ( Duplex . prototype , 'writableCorked' , {
114
- // Making it explicit this property is not enumerable
115
- // because otherwise some prototype manipulation in
116
- // userland will fail
117
- enumerable : false ,
118
- get ( ) {
119
- return this . _writableState ? this . _writableState . corked : 0 ;
120
- }
121
- } ) ;
105
+ writableLength : {
106
+ get ( ) {
107
+ return this . _writableState && this . _writableState . length ;
108
+ }
109
+ } ,
122
110
123
- ObjectDefineProperty ( Duplex . prototype , 'writableEnded' , {
124
- // Making it explicit this property is not enumerable
125
- // because otherwise some prototype manipulation in
126
- // userland will fail
127
- enumerable : false ,
128
- get ( ) {
129
- return this . _writableState ? this . _writableState . ending : false ;
111
+ writableFinished : {
112
+ get ( ) {
113
+ return this . _writableState ? this . _writableState . finished : false ;
114
+ }
115
+ } ,
116
+
117
+ writableCorked : {
118
+ get ( ) {
119
+ return this . _writableState ? this . _writableState . corked : 0 ;
120
+ }
121
+ } ,
122
+
123
+ writableEnded : {
124
+ get ( ) {
125
+ return this . _writableState ? this . _writableState . ending : false ;
126
+ }
130
127
}
131
128
} ) ;
132
129
@@ -144,30 +141,3 @@ function onend() {
144
141
function onEndNT ( self ) {
145
142
self . end ( ) ;
146
143
}
147
-
148
- ObjectDefineProperty ( Duplex . prototype , 'destroyed' , {
149
- // Making it explicit this property is not enumerable
150
- // because otherwise some prototype manipulation in
151
- // userland will fail
152
- enumerable : false ,
153
- get ( ) {
154
- if ( this . _readableState === undefined ||
155
- this . _writableState === undefined ) {
156
- return false ;
157
- }
158
- return this . _readableState . destroyed && this . _writableState . destroyed ;
159
- } ,
160
- set ( value ) {
161
- // We ignore the value if the stream
162
- // has not been initialized yet
163
- if ( this . _readableState === undefined ||
164
- this . _writableState === undefined ) {
165
- return ;
166
- }
167
-
168
- // Backward compatibility, the user is explicitly
169
- // managing destroyed
170
- this . _readableState . destroyed = value ;
171
- this . _writableState . destroyed = value ;
172
- }
173
- } ) ;
0 commit comments