process: stub unsupported worker methods · nodejs/node@d7ed125 · GitHub
Skip to content

Commit d7ed125

Browse files
cjihrigtargos
authored andcommitted
process: stub unsupported worker methods
Some process methods are not supported in workers. This commit adds stubs that throw more informative errors. PR-URL: #25587 Fixes: #25448 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 01bb7b7 commit d7ed125

7 files changed

Lines changed: 83 additions & 25 deletions

File tree

lib/internal/bootstrap/node.js

Lines changed: 28 additions & 2 deletions

lib/internal/process/worker_thread_only.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,17 @@ function wrapProcessMethods(binding) {
4545
return { umask };
4646
}
4747

48+
function unavailable(name) {
49+
function unavailableInWorker() {
50+
throw new ERR_WORKER_UNSUPPORTED_OPERATION(name);
51+
}
52+
53+
unavailableInWorker.disabled = true;
54+
return unavailableInWorker;
55+
}
56+
4857
module.exports = {
4958
initializeWorkerStdio,
59+
unavailable,
5060
wrapProcessMethods
5161
};

test/parallel/test-process-euid-egid.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,17 @@
33
const common = require('../common');
44
const assert = require('assert');
55

6-
if (common.isWindows || !common.isMainThread) {
7-
if (common.isMainThread) {
8-
assert.strictEqual(process.geteuid, undefined);
9-
assert.strictEqual(process.getegid, undefined);
10-
}
6+
if (common.isWindows) {
7+
assert.strictEqual(process.geteuid, undefined);
8+
assert.strictEqual(process.getegid, undefined);
119
assert.strictEqual(process.seteuid, undefined);
1210
assert.strictEqual(process.setegid, undefined);
1311
return;
1412
}
1513

14+
if (!common.isMainThread)
15+
return;
16+
1617
assert.throws(() => {
1718
process.seteuid({});
1819
}, {

test/parallel/test-process-initgroups.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
const common = require('../common');
33
const assert = require('assert');
44

5-
if (common.isWindows || !common.isMainThread) {
5+
if (common.isWindows) {
66
assert.strictEqual(process.initgroups, undefined);
77
return;
88
}
99

10+
if (!common.isMainThread)
11+
return;
12+
1013
[undefined, null, true, {}, [], () => {}].forEach((val) => {
1114
assert.throws(
1215
() => {

test/parallel/test-process-setgroups.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
const common = require('../common');
33
const assert = require('assert');
44

5-
if (common.isWindows || !common.isMainThread) {
5+
if (common.isWindows) {
66
assert.strictEqual(process.setgroups, undefined);
77
return;
88
}
99

10+
if (!common.isMainThread)
11+
return;
12+
1013
assert.throws(
1114
() => {
1215
process.setgroups();

test/parallel/test-process-uid-gid.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,18 @@ const common = require('../common');
2424

2525
const assert = require('assert');
2626

27-
if (common.isWindows || !common.isMainThread) {
28-
// uid/gid functions are POSIX only, setters are main-thread only.
29-
if (common.isMainThread) {
30-
assert.strictEqual(process.getuid, undefined);
31-
assert.strictEqual(process.getgid, undefined);
32-
}
27+
if (common.isWindows) {
28+
// uid/gid functions are POSIX only.
29+
assert.strictEqual(process.getuid, undefined);
30+
assert.strictEqual(process.getgid, undefined);
3331
assert.strictEqual(process.setuid, undefined);
3432
assert.strictEqual(process.setgid, undefined);
3533
return;
3634
}
3735

36+
if (!common.isMainThread)
37+
return;
38+
3839
assert.throws(() => {
3940
process.setuid({});
4041
}, {

test/parallel/test-worker-unsupported-things.js

Lines changed: 24 additions & 10 deletions

0 commit comments

Comments
 (0)