Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream: clean up definition using defineProperties #31236

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
BridgeAR marked this conversation as resolved.
Show resolved Hide resolved
},
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;
}
BridgeAR marked this conversation as resolved.
Show resolved Hide resolved
}
});

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;
}
});