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

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

lib/internal/process/warning.js

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
'use strict';
22

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

76
exports.setup = setupProcessWarnings;
87

8+
let options;
9+
function lazyOption(name) {
10+
if (!options) {
11+
options = require('internal/options');
12+
}
13+
return options.getOptionValue(name);
14+
}
15+
916
var cachedFd;
1017
var acquiringFd = false;
1118
function nop() {}
@@ -51,11 +58,11 @@ function onAcquired(message) {
5158
};
5259
}
5360

54-
function acquireFd(cb) {
61+
function acquireFd(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
} else if (cachedFd !== undefined && !acquiringFd) {
6067
cb(null, cachedFd);
6168
} else {
@@ -64,8 +71,9 @@ function acquireFd(cb) {
6471
}
6572

6673
function output(message) {
67-
if (typeof config.warningFile === 'string') {
68-
acquireFd(onAcquired(message));
74+
const warningFile = lazyOption('--redirect-warnings');
75+
if (warningFile) {
76+
acquireFd(warningFile, onAcquired(message));
6977
return;
7078
}
7179
writeOut(message);

src/node_config.cc

-5
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)