diff --git a/lib/console.js b/lib/console.js index 4b76bac8808046..2e8337fda01067 100644 --- a/lib/console.js +++ b/lib/console.js @@ -91,6 +91,10 @@ function write(ignoreErrors, stream, string, errorhandler) { stream.write(string, errorhandler); } catch (e) { + // console is a debugging utility, so it swalling errors is not desirable + // even in edge cases such as low stack space. + if (e.message === 'Maximum call stack size exceeded') + throw e; // Sorry, there’s no proper way to pass along the error here. } finally { stream.removeListener('error', noop); diff --git a/test/message/console_low_stack_space.js b/test/message/console_low_stack_space.js index 1685a35a1f9304..6b4ae8f479c804 100644 --- a/test/message/console_low_stack_space.js +++ b/test/message/console_low_stack_space.js @@ -6,13 +6,20 @@ global.console = {}; require('../common'); +// This test checks that, if Node cannot put together the `console` object +// because it is low on stack space while doing so, it can succeed later +// once the stack has unwound a little, and `console` is in a usable state then. + +let compiledConsole; + function a() { try { return a(); } catch (e) { - const console = consoleDescriptor.get(); - if (console.log) { - console.log('Hello, World!'); + compiledConsole = consoleDescriptor.get(); + if (compiledConsole.log) { + // Using `console.log` itself might not succeed yet, but the code for it + // has been compiled. } else { throw e; } @@ -20,3 +27,5 @@ function a() { } a(); + +compiledConsole.log('Hello, World!');