From bbdf285a39db7e1f19dc0da8f93361f23d419f38 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 19 Feb 2022 20:00:55 +0100 Subject: [PATCH] tools: add `console` to the list of restricted globals PR-URL: https://github.com/nodejs/node/pull/42012 Reviewed-By: Benjamin Gruenbaum Reviewed-By: James M Snell Reviewed-By: Mestery --- lib/.eslintrc.yaml | 2 ++ lib/internal/freeze_intrinsics.js | 5 +++-- lib/internal/v8_prof_polyfill.js | 4 +--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/.eslintrc.yaml b/lib/.eslintrc.yaml index 28c090cc098006..f155525b817d1e 100644 --- a/lib/.eslintrc.yaml +++ b/lib/.eslintrc.yaml @@ -89,6 +89,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 diff --git a/lib/internal/freeze_intrinsics.js b/lib/internal/freeze_intrinsics.js index ea613966980c96..82720f0ef95aba 100644 --- a/lib/internal/freeze_intrinsics.js +++ b/lib/internal/freeze_intrinsics.js @@ -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, diff --git a/lib/internal/v8_prof_polyfill.js b/lib/internal/v8_prof_polyfill.js index 21d9b932c10f4b..f4d9380ea810e6 100644 --- a/lib/internal/v8_prof_polyfill.js +++ b/lib/internal/v8_prof_polyfill.js @@ -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,