process: move process mutation into bootstrap/node.js
This patch moves the part in the report initialization that mutates the process object into bootstrap/node.js so it's easier to tell the side effect of the initialization on the global state during bootstrap. PR-URL: https://github.com/nodejs/node/pull/25821 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
This commit is contained in:
parent
c2359bdad6
commit
406329de57
@ -309,7 +309,18 @@ if (process.env.NODE_V8_COVERAGE) {
|
||||
}
|
||||
|
||||
if (getOptionValue('--experimental-report')) {
|
||||
NativeModule.require('internal/process/report').setup();
|
||||
const {
|
||||
config,
|
||||
handleSignal,
|
||||
report,
|
||||
syncConfig
|
||||
} = NativeModule.require('internal/process/report');
|
||||
process.report = report;
|
||||
// Download the CLI / ENV config into JS land.
|
||||
syncConfig(config, false);
|
||||
if (config.events.includes('signal')) {
|
||||
process.on(config.signal, handleSignal);
|
||||
}
|
||||
}
|
||||
|
||||
function setupTraceCategoryState() {
|
||||
|
@ -3,36 +3,36 @@
|
||||
const { emitExperimentalWarning } = require('internal/util');
|
||||
const {
|
||||
ERR_INVALID_ARG_TYPE,
|
||||
ERR_SYNTHETIC } = require('internal/errors').codes;
|
||||
ERR_SYNTHETIC
|
||||
} = require('internal/errors').codes;
|
||||
|
||||
exports.setup = function() {
|
||||
const REPORTEVENTS = 1;
|
||||
const REPORTSIGNAL = 2;
|
||||
const REPORTFILENAME = 3;
|
||||
const REPORTPATH = 4;
|
||||
const REPORTVERBOSE = 5;
|
||||
const REPORTEVENTS = 1;
|
||||
const REPORTSIGNAL = 2;
|
||||
const REPORTFILENAME = 3;
|
||||
const REPORTPATH = 4;
|
||||
const REPORTVERBOSE = 5;
|
||||
|
||||
// If report is enabled, extract the binding and
|
||||
// wrap the APIs with thin layers, with some error checks.
|
||||
// user options can come in from CLI / ENV / API.
|
||||
// CLI and ENV is intercepted in C++ and the API call here (JS).
|
||||
// So sync up with both sides as appropriate - initially from
|
||||
// C++ to JS and from JS to C++ whenever the API is called.
|
||||
// Some events are controlled purely from JS (signal | exception)
|
||||
// and some from C++ (fatalerror) so this sync-up is essential for
|
||||
// correct behavior and alignment with the supplied tunables.
|
||||
const nr = internalBinding('report');
|
||||
// If report is enabled, extract the binding and
|
||||
// wrap the APIs with thin layers, with some error checks.
|
||||
// user options can come in from CLI / ENV / API.
|
||||
// CLI and ENV is intercepted in C++ and the API call here (JS).
|
||||
// So sync up with both sides as appropriate - initially from
|
||||
// C++ to JS and from JS to C++ whenever the API is called.
|
||||
// Some events are controlled purely from JS (signal | exception)
|
||||
// and some from C++ (fatalerror) so this sync-up is essential for
|
||||
// correct behavior and alignment with the supplied tunables.
|
||||
const nr = internalBinding('report');
|
||||
|
||||
// Keep it un-exposed; lest programs play with it
|
||||
// leaving us with a lot of unwanted sanity checks.
|
||||
let config = {
|
||||
// Keep it un-exposed; lest programs play with it
|
||||
// leaving us with a lot of unwanted sanity checks.
|
||||
let config = {
|
||||
events: [],
|
||||
signal: 'SIGUSR2',
|
||||
filename: '',
|
||||
path: '',
|
||||
verbose: false
|
||||
};
|
||||
const report = {
|
||||
};
|
||||
const report = {
|
||||
setDiagnosticReportOptions(options) {
|
||||
emitExperimentalWarning('report');
|
||||
// Reuse the null and undefined checks. Save
|
||||
@ -125,22 +125,15 @@ exports.setup = function() {
|
||||
return nr.getReport(err.stack);
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// Download the CLI / ENV config into JS land.
|
||||
nr.syncConfig(config, false);
|
||||
|
||||
function handleSignal(signo) {
|
||||
function handleSignal(signo) {
|
||||
if (typeof signo !== 'string')
|
||||
signo = config.signal;
|
||||
nr.onUserSignal(signo);
|
||||
}
|
||||
}
|
||||
|
||||
if (config.events.includes('signal')) {
|
||||
process.on(config.signal, handleSignal);
|
||||
}
|
||||
|
||||
function parseOptions(obj) {
|
||||
function parseOptions(obj) {
|
||||
const list = [];
|
||||
if (obj == null)
|
||||
return list;
|
||||
@ -155,6 +148,11 @@ exports.setup = function() {
|
||||
if (obj.verbose != null)
|
||||
list.push(REPORTVERBOSE);
|
||||
return list;
|
||||
}
|
||||
process.report = report;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
config,
|
||||
handleSignal,
|
||||
report,
|
||||
syncConfig: nr.syncConfig
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user