From 347db7a27f7e78d5e86f205127845e40bdc6148b Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Wed, 16 Feb 2022 11:41:25 +0100 Subject: [PATCH] tools: add `console` to the list of restricted globals --- 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 86d1438cd93723..1f927389d89dbf 100644 --- a/lib/.eslintrc.yaml +++ b/lib/.eslintrc.yaml @@ -79,6 +79,8 @@ rules: message: Use `const { atob } = require('buffer');` instead of the global. - name: btoa message: Use `const { btoa } = require('buffer');` 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,