Skip to content

Commit

Permalink
report: warn on process.report object access
Browse files Browse the repository at this point in the history
Reduce the number of emitExperimentalWarning() call sites by
making process.report emit a warning on access instead of each
individual report function.

PR-URL: #26414
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Wyatt Preul <wpreul@gmail.com>
  • Loading branch information
cjihrig authored and BridgeAR committed Mar 12, 2019
1 parent 9f446a1 commit 2be9e80
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 24 deletions.
10 changes: 9 additions & 1 deletion lib/internal/bootstrap/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
24 changes: 1 addition & 23 deletions lib/internal/process/report.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
'use strict';
const {
convertToValidSignal,
emitExperimentalWarning
} = require('internal/util');
const { convertToValidSignal } = require('internal/util');
const {
ERR_INVALID_ARG_TYPE,
ERR_SYNTHETIC
Expand All @@ -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;
Expand All @@ -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')
Expand All @@ -37,54 +30,42 @@ 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();
addSignalHandler(sig);
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);

Expand All @@ -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);

Expand Down

0 comments on commit 2be9e80

Please sign in to comment.