Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

console,test: make message test more accurate #14580

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: swallowing

// 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();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a check that e.message === 'Maximum call stack size exceeded' (should be assert, but we can assume the stack is full)

if (compiledConsole.log) {
// Using `console.log` itself might not succeed yet, but the code for it
// has been compiled.
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this branch?

if (!compiledConsole.log) {
  throw e;
}

If you think it's clearer as is, no problem, ignore the comment.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing it out, but yes, I think it’s clearer this way.

throw e;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO you should throw a new Error, one that explicitly represents the failure to compile (could be prepared in advance if there's no room on the stack).

}
}
}

a();

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