Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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;
},
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;
}
});