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: console.table doesn't fall back to just logging when given a function #20679

Closed
ohbarye opened this issue May 11, 2018 · 2 comments
Closed
Labels
console Issues and PRs related to the console subsystem.

Comments

@ohbarye
Copy link
Contributor

ohbarye commented May 11, 2018

  • Version: v10.1.0
  • Platform: macOS X
  • Subsystem: console

This is a question. (And I admit it's a kind of nitpicking).

Current Behavior

According to the console.table document, it reads that it "falls back to just logging the argument if it can’t be parsed as tabular."

But it doesn't fall back when I give a function as its first argument. It logs an empty table.

$ node

> const f = function() {}
> console.table(f)
┌─────────┐
 (index) 
├─────────┤
└─────────┘
$ node

> class Test {}
> console.table(Test)
┌─────────┐
 (index) 
├─────────┤
└─────────┘

I guess that's because the following line allows a function to proceed the consequent steps.

(typeof tabularData !== 'object' && typeof tabularData !== 'function'))

Question

Is this intentional behavior?

If it's better to change this behavior, I would be glad to send a patch for that.

@devsnek devsnek added the console Issues and PRs related to the console subsystem. label May 11, 2018
@devsnek
Copy link
Member

devsnek commented May 11, 2018

i think it'd be fine to change it

ohbarye added a commit to ohbarye/node that referenced this issue May 11, 2018
According to the [console.table
document](https://github.com/nodejs/node/blob/master/doc/api/console.md#consoletabletabulardata-properties),
it reads that it "falls back to just logging the argument if it can’t be
parsed as tabular."

But it doesn't fall back when I give a function as its first argument.
It logs an empty table.

Fixes: nodejs#20679
@Trott
Copy link
Member

Trott commented May 11, 2018

I think this was intentional behavior. It's what Chrome does and it fits my interpretation of the spec. However, Firefox does it differently and the spec for console.table() is just a few sentences long so not very detailed.

Do note that it's possible to attach properties to a function and that our current implementation deals with that well:

$ ./node
> foo = function () {}
[Function: foo]
> foo.bar = 'hey'
'hey'
> console.table(foo)
┌─────────┬────────┐
│ (index) │ Values │
├─────────┼────────┤
│   bar   │ 'hey'  │
└─────────┴────────┘
undefined
>

MylesBorins pushed a commit that referenced this issue May 22, 2018
According to the console.table documentation, it reads that it "falls
back to just logging the argument if it can’t be parsed as tabular."

But it doesn't fall back when I give a function as its first argument.
It logs an empty table. This is fixes by this commit.

PR-URL: #20681
Fixes: #20679
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
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 a pull request may close this issue.

3 participants