GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — cluster: use ObjectPrototypeHasOwnProperty · nodejs/node@6cf2adc

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • cluster.js
  • test/parallel
    • test-cluster-basic.js
Expand file treeCollapse file tree
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)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.