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_readable.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'lib/_stream_readable.js') diff --git a/lib/_stream_readable.js b/lib/_stream_readable.js index 71fd74b07b..69f46f80a0 100644 --- a/lib/_stream_readable.js +++ b/lib/_stream_readable.js @@ -21,7 +21,10 @@ 'use strict'; -const { Object } = primordials; +const { + ObjectDefineProperty, + ObjectSetPrototypeOf, +} = primordials; module.exports = Readable; Readable.ReadableState = ReadableState; @@ -49,8 +52,8 @@ let StringDecoder; let createReadableStreamAsyncIterator; let from; -Object.setPrototypeOf(Readable.prototype, Stream.prototype); -Object.setPrototypeOf(Readable, Stream); +ObjectSetPrototypeOf(Readable.prototype, Stream.prototype); +ObjectSetPrototypeOf(Readable, Stream); const { errorOrDestroy } = destroyImpl; const kProxyEvents = ['error', 'close', 'destroy', 'pause', 'resume']; @@ -157,7 +160,7 @@ function ReadableState(options, stream, isDuplex) { } // Legacy getter for `pipesCount` -Object.defineProperty(ReadableState.prototype, 'pipesCount', { +ObjectDefineProperty(ReadableState.prototype, 'pipesCount', { get() { return this.pipes.length; } @@ -187,7 +190,7 @@ function Readable(options) { Stream.call(this); } -Object.defineProperty(Readable.prototype, 'destroyed', { +ObjectDefineProperty(Readable.prototype, 'destroyed', { // Making it explicit this property is not enumerable // because otherwise some prototype manipulation in // userland will fail @@ -211,7 +214,7 @@ Object.defineProperty(Readable.prototype, 'destroyed', { } }); -Object.defineProperty(Readable.prototype, 'readableEnded', { +ObjectDefineProperty(Readable.prototype, 'readableEnded', { // Making it explicit this property is not enumerable // because otherwise some prototype manipulation in // userland will fail @@ -1089,7 +1092,7 @@ Readable.prototype[Symbol.asyncIterator] = function() { return createReadableStreamAsyncIterator(this); }; -Object.defineProperty(Readable.prototype, 'readableHighWaterMark', { +ObjectDefineProperty(Readable.prototype, 'readableHighWaterMark', { // Making it explicit this property is not enumerable // because otherwise some prototype manipulation in // userland will fail @@ -1099,7 +1102,7 @@ Object.defineProperty(Readable.prototype, 'readableHighWaterMark', { } }); -Object.defineProperty(Readable.prototype, 'readableBuffer', { +ObjectDefineProperty(Readable.prototype, 'readableBuffer', { // Making it explicit this property is not enumerable // because otherwise some prototype manipulation in // userland will fail @@ -1109,7 +1112,7 @@ Object.defineProperty(Readable.prototype, 'readableBuffer', { } }); -Object.defineProperty(Readable.prototype, 'readableFlowing', { +ObjectDefineProperty(Readable.prototype, 'readableFlowing', { // Making it explicit this property is not enumerable // because otherwise some prototype manipulation in // userland will fail @@ -1127,7 +1130,7 @@ Object.defineProperty(Readable.prototype, 'readableFlowing', { // Exposed for testing purposes only. Readable._fromList = fromList; -Object.defineProperty(Readable.prototype, 'readableLength', { +ObjectDefineProperty(Readable.prototype, 'readableLength', { // Making it explicit this property is not enumerable // because otherwise some prototype manipulation in // userland will fail @@ -1137,14 +1140,14 @@ Object.defineProperty(Readable.prototype, 'readableLength', { } }); -Object.defineProperty(Readable.prototype, 'readableObjectMode', { +ObjectDefineProperty(Readable.prototype, 'readableObjectMode', { enumerable: false, get() { return this._readableState ? this._readableState.objectMode : false; } }); -Object.defineProperty(Readable.prototype, 'readableEncoding', { +ObjectDefineProperty(Readable.prototype, 'readableEncoding', { enumerable: false, get() { return this._readableState ? this._readableState.encoding : null; -- cgit v1.2.3