@@ -25,7 +25,7 @@ const {
25
25
ArrayIsArray,
26
26
NumberIsInteger,
27
27
NumberIsNaN,
28
- ObjectDefineProperty ,
28
+ ObjectDefineProperties ,
29
29
ObjectSetPrototypeOf,
30
30
SymbolAsyncIterator,
31
31
Symbol
@@ -162,15 +162,6 @@ function ReadableState(options, stream, isDuplex) {
162
162
}
163
163
}
164
164
165
- // Legacy property for `paused`
166
- ObjectDefineProperty ( ReadableState . prototype , 'paused' , {
167
- get ( ) {
168
- return this [ kPaused ] !== false ;
169
- } ,
170
- set ( value ) {
171
- this [ kPaused ] = ! ! value ;
172
- }
173
- } ) ;
174
165
175
166
function Readable ( options ) {
176
167
if ( ! ( this instanceof Readable ) )
@@ -196,40 +187,6 @@ function Readable(options) {
196
187
Stream . call ( this , options ) ;
197
188
}
198
189
199
- ObjectDefineProperty ( Readable . prototype , 'destroyed' , {
200
- // Making it explicit this property is not enumerable
201
- // because otherwise some prototype manipulation in
202
- // userland will fail
203
- enumerable : false ,
204
- get ( ) {
205
- if ( this . _readableState === undefined ) {
206
- return false ;
207
- }
208
- return this . _readableState . destroyed ;
209
- } ,
210
- set ( value ) {
211
- // We ignore the value if the stream
212
- // has not been initialized yet
213
- if ( ! this . _readableState ) {
214
- return ;
215
- }
216
-
217
- // Backward compatibility, the user is explicitly
218
- // managing destroyed
219
- this . _readableState . destroyed = value ;
220
- }
221
- } ) ;
222
-
223
- ObjectDefineProperty ( Readable . prototype , 'readableEnded' , {
224
- // Making it explicit this property is not enumerable
225
- // because otherwise some prototype manipulation in
226
- // userland will fail
227
- enumerable : false ,
228
- get ( ) {
229
- return this . _readableState ? this . _readableState . endEmitted : false ;
230
- }
231
- } ) ;
232
-
233
190
Readable . prototype . destroy = destroyImpl . destroy ;
234
191
Readable . prototype . _undestroy = destroyImpl . undestroy ;
235
192
Readable . prototype . _destroy = function ( err , cb ) {
@@ -1105,68 +1062,99 @@ Readable.prototype[SymbolAsyncIterator] = function() {
1105
1062
return createReadableStreamAsyncIterator ( this ) ;
1106
1063
} ;
1107
1064
1108
- ObjectDefineProperty ( Readable . prototype , 'readableHighWaterMark' , {
1109
- // Making it explicit this property is not enumerable
1110
- // because otherwise some prototype manipulation in
1111
- // userland will fail
1112
- enumerable : false ,
1113
- get : function ( ) {
1114
- return this . _readableState . highWaterMark ;
1115
- }
1116
- } ) ;
1065
+ // Making it explicit these properties are not enumerable
1066
+ // because otherwise some prototype manipulation in
1067
+ // userland will fail
1068
+ ObjectDefineProperties ( Readable . prototype , {
1117
1069
1118
- ObjectDefineProperty ( Readable . prototype , 'readableBuffer' , {
1119
- // Making it explicit this property is not enumerable
1120
- // because otherwise some prototype manipulation in
1121
- // userland will fail
1122
- enumerable : false ,
1123
- get : function ( ) {
1124
- return this . _readableState && this . _readableState . buffer ;
1125
- }
1126
- } ) ;
1070
+ readableHighWaterMark : {
1071
+ enumerable : false ,
1072
+ get : function ( ) {
1073
+ return this . _readableState . highWaterMark ;
1074
+ }
1075
+ } ,
1127
1076
1128
- ObjectDefineProperty ( Readable . prototype , 'readableFlowing' , {
1129
- // Making it explicit this property is not enumerable
1130
- // because otherwise some prototype manipulation in
1131
- // userland will fail
1132
- enumerable : false ,
1133
- get : function ( ) {
1134
- return this . _readableState . flowing ;
1077
+ readableBuffer : {
1078
+ enumerable : false ,
1079
+ get : function ( ) {
1080
+ return this . _readableState && this . _readableState . buffer ;
1081
+ }
1135
1082
} ,
1136
- set : function ( state ) {
1137
- if ( this . _readableState ) {
1138
- this . _readableState . flowing = state ;
1083
+
1084
+ readableFlowing : {
1085
+ enumerable : false ,
1086
+ get : function ( ) {
1087
+ return this . _readableState . flowing ;
1088
+ } ,
1089
+ set : function ( state ) {
1090
+ if ( this . _readableState ) {
1091
+ this . _readableState . flowing = state ;
1092
+ }
1139
1093
}
1140
- }
1141
- } ) ;
1094
+ } ,
1142
1095
1143
- // Exposed for testing purposes only.
1144
- Readable . _fromList = fromList ;
1096
+ readableLength : {
1097
+ enumerable : false ,
1098
+ get ( ) {
1099
+ return this . _readableState . length ;
1100
+ }
1101
+ } ,
1145
1102
1146
- ObjectDefineProperty ( Readable . prototype , 'readableLength' , {
1147
- // Making it explicit this property is not enumerable
1148
- // because otherwise some prototype manipulation in
1149
- // userland will fail
1150
- enumerable : false ,
1151
- get ( ) {
1152
- return this . _readableState . length ;
1153
- }
1154
- } ) ;
1103
+ readableObjectMode : {
1104
+ enumerable : false ,
1105
+ get ( ) {
1106
+ return this . _readableState ? this . _readableState . objectMode : false ;
1107
+ }
1108
+ } ,
1155
1109
1156
- ObjectDefineProperty ( Readable . prototype , 'readableObjectMode' , {
1157
- enumerable : false ,
1158
- get ( ) {
1159
- return this . _readableState ? this . _readableState . objectMode : false ;
1160
- }
1161
- } ) ;
1110
+ readableEncoding : {
1111
+ enumerable : false ,
1112
+ get ( ) {
1113
+ return this . _readableState ? this . _readableState . encoding : null ;
1114
+ }
1115
+ } ,
1116
+
1117
+ destroyed : {
1118
+ enumerable : false ,
1119
+ get ( ) {
1120
+ if ( this . _readableState === undefined ) {
1121
+ return false ;
1122
+ }
1123
+ return this . _readableState . destroyed ;
1124
+ } ,
1125
+ set ( value ) {
1126
+ // We ignore the value if the stream
1127
+ // has not been initialized yet
1128
+ if ( ! this . _readableState ) {
1129
+ return ;
1130
+ }
1162
1131
1163
- ObjectDefineProperty ( Readable . prototype , 'readableEncoding' , {
1164
- enumerable : false ,
1165
- get ( ) {
1166
- return this . _readableState ? this . _readableState . encoding : null ;
1132
+ // Backward compatibility, the user is explicitly
1133
+ // managing destroyed
1134
+ this . _readableState . destroyed = value ;
1135
+ }
1136
+ } ,
1137
+
1138
+ readableEnded : {
1139
+ enumerable : false ,
1140
+ get ( ) {
1141
+ return this . _readableState ? this . _readableState . endEmitted : false ;
1142
+ }
1143
+ } ,
1144
+
1145
+ paused : {
1146
+ get ( ) {
1147
+ return this [ kPaused ] !== false ;
1148
+ } ,
1149
+ set ( value ) {
1150
+ this [ kPaused ] = ! ! value ;
1151
+ }
1167
1152
}
1168
1153
} ) ;
1169
1154
1155
+ // Exposed for testing purposes only.
1156
+ Readable . _fromList = fromList ;
1157
+
1170
1158
// Pluck off n bytes from an array of buffers.
1171
1159
// Length is the combined lengths of all the buffers in the list.
1172
1160
// This function is designed to be inlinable, so please take care when making
0 commit comments