lib: add globalThis to primordials

PR-URL: https://github.com/nodejs/node/pull/38211
Backport-PR-URL: https://github.com/nodejs/node/pull/39448
Reviewed-By: Bradley Farias <bradley.meck@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Antoine du Hamel authored and Richard Lau committed 2021-07-20 07:11:41 -04:00
1 parent 1ab4f81abc
commit ea9003a559
6 files changed
+22

No files matched your search

+4
View File
@@ -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
+1
View File
@@ -9,6 +9,7 @@ const {
RegExpPrototypeExec,
SafeWeakMap,
StringPrototypeStartsWith,
globalThis,
} = primordials;
const {
+8
View File
@@ -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,
+4
View File
@@ -1,5 +1,9 @@
'use strict';
const {
globalThis,
} = primordials;
const path = require('path');
const {
+4
View File
@@ -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');
+1
View File
@@ -6,6 +6,7 @@ const {
SafeSet,
SafeWeakMap,
SymbolIterator,
globalThis,
} = primordials;
// TODO(aduh95): Add FinalizationRegistry to primordials