mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
cluster: use ObjectPrototypeHasOwnProperty
Signed-off-by: Daeyeon Jeong <daeyeon.dev@gmail.com> PR-URL: https://github.com/nodejs/node/pull/48141 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
This commit is contained in:
parent
00fcff575e
commit
b4d5f1f26d
|
|
@ -21,5 +21,9 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const childOrPrimary = 'NODE_UNIQUE_ID' in process.env ? 'child' : 'primary';
|
const {
|
||||||
|
ObjectPrototypeHasOwnProperty: ObjectHasOwn,
|
||||||
|
} = primordials;
|
||||||
|
|
||||||
|
const childOrPrimary = ObjectHasOwn(process.env, 'NODE_UNIQUE_ID') ? 'child' : 'primary';
|
||||||
module.exports = require(`internal/cluster/${childOrPrimary}`);
|
module.exports = require(`internal/cluster/${childOrPrimary}`);
|
||||||
|
|
|
||||||
|
|
@ -22,13 +22,26 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
const common = require('../common');
|
const common = require('../common');
|
||||||
|
|
||||||
const assert = require('assert');
|
const assert = require('node:assert');
|
||||||
const cluster = require('cluster');
|
const cluster = require('node:cluster');
|
||||||
|
const { spawnSync } = require('node:child_process');
|
||||||
|
|
||||||
assert.strictEqual('NODE_UNIQUE_ID' in process.env, false,
|
assert.strictEqual('NODE_UNIQUE_ID' in process.env, false,
|
||||||
`NODE_UNIQUE_ID (${process.env.NODE_UNIQUE_ID}) ` +
|
`NODE_UNIQUE_ID (${process.env.NODE_UNIQUE_ID}) ` +
|
||||||
'should be removed on startup');
|
'should be removed on startup');
|
||||||
|
|
||||||
|
{
|
||||||
|
const { status } = spawnSync(process.execPath, [
|
||||||
|
'-e',
|
||||||
|
`
|
||||||
|
const { strictEqual } = require('node:assert');
|
||||||
|
Object.setPrototypeOf(process.env, { NODE_UNIQUE_ID: 0 });
|
||||||
|
strictEqual(require('cluster').isPrimary, true);
|
||||||
|
`,
|
||||||
|
]);
|
||||||
|
assert.strictEqual(status, 0);
|
||||||
|
}
|
||||||
|
|
||||||
function forEach(obj, fn) {
|
function forEach(obj, fn) {
|
||||||
Object.keys(obj).forEach((name, index) => {
|
Object.keys(obj).forEach((name, index) => {
|
||||||
fn(obj[name], name, index);
|
fn(obj[name], name, index);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user