Skip to content

Commit

Permalink
console,test: make message test more accurate
Browse files Browse the repository at this point in the history
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.

PR-URL: #14580
Fixes: nodejs/node-v8#5
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
addaleax authored and targos committed Aug 3, 2017
1 parent 5a05055 commit fb3d0e2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ function write(ignoreErrors, stream, string, errorhandler) {

stream.write(string, errorhandler);
} catch (e) {
// console is a debugging utility, so it swallowing 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);
Expand Down
15 changes: 12 additions & 3 deletions test/message/console_low_stack_space.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,26 @@ 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;
}
}
}

a();

compiledConsole.log('Hello, World!');

0 comments on commit fb3d0e2

Please sign in to comment.