mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
stream: group all properties using defineProperties
PR-URL: https://github.com/nodejs/node/pull/31144 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
1 parent
33352c2433
commit
5bf27729dd
1 file changed
+92
-104
+92
-104
@@ -25,7 +25,7 @@ const {
|
||||
ArrayIsArray,
|
||||
NumberIsInteger,
|
||||
NumberIsNaN,
|
||||
ObjectDefineProperty,
|
||||
ObjectDefineProperties,
|
||||
ObjectSetPrototypeOf,
|
||||
SymbolAsyncIterator,
|
||||
Symbol
|
||||
@@ -166,22 +166,6 @@ function ReadableState(options, stream, isDuplex) {
|
||||
}
|
||||
}
|
||||
|
||||
// Legacy getter for `pipesCount`
|
||||
ObjectDefineProperty(ReadableState.prototype, 'pipesCount', {
|
||||
get() {
|
||||
return this.pipes.length;
|
||||
}
|
||||
});
|
||||
|
||||
// Legacy property for `paused`
|
||||
ObjectDefineProperty(ReadableState.prototype, 'paused', {
|
||||
get() {
|
||||
return this[kPaused] !== false;
|
||||
},
|
||||
set(value) {
|
||||
this[kPaused] = !!value;
|
||||
}
|
||||
});
|
||||
|
||||
function Readable(options) {
|
||||
if (!(this instanceof Readable))
|
||||
@@ -207,40 +191,6 @@ function Readable(options) {
|
||||
Stream.call(this, options);
|
||||
}
|
||||
|
||||
ObjectDefineProperty(Readable.prototype, 'destroyed', {
|
||||
// Making it explicit this property is not enumerable
|
||||
// because otherwise some prototype manipulation in
|
||||
// userland will fail
|
||||
enumerable: false,
|
||||
get() {
|
||||
if (this._readableState === undefined) {
|
||||
return false;
|
||||
}
|
||||
return this._readableState.destroyed;
|
||||
},
|
||||
set(value) {
|
||||
// We ignore the value if the stream
|
||||
// has not been initialized yet
|
||||
if (!this._readableState) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Backward compatibility, the user is explicitly
|
||||
// managing destroyed
|
||||
this._readableState.destroyed = value;
|
||||
}
|
||||
});
|
||||
|
||||
ObjectDefineProperty(Readable.prototype, 'readableEnded', {
|
||||
// Making it explicit this property is not enumerable
|
||||
// because otherwise some prototype manipulation in
|
||||
// userland will fail
|
||||
enumerable: false,
|
||||
get() {
|
||||
return this._readableState ? this._readableState.endEmitted : false;
|
||||
}
|
||||
});
|
||||
|
||||
Readable.prototype.destroy = destroyImpl.destroy;
|
||||
Readable.prototype._undestroy = destroyImpl.undestroy;
|
||||
Readable.prototype._destroy = function(err, cb) {
|
||||
@@ -1120,37 +1070,99 @@ Readable.prototype[SymbolAsyncIterator] = function() {
|
||||
return createReadableStreamAsyncIterator(this);
|
||||
};
|
||||
|
||||
ObjectDefineProperty(Readable.prototype, 'readableHighWaterMark', {
|
||||
// Making it explicit this property is not enumerable
|
||||
// because otherwise some prototype manipulation in
|
||||
// userland will fail
|
||||
enumerable: false,
|
||||
get: function() {
|
||||
return this._readableState.highWaterMark;
|
||||
}
|
||||
});
|
||||
// Making it explicit these properties are not enumerable
|
||||
// because otherwise some prototype manipulation in
|
||||
// userland will fail
|
||||
ObjectDefineProperties(Readable.prototype, {
|
||||
|
||||
ObjectDefineProperty(Readable.prototype, 'readableBuffer', {
|
||||
// Making it explicit this property is not enumerable
|
||||
// because otherwise some prototype manipulation in
|
||||
// userland will fail
|
||||
enumerable: false,
|
||||
get: function() {
|
||||
return this._readableState && this._readableState.buffer;
|
||||
}
|
||||
});
|
||||
|
||||
ObjectDefineProperty(Readable.prototype, 'readableFlowing', {
|
||||
// Making it explicit this property is not enumerable
|
||||
// because otherwise some prototype manipulation in
|
||||
// userland will fail
|
||||
enumerable: false,
|
||||
get: function() {
|
||||
return this._readableState.flowing;
|
||||
readableHighWaterMark: {
|
||||
enumerable: false,
|
||||
get: function() {
|
||||
return this._readableState.highWaterMark;
|
||||
}
|
||||
},
|
||||
set: function(state) {
|
||||
if (this._readableState) {
|
||||
this._readableState.flowing = state;
|
||||
|
||||
readableBuffer: {
|
||||
enumerable: false,
|
||||
get: function() {
|
||||
return this._readableState && this._readableState.buffer;
|
||||
}
|
||||
},
|
||||
|
||||
readableFlowing: {
|
||||
enumerable: false,
|
||||
get: function() {
|
||||
return this._readableState.flowing;
|
||||
},
|
||||
set: function(state) {
|
||||
if (this._readableState) {
|
||||
this._readableState.flowing = state;
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
readableLength: {
|
||||
enumerable: false,
|
||||
get() {
|
||||
return this._readableState.length;
|
||||
}
|
||||
},
|
||||
|
||||
readableObjectMode: {
|
||||
enumerable: false,
|
||||
get() {
|
||||
return this._readableState ? this._readableState.objectMode : false;
|
||||
}
|
||||
},
|
||||
|
||||
readableEncoding: {
|
||||
enumerable: false,
|
||||
get() {
|
||||
return this._readableState ? this._readableState.encoding : null;
|
||||
}
|
||||
},
|
||||
|
||||
destroyed: {
|
||||
enumerable: false,
|
||||
get() {
|
||||
if (this._readableState === undefined) {
|
||||
return false;
|
||||
}
|
||||
return this._readableState.destroyed;
|
||||
},
|
||||
set(value) {
|
||||
// We ignore the value if the stream
|
||||
// has not been initialized yet
|
||||
if (!this._readableState) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Backward compatibility, the user is explicitly
|
||||
// managing destroyed
|
||||
this._readableState.destroyed = value;
|
||||
}
|
||||
},
|
||||
|
||||
readableEnded: {
|
||||
enumerable: false,
|
||||
get() {
|
||||
return this._readableState ? this._readableState.endEmitted : false;
|
||||
}
|
||||
},
|
||||
|
||||
// Legacy getter for `pipesCount`
|
||||
pipesCount: {
|
||||
get() {
|
||||
return this.pipes.length;
|
||||
}
|
||||
},
|
||||
|
||||
paused: {
|
||||
get() {
|
||||
return this[kPaused] !== false;
|
||||
},
|
||||
set(value) {
|
||||
this[kPaused] = !!value;
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -1158,30 +1170,6 @@ ObjectDefineProperty(Readable.prototype, 'readableFlowing', {
|
||||
// Exposed for testing purposes only.
|
||||
Readable._fromList = fromList;
|
||||
|
||||
ObjectDefineProperty(Readable.prototype, 'readableLength', {
|
||||
// Making it explicit this property is not enumerable
|
||||
// because otherwise some prototype manipulation in
|
||||
// userland will fail
|
||||
enumerable: false,
|
||||
get() {
|
||||
return this._readableState.length;
|
||||
}
|
||||
});
|
||||
|
||||
ObjectDefineProperty(Readable.prototype, 'readableObjectMode', {
|
||||
enumerable: false,
|
||||
get() {
|
||||
return this._readableState ? this._readableState.objectMode : false;
|
||||
}
|
||||
});
|
||||
|
||||
ObjectDefineProperty(Readable.prototype, 'readableEncoding', {
|
||||
enumerable: false,
|
||||
get() {
|
||||
return this._readableState ? this._readableState.encoding : null;
|
||||
}
|
||||
});
|
||||
|
||||
// Pluck off n bytes from an array of buffers.
|
||||
// Length is the combined lengths of all the buffers in the list.
|
||||
// This function is designed to be inlinable, so please take care when making
|
||||
|
||||
Reference in new issue
Block a user