Skip to content

Commit 167fb56

Browse files
daeyeonCeres6
authored andcommitted
cluster: use ObjectPrototypeHasOwnProperty
Signed-off-by: Daeyeon Jeong <[email protected]> PR-URL: nodejs#48141 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]>
1 parent 1605c76 commit 167fb56

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

lib/cluster.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,9 @@
2121

2222
'use strict';
2323

24-
const childOrPrimary = 'NODE_UNIQUE_ID' in process.env ? 'child' : 'primary';
24+
const {
25+
ObjectPrototypeHasOwnProperty: ObjectHasOwn,
26+
} = primordials;
27+
28+
const childOrPrimary = ObjectHasOwn(process.env, 'NODE_UNIQUE_ID') ? 'child' : 'primary';
2529
module.exports = require(`internal/cluster/${childOrPrimary}`);

test/parallel/test-cluster-basic.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,26 @@
2222
'use strict';
2323
const common = require('../common');
2424

25-
const assert = require('assert');
26-
const cluster = require('cluster');
25+
const assert = require('node:assert');
26+
const cluster = require('node:cluster');
27+
const { spawnSync } = require('node:child_process');
2728

2829
assert.strictEqual('NODE_UNIQUE_ID' in process.env, false,
2930
`NODE_UNIQUE_ID (${process.env.NODE_UNIQUE_ID}) ` +
3031
'should be removed on startup');
3132

33+
{
34+
const { status } = spawnSync(process.execPath, [
35+
'-e',
36+
`
37+
const { strictEqual } = require('node:assert');
38+
Object.setPrototypeOf(process.env, { NODE_UNIQUE_ID: 0 });
39+
strictEqual(require('cluster').isPrimary, true);
40+
`,
41+
]);
42+
assert.strictEqual(status, 0);
43+
}
44+
3245
function forEach(obj, fn) {
3346
Object.keys(obj).forEach((name, index) => {
3447
fn(obj[name], name, index);

0 commit comments

Comments
 (0)