Browse Source

lib: instantiate console methods eagerly

Before this commit they were instantiated lazily but that fails when the
first call is under stack overflow conditions.

PR-URL: https://github.com/nodejs/node/pull/14791
Fixes: https://github.com/nodejs/help#778
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
canary-base
Ben Noordhuis 7 years ago
committed by James M Snell
parent
commit
da1af3d3fc
  1. 19
      lib/internal/bootstrap_node.js
  2. 18
      test/message/stack_overflow_async.js
  3. 4
      test/message/stack_overflow_async.out

19
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__)

18
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();

4
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:*)
Loading…
Cancel
Save