★ wanayoo — archive 1999 https://github.com/nodejs/node/pull/27281Nouvelle recherche | Portail wanayoo
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util: access process states lazily in debuglog #27281

Closed
wants to merge 1 commit into from

Conversation

Copy link
Member

@joyeecheung joyeecheung commented Apr 17, 2019

debuglog() depends on process.pid and process.env.NODE_DEBUG,
so it needs to be called lazily in top scopes of internal modules
that may be loaded before these run time states are allowed to
be accessed. This patch makes its implementation lazy by default,
the process states are only accessed when the returned debug
function is called for the first time.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines

`debuglog()` depends on `process.pid` and `process.env.NODE_DEBUG`,
so it needs to be called lazily in top scopes of internal modules
that may be loaded before these run time states are allowed to
be accessed. This patch makes its implementation lazy by default,
the process states are only accessed when the returned debug
function is called for the first time.
@nodejs-github-bot
Copy link
Contributor

@nodejs-github-bot nodejs-github-bot commented Apr 17, 2019

@nodejs-github-bot nodejs-github-bot added the lib / src label Apr 17, 2019
@nodejs-github-bot
Copy link
Contributor

@nodejs-github-bot nodejs-github-bot commented Apr 17, 2019

@@ -31,7 +31,7 @@ function emitWarningIfNeeded(set) {
}
}

function debuglog(set) {
function debuglogImpl(set) {
set = set.toUpperCase();
if (!debugs[set]) {
if (debugEnvRegex.test(set)) {
Copy link
Member Author

@joyeecheung joyeecheung Apr 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that since process.env.NODE_DEBUG is saved above during pre-execution, even though the saved value is accessed lazily, it's still saved as soon as possible.

@joyeecheung joyeecheung added author ready util labels Apr 18, 2019
@joyeecheung
Copy link
Member Author

@joyeecheung joyeecheung commented Apr 19, 2019

Landed in 2e4ceb5

joyeecheung added a commit that referenced this issue Apr 19, 2019
`debuglog()` depends on `process.pid` and `process.env.NODE_DEBUG`,
so it needs to be called lazily in top scopes of internal modules
that may be loaded before these run time states are allowed to
be accessed. This patch makes its implementation lazy by default,
the process states are only accessed when the returned debug
function is called for the first time.

PR-URL: #27281
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready lib / src util
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants