diff options
author | Michaël Zasso <targos@protonmail.com> | 2019-11-22 20:04:46 +0300 |
---|---|---|
committer | Michaël Zasso <targos@protonmail.com> | 2019-11-25 12:28:15 +0300 |
commit | 0646eda4fc0affb98e13c30acb522e63b7fd6dde (patch) | |
tree | 078209f50b044e24ea2c72cbbe7dca6e34bb7e25 /lib/internal/cluster | |
parent | 35c6e0cc2b56a5380e6808ef5603ecc2b167e032 (diff) |
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/cluster')
-rw-r--r-- | lib/internal/cluster/child.js | 6 | ||||
-rw-r--r-- | lib/internal/cluster/master.js | 13 | ||||
-rw-r--r-- | lib/internal/cluster/worker.js | 4 |
3 files changed, 13 insertions, 10 deletions
diff --git a/lib/internal/cluster/child.js b/lib/internal/cluster/child.js index 097c6dafae0..9f63b1a1da4 100644 --- a/lib/internal/cluster/child.js +++ b/lib/internal/cluster/child.js @@ -1,6 +1,8 @@ 'use strict'; -const { Object } = primordials; +const { + ObjectAssign, +} = primordials; const assert = require('internal/assert'); const path = require('path'); @@ -154,7 +156,7 @@ function rr(message, indexesKey, cb) { function getsockname(out) { if (key) - Object.assign(out, message.sockname); + ObjectAssign(out, message.sockname); return 0; } diff --git a/lib/internal/cluster/master.js b/lib/internal/cluster/master.js index 645d8f1bd89..bee224a67d9 100644 --- a/lib/internal/cluster/master.js +++ b/lib/internal/cluster/master.js @@ -1,6 +1,9 @@ 'use strict'; -const { Object } = primordials; +const { + ObjectKeys, + ObjectValues, +} = primordials; const assert = require('internal/assert'); const { fork } = require('child_process'); @@ -82,7 +85,7 @@ cluster.setupMaster = function(options) { if (message.cmd !== 'NODE_DEBUG_ENABLED') return; - for (const worker of Object.values(cluster.workers)) { + for (const worker of ObjectValues(cluster.workers)) { if (worker.state === 'online' || worker.state === 'listening') { process._debugProcess(worker.process.pid); } else { @@ -144,7 +147,7 @@ function removeWorker(worker) { assert(worker); delete cluster.workers[worker.id]; - if (Object.keys(cluster.workers).length === 0) { + if (ObjectKeys(cluster.workers).length === 0) { assert(handles.size === 0, 'Resource leak detected.'); intercom.emit('disconnect'); } @@ -222,12 +225,12 @@ function emitForkNT(worker) { } cluster.disconnect = function(cb) { - const workers = Object.keys(cluster.workers); + const workers = ObjectKeys(cluster.workers); if (workers.length === 0) { process.nextTick(() => intercom.emit('disconnect')); } else { - for (const worker of Object.values(cluster.workers)) { + for (const worker of ObjectValues(cluster.workers)) { if (worker.isConnected()) { worker.disconnect(); } diff --git a/lib/internal/cluster/worker.js b/lib/internal/cluster/worker.js index 4563b2e663b..516b7a3b73d 100644 --- a/lib/internal/cluster/worker.js +++ b/lib/internal/cluster/worker.js @@ -1,9 +1,7 @@ 'use strict'; const { - Object: { - setPrototypeOf: ObjectSetPrototypeOf - } + ObjectSetPrototypeOf, } = primordials; const EventEmitter = require('events'); |