Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7692d2e

Browse filesBrowse files
daeyeonMoLow
authored andcommitted
cluster: use ObjectPrototypeHasOwnProperty
Signed-off-by: Daeyeon Jeong <daeyeon.dev@gmail.com> PR-URL: #48141 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
1 parent 230335e commit 7692d2e
Copy full SHA for 7692d2e

File tree

Expand file treeCollapse file tree

2 files changed

+20
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

2 files changed

+20
-3
lines changed
Open diff view settings
Collapse file

‎lib/cluster.js‎

Copy file name to clipboardExpand all lines: lib/cluster.js
+5-1Lines changed: 5 additions & 1 deletion
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}`);
Collapse file

‎test/parallel/test-cluster-basic.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-cluster-basic.js
+15-2Lines changed: 15 additions & 2 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.