Skip to content

Commit fb3d0e2

Browse files
addaleaxtargos
authored andcommitted
console,test: make message test more accurate
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 <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
1 parent 5a05055 commit fb3d0e2

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/console.js

+4
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ function write(ignoreErrors, stream, string, errorhandler) {
9494

9595
stream.write(string, errorhandler);
9696
} catch (e) {
97+
// console is a debugging utility, so it swallowing errors is not desirable
98+
// even in edge cases such as low stack space.
99+
if (e.message === 'Maximum call stack size exceeded')
100+
throw e;
97101
// Sorry, there’s no proper way to pass along the error here.
98102
} finally {
99103
stream.removeListener('error', noop);

test/message/console_low_stack_space.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,26 @@ global.console = {};
66

77
require('../common');
88

9+
// This test checks that, if Node cannot put together the `console` object
10+
// because it is low on stack space while doing so, it can succeed later
11+
// once the stack has unwound a little, and `console` is in a usable state then.
12+
13+
let compiledConsole;
14+
915
function a() {
1016
try {
1117
return a();
1218
} catch (e) {
13-
const console = consoleDescriptor.get();
14-
if (console.log) {
15-
console.log('Hello, World!');
19+
compiledConsole = consoleDescriptor.get();
20+
if (compiledConsole.log) {
21+
// Using `console.log` itself might not succeed yet, but the code for it
22+
// has been compiled.
1623
} else {
1724
throw e;
1825
}
1926
}
2027
}
2128

2229
a();
30+
31+
compiledConsole.log('Hello, World!');

0 commit comments

Comments
 (0)