console: .table fall back to logging for function too#20681
console: .table fall back to logging for function too#20681ohbarye wants to merge 1 commit intonodejs:masterfrom
Conversation
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
|
This will break current behavior in the situation where a function has properties attached to it: $ ./node
> foo = function () {}
[Function: foo]
> foo.bar = 'hey'
'hey'
> console.table(foo)
┌─────────┬────────┐
│ (index) │ Values │
├─────────┼────────┤
│ bar │ 'hey' │
└─────────┴────────┘
undefined
>Honest question: Do we care? In both situations, Chrome appears to publish a blank line. Firefox, in contrast, does what this PR does. FWIW, my interpretation of the spec is that our current behavior is correct. |
|
i'm fine with this change. if you want to get really into it you could check the getOwnPropertyNames and filter out |
|
Thinking more about this, yeah, I don't object to this change. It's not my preference, but I can certainly see it this way, and we can always revisit if the spec ever gets more specific about how to handle functions. |
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: nodejs#20681 Fixes: nodejs#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>
|
Thank you for your review and the warm welcome! :) |
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>
Hello @devsnek
I prepared a pull request for #20679.
Overview
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.
Fixes: #20679
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes[ ] documentation is changed or added(I think it's not necessary this time)