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: minor console refactoring #17707

Closed
wants to merge 6 commits into from

Conversation

BridgeAR
Copy link
Member

Some minor changes

console: make error handling engine agnostic

Calling write could throw a maximum call stack size error. To make
sure this is not specific to a single engine (version), lazily
populate the correct error message by producing such a error on
demand.
console: make variables and checks stricter
console: use spread instead of apply

The performance seems pretty similar to the any other method and
this is the most readable one.
Also fix and refactor the console benchmark. It did not test console
so it got renamed and mainly tests the different ways of passing
arguments through
console: order functions and remove \n\n

This lists all function aliases directly below the declared function.
doc: remove old console note

This should not be important anymore in newer docs. The change is
also documented in the "changed" part of the function.
Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

console, doc, benchmark

Calling write could throw a maximum call stack size error. To make
sure this is not specific to a single engine (version), lazily
populate the correct error message by producing such a error on
demand.
@nodejs-github-bot nodejs-github-bot added the console Issues and PRs related to the console subsystem. label Dec 16, 2017
lib/console.js Outdated
@@ -50,7 +52,7 @@ function Console(stdout, stderr, ignoreErrors = true) {
Object.defineProperty(this, '_stdout', prop);
prop.value = stderr;
Object.defineProperty(this, '_stderr', prop);
prop.value = ignoreErrors;
prop.value = !!ignoreErrors;
Copy link
Contributor

Choose a reason for hiding this comment

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

Using Boolean(ignoreErrors) might be more readable here.

lib/console.js Outdated

Console.prototype.warn = function warn(...args) {
write(this._ignoreErrors,
this._stderr,
util.format.apply(null, args),
util.format(...args),
Copy link
Member

Choose a reason for hiding this comment

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

The spread operator, unlike .apply(), pushes the elements onto the stack. That is, it makes stack overflows more likely.

Fix and refactor the console benchmark. It did not test console
so it got renamed and mainly tests the different ways of passing
arguments through.
This lists all function aliases directly below the declared function.
This should not be important anymore in newer docs. The change is
also documented in the "changed" part of the function.
@BridgeAR
Copy link
Member Author

Comments addressed. I removed the spread operator again and added a comment about it.

n: [1e6]
});

const nullStream = createNullStream();
Copy link
Member

Choose a reason for hiding this comment

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

Unrelated but can't this be simplified to just new Writable({ write: () => {} })?

Copy link
Member Author

@BridgeAR BridgeAR Dec 18, 2017

Choose a reason for hiding this comment

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

I went ahead and removed the fake console overall as it had no real purpose in this benchmark.

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Dec 19, 2017
@BridgeAR
Copy link
Member Author

@BridgeAR
Copy link
Member Author

@BridgeAR
Copy link
Member Author

Landed in 1e84e69, 5b4d532, 0eab495, 1d6b729, 5198a53

@BridgeAR BridgeAR closed this Dec 20, 2017
BridgeAR added a commit to BridgeAR/node that referenced this pull request Dec 20, 2017
Calling write could throw a maximum call stack size error. To make
sure this is not specific to a single engine (version), lazily
populate the correct error message by producing such a error on
demand.

PR-URL: nodejs#17707
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
BridgeAR added a commit to BridgeAR/node that referenced this pull request Dec 20, 2017
PR-URL: nodejs#17707
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
BridgeAR added a commit to BridgeAR/node that referenced this pull request Dec 20, 2017
Fix and refactor the console benchmark. It did not test console
so it got renamed and mainly tests the different ways of passing
arguments through.

PR-URL: nodejs#17707
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
BridgeAR added a commit to BridgeAR/node that referenced this pull request Dec 20, 2017
This lists all function aliases directly below the declared function.

PR-URL: nodejs#17707
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
BridgeAR added a commit to BridgeAR/node that referenced this pull request Dec 20, 2017
This should not be important anymore in newer docs. The change is
also documented in the "changed" part of the function.

PR-URL: nodejs#17707
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@addaleax addaleax removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Dec 29, 2017
MylesBorins pushed a commit that referenced this pull request Jan 8, 2018
Calling write could throw a maximum call stack size error. To make
sure this is not specific to a single engine (version), lazily
populate the correct error message by producing such a error on
demand.

PR-URL: #17707
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Jan 8, 2018
PR-URL: #17707
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Jan 8, 2018
Fix and refactor the console benchmark. It did not test console
so it got renamed and mainly tests the different ways of passing
arguments through.

PR-URL: #17707
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Jan 8, 2018
This lists all function aliases directly below the declared function.

PR-URL: #17707
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Jan 8, 2018
This should not be important anymore in newer docs. The change is
also documented in the "changed" part of the function.

PR-URL: #17707
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Jan 9, 2018
Calling write could throw a maximum call stack size error. To make
sure this is not specific to a single engine (version), lazily
populate the correct error message by producing such a error on
demand.

PR-URL: #17707
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Jan 9, 2018
PR-URL: #17707
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Jan 9, 2018
Fix and refactor the console benchmark. It did not test console
so it got renamed and mainly tests the different ways of passing
arguments through.

PR-URL: #17707
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Jan 9, 2018
This lists all function aliases directly below the declared function.

PR-URL: #17707
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this pull request Jan 9, 2018
This should not be important anymore in newer docs. The change is
also documented in the "changed" part of the function.

PR-URL: #17707
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@MylesBorins MylesBorins mentioned this pull request Jan 10, 2018
@MylesBorins
Copy link
Contributor

should this be backported to v6.x or v8.x?

@MylesBorins

This comment has been minimized.

@MylesBorins
Copy link
Contributor

@BridgeAR should this be backported?

@BridgeAR BridgeAR deleted the refactor-console branch April 1, 2019 23:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
console Issues and PRs related to the console subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants