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

lib: change abstract equal to strict equal #22974

Closed
wants to merge 2 commits 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
2 changes: 1 addition & 1 deletion lib/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ Console.prototype.table = function(tabularData, properties) {
if (properties !== undefined && !ArrayIsArray(properties))
throw new ERR_INVALID_ARG_TYPE('properties', 'Array', properties);

if (tabularData == null || typeof tabularData !== 'object')
if (tabularData === null || typeof tabularData !== 'object')
Copy link
Member

Choose a reason for hiding this comment

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

It's not obvious, but this significantly changes the semantics of the check in a non-backwards compatible way.

null == null; // true
undefined == null; // true
null === null; // true
undefined === null; // false

The current check makes sure that tabularData is also not undefined.

Copy link
Member Author

@ZYSzys ZYSzys Sep 20, 2018

Choose a reason for hiding this comment

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

But the later one can check it, typeof undefined === 'undefined' so typeof tabularData !== 'object' is true.

Copy link
Member

Choose a reason for hiding this comment

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

This is 100 % subjective, but maybe this would be a bit more Obviously Correct™ if the conditions were switched?

Copy link
Member

Choose a reason for hiding this comment

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

Just not seeing the point of the change then if it simply shifts the undefined case a bit to the right.

Copy link
Member Author

@ZYSzys ZYSzys Sep 20, 2018

Choose a reason for hiding this comment

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

Just change to strict equal to unify the overall code style.
If there is any problem, feel free to close it.😜

Copy link
Member

Choose a reason for hiding this comment

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

Nah, I'm not overly happy with it but I won't block it :-)

return this.log(tabularData);

if (cliTable === undefined) cliTable = require('internal/cli_table');
Expand Down
9 changes: 9 additions & 0 deletions test/parallel/test-console-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ test([Symbol(), 5, [10]], `
└─────────┴────┴──────────┘
`);

test([null, 5], `
┌─────────┬────────┐
│ (index) │ Values │
├─────────┼────────┤
│ 0 │ null │
│ 1 │ 5 │
└─────────┴────────┘
`);

test([undefined, 5], `
┌─────────┬───────────┐
│ (index) │ Values │
Expand Down