forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
console: take care of console set undefined case
If global.console write undefined would come earlier than global.console read then lazy read in get would happen, despite write was done. This commit fix the problem. Fixes: nodejs#11805
- Loading branch information
Showing
2 changed files
with
29 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
// Should be above require, because code in require read console | ||
// what we are trying to avoid | ||
// set should be earlier than get | ||
|
||
global.console = undefined; | ||
|
||
// Initially, the `console` variable is `undefined`, since console will be | ||
// lazily loaded in the getter. | ||
|
||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
// global.console's getter is called | ||
// Since the `console` cache variable is `undefined` and therefore false-y, | ||
// the getter still calls NativeModule.require() and returns the object | ||
// obtained from it, instead of returning `undefined` as expected. | ||
|
||
assert.strictEqual(global.console, undefined, 'first read'); | ||
assert.strictEqual(global.console, undefined, 'second read'); |