tools: add `console` to the list of restricted globals

PR-URL: https://github.com/nodejs/node/pull/42012
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Mestery <mestery@protonmail.com>
This commit is contained in:
Antoine du Hamel 2022-02-19 20:00:55 +01:00 committed by GitHub
parent 246227f4bc
commit 53364a2ec6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 5 deletions

View File

@ -93,6 +93,8 @@ rules:
message: Use `const { clearInterval } = require('timers');` instead of the global.
- name: clearTimeout
message: Use `const { clearTimeout } = require('timers');` instead of the global.
- name: console
message: Use `const { console } = require('internal/console/global');` instead of the global.
- name: crypto
message: Use `const { crypto } = require('internal/crypto/webcrypto');` instead of the global.
- name: Crypto

View File

@ -19,7 +19,6 @@
// https://github.com/google/caja/blob/HEAD/src/com/google/caja/ses/repairES5.js
// https://github.com/tc39/proposal-ses/blob/e5271cc42a257a05dcae2fd94713ed2f46c08620/shim/src/freeze.js
/* global console */
'use strict';
const {
@ -133,6 +132,8 @@ const {
} = globalThis;
module.exports = function() {
const { Console } = require('internal/console/constructor');
const { console } = require('internal/console/global');
const {
clearImmediate,
clearInterval,
@ -216,7 +217,7 @@ module.exports = function() {
PromisePrototype, // 27.2
// Other APIs / Web Compatibility
console.Console.prototype,
Console.prototype,
WebAssembly.Module.prototype,
WebAssembly.Instance.prototype,
WebAssembly.Table.prototype,

View File

@ -27,7 +27,7 @@
'use strict';
/* eslint-disable node-core/prefer-primordials */
/* eslint-disable node-core/prefer-primordials, no-restricted-globals */
/* global console */
module.exports = { versionCheck };
@ -73,7 +73,6 @@ 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);
@ -163,7 +162,6 @@ function macCppfiltNm(out) {
});
}
// eslint-disable-next-line no-restricted-globals
Object.assign(globalThis, {
os,
print,