Skip to content

Commit

Permalink
src: remove internalBinding('config').warningFile
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
joyeecheung authored and BethGriggs committed Jul 16, 2019
1 parent b3d8a1b commit 76af23a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
18 changes: 13 additions & 5 deletions lib/internal/process/warning.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
'use strict';

const config = process.binding('config');
const prefix = `(${process.release.name}:${process.pid}) `;
const { ERR_INVALID_ARG_TYPE } = require('internal/errors').codes;

exports.setup = setupProcessWarnings;

let options;
function lazyOption(name) {
if (!options) {
options = require('internal/options');
}
return options.getOptionValue(name);
}

var cachedFd;
var acquiringFd = false;
function nop() {}
Expand Down Expand Up @@ -51,11 +58,11 @@ function onAcquired(message) {
};
}

function acquireFd(cb) {
function acquireFd(warningFile, cb) {
if (cachedFd === undefined && !acquiringFd) {
acquiringFd = true;
if (fs === null) fs = require('fs');
fs.open(config.warningFile, 'a', onOpen(cb));
fs.open(warningFile, 'a', onOpen(cb));
} else if (cachedFd !== undefined && !acquiringFd) {
cb(null, cachedFd);
} else {
Expand All @@ -64,8 +71,9 @@ function acquireFd(cb) {
}

function output(message) {
if (typeof config.warningFile === 'string') {
acquireFd(onAcquired(message));
const warningFile = lazyOption('--redirect-warnings');
if (warningFile) {
acquireFd(warningFile, onAcquired(message));
return;
}
writeOut(message);
Expand Down
5 changes: 0 additions & 5 deletions src/node_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,6 @@ static void Initialize(Local<Object> target,
"bits",
Number::New(env->isolate(), 8 * sizeof(intptr_t)));

const std::string& warning_file = env->options()->redirect_warnings;
if (!warning_file.empty()) {
READONLY_STRING_PROPERTY(target, "warningFile", warning_file);
}

std::shared_ptr<DebugOptions> debug_options = env->options()->debug_options;
Local<Object> debug_options_obj = Object::New(isolate);
READONLY_PROPERTY(target, "debugOptions", debug_options_obj);
Expand Down

0 comments on commit 76af23a

Please sign in to comment.