From 2be9e800f10bdb32b3d4f4b108f71f4d185d2b84 Mon Sep 17 00:00:00 2001 From: cjihrig Date: Tue, 5 Mar 2019 08:41:51 -0500 Subject: [PATCH] report: warn on process.report object access Reduce the number of emitExperimentalWarning() call sites by making process.report emit a warning on access instead of each individual report function. PR-URL: https://github.com/nodejs/node/pull/26414 Reviewed-By: Richard Lau Reviewed-By: Wyatt Preul --- lib/internal/bootstrap/pre_execution.js | 10 +++++++++- lib/internal/process/report.js | 24 +----------------------- 2 files changed, 10 insertions(+), 24 deletions(-) diff --git a/lib/internal/bootstrap/pre_execution.js b/lib/internal/bootstrap/pre_execution.js index 81b411598f0ce7..739a78208b62da 100644 --- a/lib/internal/bootstrap/pre_execution.js +++ b/lib/internal/bootstrap/pre_execution.js @@ -40,7 +40,15 @@ function initializeReport() { return; } const { report } = require('internal/process/report'); - process.report = report; + const { emitExperimentalWarning } = require('internal/util'); + Object.defineProperty(process, 'report', { + enumerable: false, + configurable: true, + get() { + emitExperimentalWarning('report'); + return report; + } + }); } function setupSignalHandlers() { diff --git a/lib/internal/process/report.js b/lib/internal/process/report.js index 96729b2ee3d315..c96443102534ba 100644 --- a/lib/internal/process/report.js +++ b/lib/internal/process/report.js @@ -1,8 +1,5 @@ 'use strict'; -const { - convertToValidSignal, - emitExperimentalWarning -} = require('internal/util'); +const { convertToValidSignal } = require('internal/util'); const { ERR_INVALID_ARG_TYPE, ERR_SYNTHETIC @@ -11,8 +8,6 @@ const { validateString } = require('internal/validators'); const nr = internalBinding('report'); const report = { triggerReport(file, err) { - emitExperimentalWarning('report'); - if (typeof file === 'object' && file !== null) { err = file; file = undefined; @@ -27,8 +22,6 @@ const report = { return nr.triggerReport('JavaScript API', 'API', file, err.stack); }, getReport(err) { - emitExperimentalWarning('report'); - if (err === undefined) err = new ERR_SYNTHETIC(); else if (err === null || typeof err !== 'object') @@ -37,29 +30,23 @@ const report = { return nr.getReport(err.stack); }, get directory() { - emitExperimentalWarning('report'); return nr.getDirectory(); }, set directory(dir) { - emitExperimentalWarning('report'); validateString(dir, 'directory'); return nr.setDirectory(dir); }, get filename() { - emitExperimentalWarning('report'); return nr.getFilename(); }, set filename(name) { - emitExperimentalWarning('report'); validateString(name, 'filename'); return nr.setFilename(name); }, get signal() { - emitExperimentalWarning('report'); return nr.getSignal(); }, set signal(sig) { - emitExperimentalWarning('report'); validateString(sig, 'signal'); convertToValidSignal(sig); // Validate that the signal is recognized. removeSignalHandler(); @@ -67,24 +54,18 @@ const report = { return nr.setSignal(sig); }, get reportOnFatalError() { - emitExperimentalWarning('report'); return nr.shouldReportOnFatalError(); }, set reportOnFatalError(trigger) { - emitExperimentalWarning('report'); - if (typeof trigger !== 'boolean') throw new ERR_INVALID_ARG_TYPE('trigger', 'boolean', trigger); return nr.setReportOnFatalError(trigger); }, get reportOnSignal() { - emitExperimentalWarning('report'); return nr.shouldReportOnSignal(); }, set reportOnSignal(trigger) { - emitExperimentalWarning('report'); - if (typeof trigger !== 'boolean') throw new ERR_INVALID_ARG_TYPE('trigger', 'boolean', trigger); @@ -93,12 +74,9 @@ const report = { addSignalHandler(); }, get reportOnUncaughtException() { - emitExperimentalWarning('report'); return nr.shouldReportOnUncaughtException(); }, set reportOnUncaughtException(trigger) { - emitExperimentalWarning('report'); - if (typeof trigger !== 'boolean') throw new ERR_INVALID_ARG_TYPE('trigger', 'boolean', trigger);