Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: add globalThis to primordials #38211

Merged
merged 1 commit into from
Apr 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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