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: https://github.com/nodejs/node/pull/14580 Fixes: https://github.com/nodejs/node-v8/issues/5 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
This commit is contained in:
parent
5a050550d3
commit
fb3d0e25cb
@ -94,6 +94,10 @@ function write(ignoreErrors, stream, string, errorhandler) {
|
|||||||
|
|
||||||
stream.write(string, errorhandler);
|
stream.write(string, errorhandler);
|
||||||
} catch (e) {
|
} 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.
|
// Sorry, there’s no proper way to pass along the error here.
|
||||||
} finally {
|
} finally {
|
||||||
stream.removeListener('error', noop);
|
stream.removeListener('error', noop);
|
||||||
|
@ -6,13 +6,20 @@ global.console = {};
|
|||||||
|
|
||||||
require('../common');
|
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() {
|
function a() {
|
||||||
try {
|
try {
|
||||||
return a();
|
return a();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const console = consoleDescriptor.get();
|
compiledConsole = consoleDescriptor.get();
|
||||||
if (console.log) {
|
if (compiledConsole.log) {
|
||||||
console.log('Hello, World!');
|
// Using `console.log` itself might not succeed yet, but the code for it
|
||||||
|
// has been compiled.
|
||||||
} else {
|
} else {
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
@ -20,3 +27,5 @@ function a() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
a();
|
a();
|
||||||
|
|
||||||
|
compiledConsole.log('Hello, World!');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user