From 76d8746086db6a42d1c7bc9558d7cb7b3554ecc9 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Wed, 2 Aug 2017 00:17:06 +0200 Subject: [PATCH] console,test: make message test more accurate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make a message test more accurate in what it’s testing for. This requires not swallowing stack overflow RangeErrors in `console.log` and similar methods, which I would consider a bugfix in itself. Fixes: https://github.com/nodejs/node-v8/issues/5 --- lib/console.js | 4 ++++ test/message/console_low_stack_space.js | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) 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!');