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 69eaff1

Browse filesBrowse files
addaleaxtargos
authored andcommitted
lib: move initialization of APIs for changing process state
Whether these APIs should be available for Node.js instances semantically depends on whether the current Node.js instance was assigned ownership of process-wide state, and not whether it refers to the main thread or not. PR-URL: #31172 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com>
1 parent ff47915 commit 69eaff1
Copy full SHA for 69eaff1

File tree

Expand file treeCollapse file tree

4 files changed

+55
-56
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

4 files changed

+55
-56
lines changed
Open diff view settings
Collapse file
+21-3Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
'use strict';
22

33
const credentials = internalBinding('credentials');
4+
const rawMethods = internalBinding('process_methods');
5+
// TODO: this should be detached from ERR_WORKER_UNSUPPORTED_OPERATION
6+
const { unavailable } = require('internal/process/worker_thread_only');
47

5-
if (credentials.implementsPosixCredentials) {
6-
// TODO: this should be detached from ERR_WORKER_UNSUPPORTED_OPERATION
7-
const { unavailable } = require('internal/process/worker_thread_only');
8+
process.abort = unavailable('process.abort()');
9+
process.chdir = unavailable('process.chdir()');
10+
process.umask = wrappedUmask;
11+
process.cwd = rawMethods.cwd;
812

13+
if (credentials.implementsPosixCredentials) {
914
process.initgroups = unavailable('process.initgroups()');
1015
process.setgroups = unavailable('process.setgroups()');
1116
process.setegid = unavailable('process.setegid()');
@@ -16,3 +21,16 @@ if (credentials.implementsPosixCredentials) {
1621

1722
// ---- keep the attachment of the wrappers above so that it's easier to ----
1823
// ---- compare the setups side-by-side -----
24+
25+
const {
26+
codes: { ERR_WORKER_UNSUPPORTED_OPERATION }
27+
} = require('internal/errors');
28+
29+
function wrappedUmask(mask) {
30+
// process.umask() is a read-only operation in workers.
31+
if (mask !== undefined) {
32+
throw new ERR_WORKER_UNSUPPORTED_OPERATION('Setting process.umask()');
33+
}
34+
35+
return rawMethods.umask(mask);
36+
}
Collapse file

‎lib/internal/bootstrap/switches/does_own_process_state.js‎

Copy file name to clipboardExpand all lines: lib/internal/bootstrap/switches/does_own_process_state.js
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
'use strict';
22

33
const credentials = internalBinding('credentials');
4+
const rawMethods = internalBinding('process_methods');
5+
6+
process.abort = rawMethods.abort;
7+
process.umask = wrappedUmask;
8+
process.chdir = wrappedChdir;
9+
process.cwd = wrappedCwd;
410

511
if (credentials.implementsPosixCredentials) {
612
const wrapped = wrapPosixCredentialSetters(credentials);
@@ -16,6 +22,11 @@ if (credentials.implementsPosixCredentials) {
1622
// ---- keep the attachment of the wrappers above so that it's easier to ----
1723
// ---- compare the setups side-by-side -----
1824

25+
const {
26+
parseMode,
27+
validateString
28+
} = require('internal/validators');
29+
1930
function wrapPosixCredentialSetters(credentials) {
2031
const {
2132
ArrayIsArray,
@@ -94,3 +105,26 @@ function wrapPosixCredentialSetters(credentials) {
94105
setuid: wrapIdSetter('User', _setuid)
95106
};
96107
}
108+
109+
// Cache the working directory to prevent lots of lookups. If the working
110+
// directory is changed by `chdir`, it'll be updated.
111+
let cachedCwd = '';
112+
113+
function wrappedChdir(directory) {
114+
validateString(directory, 'directory');
115+
rawMethods.chdir(directory);
116+
// Mark cache that it requires an update.
117+
cachedCwd = '';
118+
}
119+
120+
function wrappedUmask(mask) {
121+
if (mask !== undefined) {
122+
mask = parseMode(mask, 'mask');
123+
}
124+
return rawMethods.umask(mask);
125+
}
126+
127+
function wrappedCwd() {
128+
cachedCwd = rawMethods.cwd();
129+
return cachedCwd;
130+
}
Collapse file

‎lib/internal/bootstrap/switches/is_main_thread.js‎

Copy file name to clipboardExpand all lines: lib/internal/bootstrap/switches/is_main_thread.js
-32Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@
33
const { ObjectDefineProperty } = primordials;
44
const rawMethods = internalBinding('process_methods');
55

6-
process.abort = rawMethods.abort;
7-
process.umask = wrappedUmask;
8-
process.chdir = wrappedChdir;
9-
process.cwd = wrappedCwd;
10-
116
// TODO(joyeecheung): deprecate and remove these underscore methods
127
process._debugProcess = rawMethods._debugProcess;
138
process._debugEnd = rawMethods._debugEnd;
@@ -38,33 +33,6 @@ process.on('removeListener', stopListeningIfSignal);
3833
// ---- compare the setups side-by-side -----
3934

4035
const { guessHandleType } = internalBinding('util');
41-
const {
42-
parseMode,
43-
validateString
44-
} = require('internal/validators');
45-
46-
// Cache the working directory to prevent lots of lookups. If the working
47-
// directory is changed by `chdir`, it'll be updated.
48-
let cachedCwd = '';
49-
50-
function wrappedChdir(directory) {
51-
validateString(directory, 'directory');
52-
rawMethods.chdir(directory);
53-
// Mark cache that it requires an update.
54-
cachedCwd = '';
55-
}
56-
57-
function wrappedUmask(mask) {
58-
if (mask !== undefined) {
59-
mask = parseMode(mask, 'mask');
60-
}
61-
return rawMethods.umask(mask);
62-
}
63-
64-
function wrappedCwd() {
65-
cachedCwd = rawMethods.cwd();
66-
return cachedCwd;
67-
}
6836

6937
function createWritableStdioStream(fd) {
7038
let stream;
Collapse file

‎lib/internal/bootstrap/switches/is_not_main_thread.js‎

Copy file name to clipboardExpand all lines: lib/internal/bootstrap/switches/is_not_main_thread.js
-21Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
'use strict';
22

33
const { ObjectDefineProperty } = primordials;
4-
const rawMethods = internalBinding('process_methods');
5-
const {
6-
unavailable
7-
} = require('internal/process/worker_thread_only');
8-
9-
process.abort = unavailable('process.abort()');
10-
process.chdir = unavailable('process.chdir()');
11-
process.umask = wrappedUmask;
12-
process.cwd = rawMethods.cwd;
134

145
delete process._debugProcess;
156
delete process._debugEnd;
@@ -42,9 +33,6 @@ process.removeListener('removeListener', stopListeningIfSignal);
4233
const {
4334
createWorkerStdio
4435
} = require('internal/worker/io');
45-
const {
46-
codes: { ERR_WORKER_UNSUPPORTED_OPERATION }
47-
} = require('internal/errors');
4836

4937
let workerStdio;
5038
function lazyWorkerStdio() {
@@ -57,12 +45,3 @@ function getStdout() { return lazyWorkerStdio().stdout; }
5745
function getStderr() { return lazyWorkerStdio().stderr; }
5846

5947
function getStdin() { return lazyWorkerStdio().stdin; }
60-
61-
function wrappedUmask(mask) {
62-
// process.umask() is a read-only operation in workers.
63-
if (mask !== undefined) {
64-
throw new ERR_WORKER_UNSUPPORTED_OPERATION('Setting process.umask()');
65-
}
66-
67-
return rawMethods.umask(mask);
68-
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.