Skip to content

Commit

Permalink
lib: add globalThis to primordials
Browse files Browse the repository at this point in the history
PR-URL: nodejs#38211
Reviewed-By: Bradley Farias <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
aduh95 committed Apr 13, 2021
1 parent 8021710 commit 23d2c54
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/.eslintrc.yaml
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,14 @@ function copyPrototype(src, dest, prefix) {
}
}

// 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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions lib/internal/v8_prof_polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ function read(fileName) {
}
const quit = process.exit;
// Polyfill "readline()".
// eslint-disable-next-line no-restricted-globals
const logFile = globalThis.arguments[globalThis.arguments.length - 1];
try {
fs.accessSync(logFile);
Expand Down Expand Up @@ -161,6 +162,7 @@ function macCppfiltNm(out) {
});
}

// eslint-disable-next-line no-restricted-globals
Object.assign(globalThis, {
os,
print,
Expand Down

0 comments on commit 23d2c54

Please sign in to comment.