Skip to content

Commit 7f34c76

Browse files
joyeecheungMylesBorins
authored andcommitted
src: remove internalBinding('config').warningFile
Instead use `require('internal/options')` lazily. Also refactor the call site a bit so that the option is queried only once since it's synchronous anyway. PR-URL: #24959 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 0cde1a4 commit 7f34c76

2 files changed

Lines changed: 13 additions & 10 deletions

File tree

‎lib/internal/process/warning.js‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
'use strict';
22

3-
constconfig=internalBinding('config');
43
constprefix=`(${process.release.name}:${process.pid}) `;
54
const{ERR_INVALID_ARG_TYPE}=require('internal/errors').codes;
65

76
exports.setup=setupProcessWarnings;
87

8+
letoptions;
9+
functionlazyOption(name){
10+
if(!options){
11+
options=require('internal/options');
12+
}
13+
returnoptions.getOptionValue(name);
14+
}
15+
916
varcachedFd;
1017
varacquiringFd=false;
1118
functionnop(){}
@@ -51,11 +58,11 @@ function onAcquired(message) {
5158
};
5259
}
5360

54-
functionacquireFd(cb){
61+
functionacquireFd(warningFile,cb){
5562
if(cachedFd===undefined&&!acquiringFd){
5663
acquiringFd=true;
5764
if(fs===null)fs=require('fs');
58-
fs.open(config.warningFile,'a',onOpen(cb));
65+
fs.open(warningFile,'a',onOpen(cb));
5966
}elseif(cachedFd!==undefined&&!acquiringFd){
6067
cb(null,cachedFd);
6168
}else{
@@ -64,8 +71,9 @@ function acquireFd(cb) {
6471
}
6572

6673
functionoutput(message){
67-
if(typeofconfig.warningFile==='string'){
68-
acquireFd(onAcquired(message));
74+
constwarningFile=lazyOption('--redirect-warnings');
75+
if(warningFile){
76+
acquireFd(warningFile,onAcquired(message));
6977
return;
7078
}
7179
writeOut(message);

‎src/node_config.cc‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,6 @@ static void Initialize(Local<Object> target,
9090
"bits",
9191
Number::New(env->isolate(), 8 * sizeof(intptr_t)));
9292

93-
const std::string& warning_file = env->options()->redirect_warnings;
94-
if (!warning_file.empty()) {
95-
READONLY_STRING_PROPERTY(target, "warningFile", warning_file);
96-
}
97-
9893
Local<Object> debug_options_obj = Object::New(isolate);
9994
READONLY_PROPERTY(target, "debugOptions", debug_options_obj);
10095

0 commit comments

Comments
 (0)