Skip to content

Commit 23d2c54

Browse files
committed
lib: add globalThis to primordials
PR-URL: nodejs#38211 Reviewed-By: Bradley Farias <bradley.meck@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 8021710 commit 23d2c54

File tree

6 files changed

+23
-0
lines changed

6 files changed

+23
-0
lines changed

lib/.eslintrc.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ rules:
2525
message: "Please use `require('internal/errors').hideStackFrames()` instead."
2626
- selector: "AssignmentExpression:matches([left.name='prepareStackTrace'], [left.property.name='prepareStackTrace'])"
2727
message: "Use 'overrideStackTrace' from 'lib/internal/errors.js' instead of 'Error.prepareStackTrace'."
28+
no-restricted-globals:
29+
- error
30+
- name: globalThis
31+
message: "Use `const { globalThis } = primordials;` instead of the global."
2832
# Custom rules in tools/eslint-rules
2933
node-core/lowercase-name-for-primitive: error
3034
node-core/non-ascii-character: error

lib/internal/modules/esm/loader.js

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const {
99
RegExpPrototypeExec,
1010
SafeWeakMap,
1111
StringPrototypeStartsWith,
12+
globalThis,
1213
} = primordials;
1314

1415
const {

lib/internal/per_context/primordials.js

+8
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ function copyPrototype(src, dest, prefix) {
131131
}
132132
}
133133

134+
// Create copies of configurable value properties of the global object
135+
[
136+
'globalThis',
137+
].forEach((name) => {
138+
// eslint-disable-next-line no-restricted-globals
139+
primordials[name] = globalThis[name];
140+
});
141+
134142
// Create copies of URI handling functions
135143
[
136144
decodeURI,

lib/internal/process/execution.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
'use strict';
22

3+
const {
4+
globalThis,
5+
} = primordials;
6+
37
const path = require('path');
48

59
const {

lib/internal/test/binding.js

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
'use strict';
22

3+
const {
4+
globalThis,
5+
} = primordials;
6+
37
process.emitWarning(
48
'These APIs are for internal testing only. Do not use them.',
59
'internal/test/binding');

lib/internal/v8_prof_polyfill.js

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ function read(fileName) {
7272
}
7373
const quit = process.exit;
7474
// Polyfill "readline()".
75+
// eslint-disable-next-line no-restricted-globals
7576
const logFile = globalThis.arguments[globalThis.arguments.length - 1];
7677
try {
7778
fs.accessSync(logFile);
@@ -161,6 +162,7 @@ function macCppfiltNm(out) {
161162
});
162163
}
163164

165+
// eslint-disable-next-line no-restricted-globals
164166
Object.assign(globalThis, {
165167
os,
166168
print,

0 commit comments

Comments
 (0)