Skip to content

Commit

Permalink
lib: fix incorrect use of console intrinsic
Browse files Browse the repository at this point in the history
The console object was not being frozen because the intrinsic
freezing code was accessing undefined instead of the console
object.

PR-URL: nodejs#46044
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
  • Loading branch information
cjihrig authored and RafaelGSS committed Jan 17, 2023
1 parent f369b5f commit c34f9da
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/internal/freeze_intrinsics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 9 additions & 0 deletions test/parallel/test-freeze-intrinsics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

0 comments on commit c34f9da

Please sign in to comment.