Skip to content

Commit

Permalink
process: set up process warning handler in pre-execution
Browse files Browse the repository at this point in the history
Since it depends on environment variables.

PR-URL: nodejs#26466
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
joyeecheung authored and refack committed Mar 17, 2019
1 parent 4be5076 commit 7ab1a11
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
5 changes: 1 addition & 4 deletions lib/internal/bootstrap/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,9 @@ if (isMainThread) {
}

const {
onWarning,
emitWarning
} = NativeModule.require('internal/process/warning');
if (!process.noProcessWarnings && process.env.NODE_NO_WARNINGS !== '1') {
process.on('warning', onWarning);
}

process.emitWarning = emitWarning;

const {
Expand Down
12 changes: 12 additions & 0 deletions lib/internal/bootstrap/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ let traceEventsAsyncHook;
function prepareMainThreadExecution() {
setupTraceCategoryState();

setupWarningHandler();

// Only main thread receives signals.
setupSignalHandlers();

Expand Down Expand Up @@ -36,6 +38,15 @@ function prepareMainThreadExecution() {
loadPreloadModules();
}

function setupWarningHandler() {
const {
onWarning
} = require('internal/process/warning');
if (!process.noProcessWarnings && process.env.NODE_NO_WARNINGS !== '1') {
process.on('warning', onWarning);
}
}

function initializeReport() {
if (!getOptionValue('--experimental-report')) {
return;
Expand Down Expand Up @@ -251,6 +262,7 @@ function loadPreloadModules() {
}

module.exports = {
setupWarningHandler,
prepareMainThreadExecution,
initializeDeprecations,
initializeESMLoader,
Expand Down
3 changes: 3 additions & 0 deletions lib/internal/main/worker_thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// message port.

const {
setupWarningHandler,
initializeDeprecations,
initializeESMLoader,
initializeFrozenIntrinsics,
Expand Down Expand Up @@ -39,6 +40,8 @@ const {
const publicWorker = require('worker_threads');
const debug = require('util').debuglog('worker');

setupWarningHandler();

debug(`[${threadId}] is setting up worker child environment`);

// Set up the message port and start listening
Expand Down

0 comments on commit 7ab1a11

Please sign in to comment.