From 5085ffb169d21281bc33ff7fbdde1e88aa47eb31 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 11 Dec 2018 23:17:43 +0800 Subject: [PATCH] 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. --- lib/internal/process/warning.js | 18 +++++++++++++----- src/node_config.cc | 5 ----- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/internal/process/warning.js b/lib/internal/process/warning.js index 2238bc2577bb50..698e73d97f14b5 100644 --- a/lib/internal/process/warning.js +++ b/lib/internal/process/warning.js @@ -1,11 +1,18 @@ 'use strict'; -const config = internalBinding('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() {} @@ -49,11 +56,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 { @@ -62,8 +69,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); diff --git a/src/node_config.cc b/src/node_config.cc index 27ec44b8d30538..a8ffac2cc158a4 100644 --- a/src/node_config.cc +++ b/src/node_config.cc @@ -90,11 +90,6 @@ static void Initialize(Local 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); - } - Local debug_options_obj = Object::New(isolate); READONLY_PROPERTY(target, "debugOptions", debug_options_obj);