Skip to content

Commit

Permalink
lib: add globalThis to primordials
Browse files Browse the repository at this point in the history
PR-URL: #38211
Backport-PR-URL: #39448
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
aduh95 authored and richardlau committed Jul 20, 2021
1 parent 1ab4f81 commit ea9003a
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/.eslintrc.yaml
Expand Up @@ -25,6 +25,10 @@ rules:
message: "Please use `require('internal/errors').hideStackFrames()` instead."
- selector: "AssignmentExpression:matches([left.name='prepareStackTrace'], [left.property.name='prepareStackTrace'])"
message: "Use 'overrideStackTrace' from 'lib/internal/errors.js' instead of 'Error.prepareStackTrace'."
no-restricted-globals:
- error
- name: globalThis
message: "Use `const { globalThis } = primordials;` instead of the global."
# Custom rules in tools/eslint-rules
node-core/lowercase-name-for-primitive: error
node-core/non-ascii-character: error
Expand Down
1 change: 1 addition & 0 deletions lib/internal/modules/esm/loader.js
Expand Up @@ -9,6 +9,7 @@ const {
RegExpPrototypeExec,
SafeWeakMap,
StringPrototypeStartsWith,
globalThis,
} = primordials;

const {
Expand Down
8 changes: 8 additions & 0 deletions lib/internal/per_context/primordials.js
Expand Up @@ -171,6 +171,14 @@ primordials.SafeWeakSet = makeSafe(
}
);

// Create copies of configurable value properties of the global object
[
'globalThis',
].forEach((name) => {
// eslint-disable-next-line no-restricted-globals
primordials[name] = globalThis[name];
});

// Create copies of URI handling functions
[
decodeURI,
Expand Down
4 changes: 4 additions & 0 deletions lib/internal/process/execution.js
@@ -1,5 +1,9 @@
'use strict';

const {
globalThis,
} = primordials;

const path = require('path');

const {
Expand Down
4 changes: 4 additions & 0 deletions lib/internal/test/binding.js
@@ -1,5 +1,9 @@
'use strict';

const {
globalThis,
} = primordials;

process.emitWarning(
'These APIs are for internal testing only. Do not use them.',
'internal/test/binding');
Expand Down
1 change: 1 addition & 0 deletions lib/internal/util/iterable_weak_map.js
Expand Up @@ -6,6 +6,7 @@ const {
SafeSet,
SafeWeakMap,
SymbolIterator,
globalThis,
} = primordials;

// TODO(aduh95): Add FinalizationRegistry to primordials
Expand Down

0 comments on commit ea9003a

Please sign in to comment.