diff options
author | Michaël Zasso <targos@protonmail.com> | 2019-11-22 18:04:46 +0100 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2019-11-25 10:28:15 +0100 |
commit | 0646eda4fc0affb98e13c30acb522e63b7fd6dde (patch) | |
tree | 078209f50b044e24ea2c72cbbe7dca6e34bb7e25 /lib/internal/fs/streams.js | |
parent | 35c6e0cc2b56a5380e6808ef5603ecc2b167e032 (diff) | |
download | android-node-v8-0646eda4fc0affb98e13c30acb522e63b7fd6dde.tar.gz android-node-v8-0646eda4fc0affb98e13c30acb522e63b7fd6dde.tar.bz2 android-node-v8-0646eda4fc0affb98e13c30acb522e63b7fd6dde.zip |
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 <anna@addaleax.net>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Diffstat (limited to 'lib/internal/fs/streams.js')
-rw-r--r-- | lib/internal/fs/streams.js | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/lib/internal/fs/streams.js b/lib/internal/fs/streams.js index 0eb90cfd6d..c8447191b5 100644 --- a/lib/internal/fs/streams.js +++ b/lib/internal/fs/streams.js @@ -1,6 +1,10 @@ 'use strict'; -const { Math, Object } = primordials; +const { + MathMin, + ObjectDefineProperty, + ObjectSetPrototypeOf, +} = primordials; const { ERR_OUT_OF_RANGE @@ -109,8 +113,8 @@ function ReadStream(path, options) { } }); } -Object.setPrototypeOf(ReadStream.prototype, Readable.prototype); -Object.setPrototypeOf(ReadStream, Readable); +ObjectSetPrototypeOf(ReadStream.prototype, Readable.prototype); +ObjectSetPrototypeOf(ReadStream, Readable); const openReadFs = internalUtil.deprecate(function() { _openReadFs(this); @@ -157,13 +161,13 @@ ReadStream.prototype._read = function(n) { // in the thread pool another read() finishes up the pool, and // allocates a new one. const thisPool = pool; - let toRead = Math.min(pool.length - pool.used, n); + let toRead = MathMin(pool.length - pool.used, n); const start = pool.used; if (this.pos !== undefined) - toRead = Math.min(this.end - this.pos + 1, toRead); + toRead = MathMin(this.end - this.pos + 1, toRead); else - toRead = Math.min(this.end - this.bytesRead + 1, toRead); + toRead = MathMin(this.end - this.bytesRead + 1, toRead); // Already read everything we were supposed to read! // treat as EOF. @@ -235,7 +239,7 @@ ReadStream.prototype.close = function(cb) { this.destroy(null, cb); }; -Object.defineProperty(ReadStream.prototype, 'pending', { +ObjectDefineProperty(ReadStream.prototype, 'pending', { get() { return this.fd === null; }, configurable: true }); @@ -280,8 +284,8 @@ function WriteStream(path, options) { if (typeof this.fd !== 'number') _openWriteFs(this); } -Object.setPrototypeOf(WriteStream.prototype, Writable.prototype); -Object.setPrototypeOf(WriteStream, Writable); +ObjectSetPrototypeOf(WriteStream.prototype, Writable.prototype); +ObjectSetPrototypeOf(WriteStream, Writable); WriteStream.prototype._final = function(callback) { if (typeof this.fd !== 'number') { @@ -406,7 +410,7 @@ WriteStream.prototype.close = function(cb) { // There is no shutdown() for files. WriteStream.prototype.destroySoon = WriteStream.prototype.end; -Object.defineProperty(WriteStream.prototype, 'pending', { +ObjectDefineProperty(WriteStream.prototype, 'pending', { get() { return this.fd === null; }, configurable: true }); |