Skip to content

Commit

Permalink
stream: clean up definition using defineProperties
Browse files Browse the repository at this point in the history
PR-URL: #31236
Refs: #31187
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
antsmartian authored and Trott committed Jan 9, 2020
1 parent b0f67f2 commit aff6fff
Showing 1 changed file with 50 additions and 80 deletions.
130 changes: 50 additions & 80 deletions lib/_stream_duplex.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
'use strict';

const {
ObjectDefineProperty,
ObjectDefineProperties,
ObjectKeys,
ObjectSetPrototypeOf,
} = primordials;
Expand Down Expand Up @@ -70,63 +70,60 @@ function Duplex(options) {
}
}

ObjectDefineProperty(Duplex.prototype, 'writableHighWaterMark', {
// Making it explicit this property is not enumerable
// because otherwise some prototype manipulation in
// userland will fail
enumerable: false,
get() {
return this._writableState && this._writableState.highWaterMark;
}
});
ObjectDefineProperties(Duplex.prototype, {

ObjectDefineProperty(Duplex.prototype, 'writableBuffer', {
// Making it explicit this property is not enumerable
// because otherwise some prototype manipulation in
// userland will fail
enumerable: false,
get: function() {
return this._writableState && this._writableState.getBuffer();
}
});
destroyed: {
get() {
if (this._readableState === undefined ||
this._writableState === undefined) {
return false;
}
return this._readableState.destroyed && this._writableState.destroyed;
},
set(value) {
// Backward compatibility, the user is explicitly
// managing destroyed
if (this._readableState && this._writableState) {
this._readableState.destroyed = value;
this._writableState.destroyed = value;
}
}
},

ObjectDefineProperty(Duplex.prototype, 'writableLength', {
// Making it explicit this property is not enumerable
// because otherwise some prototype manipulation in
// userland will fail
enumerable: false,
get() {
return this._writableState && this._writableState.length;
}
});
writableHighWaterMark: {
get() {
return this._writableState && this._writableState.highWaterMark;
}
},

ObjectDefineProperty(Duplex.prototype, 'writableFinished', {
// Making it explicit this property is not enumerable
// because otherwise some prototype manipulation in
// userland will fail
enumerable: false,
get() {
return this._writableState ? this._writableState.finished : false;
}
});
writableBuffer: {
get() {
return this._writableState && this._writableState.getBuffer();
}
},

ObjectDefineProperty(Duplex.prototype, 'writableCorked', {
// Making it explicit this property is not enumerable
// because otherwise some prototype manipulation in
// userland will fail
enumerable: false,
get() {
return this._writableState ? this._writableState.corked : 0;
}
});
writableLength: {
get() {
return this._writableState && this._writableState.length;
}
},

ObjectDefineProperty(Duplex.prototype, 'writableEnded', {
// Making it explicit this property is not enumerable
// because otherwise some prototype manipulation in
// userland will fail
enumerable: false,
get() {
return this._writableState ? this._writableState.ending : false;
writableFinished: {
get() {
return this._writableState ? this._writableState.finished : false;
}
},

writableCorked: {
get() {
return this._writableState ? this._writableState.corked : 0;
}
},

writableEnded: {
get() {
return this._writableState ? this._writableState.ending : false;
}
}
});

Expand All @@ -144,30 +141,3 @@ function onend() {
function onEndNT(self) {
self.end();
}

ObjectDefineProperty(Duplex.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 ||
this._writableState === undefined) {
return false;
}
return this._readableState.destroyed && this._writableState.destroyed;
},
set(value) {
// We ignore the value if the stream
// has not been initialized yet
if (this._readableState === undefined ||
this._writableState === undefined) {
return;
}

// Backward compatibility, the user is explicitly
// managing destroyed
this._readableState.destroyed = value;
this._writableState.destroyed = value;
}
});

0 comments on commit aff6fff

Please sign in to comment.