diff --git a/lib/internal/bootstrap_node.js b/lib/internal/bootstrap_node.js index 670e35fb31635d..9e26080987183e 100644 --- a/lib/internal/bootstrap_node.js +++ b/lib/internal/bootstrap_node.js @@ -26,7 +26,8 @@ setupProcessICUVersions(); setupGlobalVariables(); - if (!process._noBrowserGlobals) { + const browserGlobals = !process._noBrowserGlobals; + if (browserGlobals) { setupGlobalTimeouts(); setupGlobalConsole(); } @@ -40,6 +41,22 @@ NativeModule.require('internal/process/warning').setup(); NativeModule.require('internal/process/next_tick').setup(); NativeModule.require('internal/process/stdio').setup(); + if (browserGlobals) { + // Instantiate eagerly in case the first call is under stack overflow + // conditions where instantiation doesn't work. + const console = global.console; + console.assert; + console.clear; + console.count; + console.countReset; + console.dir; + console.error; + console.log; + console.time; + console.timeEnd; + console.trace; + console.warn; + } _process.setupKillAndExit(); _process.setupSignalHandlers(); if (global.__coverage__) diff --git a/test/message/stack_overflow_async.js b/test/message/stack_overflow_async.js new file mode 100644 index 00000000000000..9aefbf9557ea03 --- /dev/null +++ b/test/message/stack_overflow_async.js @@ -0,0 +1,18 @@ +// Flags: --stack_trace_limit=3 + +'use strict'; +require('../common'); + +async function f() { + await f(); +} + +async function g() { + try { + await f(); + } catch (e) { + console.log(e); + } +} + +g(); diff --git a/test/message/stack_overflow_async.out b/test/message/stack_overflow_async.out new file mode 100644 index 00000000000000..4028c7642ac531 --- /dev/null +++ b/test/message/stack_overflow_async.out @@ -0,0 +1,4 @@ +RangeError: Maximum call stack size exceeded + at f (*test*message*stack_overflow_async.js:*) + at f (*test*message*stack_overflow_async.js:7:*) + at f (*test*message*stack_overflow_async.js:7:*)