diff options
Diffstat (limited to 'lib/internal/fs')
-rw-r--r-- | lib/internal/fs/dir.js | 6 | ||||
-rw-r--r-- | lib/internal/fs/promises.js | 11 | ||||
-rw-r--r-- | lib/internal/fs/read_file_context.js | 6 | ||||
-rw-r--r-- | lib/internal/fs/streams.js | 24 | ||||
-rw-r--r-- | lib/internal/fs/sync_write_stream.js | 8 | ||||
-rw-r--r-- | lib/internal/fs/utils.js | 15 | ||||
-rw-r--r-- | lib/internal/fs/watchers.js | 15 |
7 files changed, 52 insertions, 33 deletions
diff --git a/lib/internal/fs/dir.js b/lib/internal/fs/dir.js index 90ab31fe5a..c4e0a3746c 100644 --- a/lib/internal/fs/dir.js +++ b/lib/internal/fs/dir.js @@ -1,6 +1,8 @@ 'use strict'; -const { Object } = primordials; +const { + ObjectDefineProperty, +} = primordials; const pathModule = require('path'); const binding = internalBinding('fs'); @@ -172,7 +174,7 @@ class Dir { } } -Object.defineProperty(Dir.prototype, Symbol.asyncIterator, { +ObjectDefineProperty(Dir.prototype, Symbol.asyncIterator, { value: Dir.prototype.entries, enumerable: false, writable: true, diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js index 31613780a7..a4ac18ba45 100644 --- a/lib/internal/fs/promises.js +++ b/lib/internal/fs/promises.js @@ -1,6 +1,9 @@ 'use strict'; -const { Math } = primordials; +const { + MathMax, + MathMin, +} = primordials; const { F_OK, @@ -134,7 +137,7 @@ async function writeFileHandle(filehandle, data, options) { do { const { bytesWritten } = await write(filehandle, buffer, 0, - Math.min(16384, buffer.length)); + MathMin(16384, buffer.length)); remaining -= bytesWritten; buffer = buffer.slice(bytesWritten); } while (remaining > 0); @@ -160,7 +163,7 @@ async function readFileHandle(filehandle, options) { const chunks = []; const chunkSize = size === 0 ? kReadFileMaxChunkSize : - Math.min(size, kReadFileMaxChunkSize); + MathMin(size, kReadFileMaxChunkSize); let endOfFile = false; do { const buf = Buffer.alloc(chunkSize); @@ -299,7 +302,7 @@ async function truncate(path, len = 0) { async function ftruncate(handle, len = 0) { validateFileHandle(handle); validateInteger(len, 'len'); - len = Math.max(0, len); + len = MathMax(0, len); return binding.ftruncate(handle.fd, len, kUsePromises); } diff --git a/lib/internal/fs/read_file_context.js b/lib/internal/fs/read_file_context.js index e1de8fc7cd..d7b0e36800 100644 --- a/lib/internal/fs/read_file_context.js +++ b/lib/internal/fs/read_file_context.js @@ -1,6 +1,8 @@ 'use strict'; -const { Math } = primordials; +const { + MathMin, +} = primordials; const { Buffer } = require('buffer'); @@ -87,7 +89,7 @@ class ReadFileContext { } else { buffer = this.buffer; offset = this.pos; - length = Math.min(kReadFileBufferLength, this.size - this.pos); + length = MathMin(kReadFileBufferLength, this.size - this.pos); } const req = new FSReqCallback(); 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 }); diff --git a/lib/internal/fs/sync_write_stream.js b/lib/internal/fs/sync_write_stream.js index 522bfc829d..7d1209ba2d 100644 --- a/lib/internal/fs/sync_write_stream.js +++ b/lib/internal/fs/sync_write_stream.js @@ -1,6 +1,8 @@ 'use strict'; -const { Object } = primordials; +const { + ObjectSetPrototypeOf, +} = primordials; const { Writable } = require('stream'); const { closeSync, writeSync } = require('fs'); @@ -15,8 +17,8 @@ function SyncWriteStream(fd, options) { this.autoClose = options.autoClose === undefined ? true : options.autoClose; } -Object.setPrototypeOf(SyncWriteStream.prototype, Writable.prototype); -Object.setPrototypeOf(SyncWriteStream, Writable); +ObjectSetPrototypeOf(SyncWriteStream.prototype, Writable.prototype); +ObjectSetPrototypeOf(SyncWriteStream, Writable); SyncWriteStream.prototype._write = function(chunk, encoding, cb) { writeSync(this.fd, chunk, 0, chunk.length); diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js index 3324ec5080..6a4717e664 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -1,6 +1,9 @@ 'use strict'; -const { Object, Reflect } = primordials; +const { + ObjectSetPrototypeOf, + ReflectOwnKeys, +} = primordials; const { Buffer } = require('buffer'); const { @@ -118,7 +121,7 @@ class DirentFromStats extends Dirent { } } -for (const name of Reflect.ownKeys(Dirent.prototype)) { +for (const name of ReflectOwnKeys(Dirent.prototype)) { if (name === 'constructor') { continue; } @@ -353,8 +356,8 @@ function BigIntStats(dev, mode, nlink, uid, gid, rdev, blksize, this.birthtime = dateFromMs(this.birthtimeMs); } -Object.setPrototypeOf(BigIntStats.prototype, StatsBase.prototype); -Object.setPrototypeOf(BigIntStats, StatsBase); +ObjectSetPrototypeOf(BigIntStats.prototype, StatsBase.prototype); +ObjectSetPrototypeOf(BigIntStats, StatsBase); BigIntStats.prototype._checkModeProperty = function(property) { if (isWindows && (property === S_IFIFO || property === S_IFBLK || @@ -379,8 +382,8 @@ function Stats(dev, mode, nlink, uid, gid, rdev, blksize, this.birthtime = dateFromMs(birthtimeMs); } -Object.setPrototypeOf(Stats.prototype, StatsBase.prototype); -Object.setPrototypeOf(Stats, StatsBase); +ObjectSetPrototypeOf(Stats.prototype, StatsBase.prototype); +ObjectSetPrototypeOf(Stats, StatsBase); // HACK: Workaround for https://github.com/standard-things/esm/issues/821. // TODO(ronag): Remove this as soon as `esm` publishes a fixed version. diff --git a/lib/internal/fs/watchers.js b/lib/internal/fs/watchers.js index 0685bcef4d..c94739d718 100644 --- a/lib/internal/fs/watchers.js +++ b/lib/internal/fs/watchers.js @@ -1,6 +1,9 @@ 'use strict'; -const { Object } = primordials; +const { + ObjectDefineProperty, + ObjectSetPrototypeOf, +} = primordials; const errors = require('internal/errors'); const { @@ -39,8 +42,8 @@ function StatWatcher(bigint) { this[kOldStatus] = -1; this[kUseBigint] = bigint; } -Object.setPrototypeOf(StatWatcher.prototype, EventEmitter.prototype); -Object.setPrototypeOf(StatWatcher, EventEmitter); +ObjectSetPrototypeOf(StatWatcher.prototype, EventEmitter.prototype); +ObjectSetPrototypeOf(StatWatcher, EventEmitter); function onchange(newStatus, stats) { const self = this[owner_symbol]; @@ -143,8 +146,8 @@ function FSWatcher() { } }; } -Object.setPrototypeOf(FSWatcher.prototype, EventEmitter.prototype); -Object.setPrototypeOf(FSWatcher, EventEmitter); +ObjectSetPrototypeOf(FSWatcher.prototype, EventEmitter.prototype); +ObjectSetPrototypeOf(FSWatcher, EventEmitter); // At the moment if filename is undefined, we // 1. Throw an Error if it's the first time Symbol('kFSWatchStart') is called @@ -210,7 +213,7 @@ function emitCloseNT(self) { // Legacy alias on the C++ wrapper object. This is not public API, so we may // want to runtime-deprecate it at some point. There's no hurry, though. -Object.defineProperty(FSEvent.prototype, 'owner', { +ObjectDefineProperty(FSEvent.prototype, 'owner', { get() { return this[owner_symbol]; }, set(v) { return this[owner_symbol] = v; } }); |