From 0646eda4fc0affb98e13c30acb522e63b7fd6dde Mon Sep 17 00:00:00 2001 From: Michaƫl Zasso Date: Fri, 22 Nov 2019 18:04:46 +0100 Subject: lib: flatten access to primordials Store all primordials as properties of the primordials object. Static functions are prefixed by the constructor's name and prototype methods are prefixed by the constructor's name followed by "Prototype". For example: primordials.Object.keys becomes primordials.ObjectKeys. PR-URL: https://github.com/nodejs/node/pull/30610 Refs: https://github.com/nodejs/node/issues/29766 Reviewed-By: Anna Henningsen Reviewed-By: Matteo Collina Reviewed-By: Colin Ihrig Reviewed-By: Trivikram Kamat --- lib/_stream_duplex.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) (limited to 'lib/_stream_duplex.js') diff --git a/lib/_stream_duplex.js b/lib/_stream_duplex.js index 858dc938f0..572e6da94d 100644 --- a/lib/_stream_duplex.js +++ b/lib/_stream_duplex.js @@ -26,19 +26,23 @@ 'use strict'; -const { Object } = primordials; +const { + ObjectDefineProperty, + ObjectKeys, + ObjectSetPrototypeOf, +} = primordials; module.exports = Duplex; const Readable = require('_stream_readable'); const Writable = require('_stream_writable'); -Object.setPrototypeOf(Duplex.prototype, Readable.prototype); -Object.setPrototypeOf(Duplex, Readable); +ObjectSetPrototypeOf(Duplex.prototype, Readable.prototype); +ObjectSetPrototypeOf(Duplex, Readable); { // Allow the keys array to be GC'ed. - const keys = Object.keys(Writable.prototype); + const keys = ObjectKeys(Writable.prototype); for (let v = 0; v < keys.length; v++) { const method = keys[v]; if (!Duplex.prototype[method]) @@ -68,7 +72,7 @@ function Duplex(options) { } } -Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', { +ObjectDefineProperty(Duplex.prototype, 'writableHighWaterMark', { // Making it explicit this property is not enumerable // because otherwise some prototype manipulation in // userland will fail @@ -78,7 +82,7 @@ Object.defineProperty(Duplex.prototype, 'writableHighWaterMark', { } }); -Object.defineProperty(Duplex.prototype, 'writableBuffer', { +ObjectDefineProperty(Duplex.prototype, 'writableBuffer', { // Making it explicit this property is not enumerable // because otherwise some prototype manipulation in // userland will fail @@ -88,7 +92,7 @@ Object.defineProperty(Duplex.prototype, 'writableBuffer', { } }); -Object.defineProperty(Duplex.prototype, 'writableLength', { +ObjectDefineProperty(Duplex.prototype, 'writableLength', { // Making it explicit this property is not enumerable // because otherwise some prototype manipulation in // userland will fail @@ -98,7 +102,7 @@ Object.defineProperty(Duplex.prototype, 'writableLength', { } }); -Object.defineProperty(Duplex.prototype, 'writableFinished', { +ObjectDefineProperty(Duplex.prototype, 'writableFinished', { // Making it explicit this property is not enumerable // because otherwise some prototype manipulation in // userland will fail @@ -108,7 +112,7 @@ Object.defineProperty(Duplex.prototype, 'writableFinished', { } }); -Object.defineProperty(Duplex.prototype, 'writableCorked', { +ObjectDefineProperty(Duplex.prototype, 'writableCorked', { // Making it explicit this property is not enumerable // because otherwise some prototype manipulation in // userland will fail @@ -118,7 +122,7 @@ Object.defineProperty(Duplex.prototype, 'writableCorked', { } }); -Object.defineProperty(Duplex.prototype, 'writableEnded', { +ObjectDefineProperty(Duplex.prototype, 'writableEnded', { // Making it explicit this property is not enumerable // because otherwise some prototype manipulation in // userland will fail @@ -143,7 +147,7 @@ function onEndNT(self) { self.end(); } -Object.defineProperty(Duplex.prototype, 'destroyed', { +ObjectDefineProperty(Duplex.prototype, 'destroyed', { // Making it explicit this property is not enumerable // because otherwise some prototype manipulation in // userland will fail -- cgit v1.2.3