Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 70773a6

Browse files
aduh95foxxyz
authored andcommittedOct 18, 2021
lib: add globalThis to primordials
PR-URL: nodejs#38211 Backport-PR-URL: nodejs#39448 Reviewed-By: Bradley Farias <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 72c0c71 commit 70773a6

File tree

6 files changed

+22
-0
lines changed

6 files changed

+22
-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
@@ -171,6 +171,14 @@ primordials.SafeWeakSet = makeSafe(
171171
}
172172
);
173173

174+
// Create copies of configurable value properties of the global object
175+
[
176+
'globalThis',
177+
].forEach((name) => {
178+
// eslint-disable-next-line no-restricted-globals
179+
primordials[name] = globalThis[name];
180+
});
181+
174182
// Create copies of URI handling functions
175183
[
176184
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/util/iterable_weak_map.js

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const {
66
SafeSet,
77
SafeWeakMap,
88
SymbolIterator,
9+
globalThis,
910
} = primordials;
1011

1112
// TODO(aduh95): Add FinalizationRegistry to primordials

0 commit comments

Comments
 (0)
Please sign in to comment.