Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib: instantiate console methods eagerly #14791

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion lib/internal/bootstrap_node.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
setupProcessICUVersions();

setupGlobalVariables();
if (!process._noBrowserGlobals) {
const browserGlobals = !process._noBrowserGlobals;
if (browserGlobals) {
setupGlobalTimeouts();
setupGlobalConsole();
}
Expand All @@ -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__)
Expand Down
18 changes: 18 additions & 0 deletions test/message/stack_overflow_async.js
Original file line number Diff line number Diff line change
@@ -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();
4 changes: 4 additions & 0 deletions test/message/stack_overflow_async.out
Original file line number Diff line number Diff line change
@@ -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:*)