From 8684dae8d9844dc7a3de88dd07339d50f547e313 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Sun, 1 Jan 2023 12:22:29 -0500 Subject: [PATCH] lib: fix incorrect use of console intrinsic MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The console object was not being frozen because the intrinsic freezing code was accessing undefined instead of the console object. PR-URL: https://github.com/nodejs/node/pull/46044 Reviewed-By: Yagiz Nizipli Reviewed-By: Filip Skokan Reviewed-By: Tobias Nießen Reviewed-By: Antoine du Hamel Reviewed-By: Darshan Sen Reviewed-By: Juan José Arboleda Reviewed-By: Luigi Pinca --- lib/internal/freeze_intrinsics.js | 2 +- test/parallel/test-freeze-intrinsics.js | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/internal/freeze_intrinsics.js b/lib/internal/freeze_intrinsics.js index 508b071c7c0f88..02732ea4cad88d 100644 --- a/lib/internal/freeze_intrinsics.js +++ b/lib/internal/freeze_intrinsics.js @@ -135,7 +135,7 @@ const { module.exports = function() { const { Console } = require('internal/console/constructor'); - const { console } = require('internal/console/global'); + const console = require('internal/console/global'); const { clearImmediate, clearInterval, diff --git a/test/parallel/test-freeze-intrinsics.js b/test/parallel/test-freeze-intrinsics.js index 978a6861a517fc..4e20346a9deda8 100644 --- a/test/parallel/test-freeze-intrinsics.js +++ b/test/parallel/test-freeze-intrinsics.js @@ -37,3 +37,12 @@ assert.throws( { name: 'TypeError' }); assert.strictEqual(globalThis.globalThis, globalThis); } + +// Ensure that we cannot override console properties. +{ + const { log } = console; + + assert.throws(() => { console.log = null; }, + { name: 'TypeError' }); + assert.strictEqual(console.log, log); +}