Skip to content

Commit

Permalink
console: .table fall back to logging for function too
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
ohbarye authored and MylesBorins committed May 22, 2018
1 parent 3edb04d commit 3fd6724
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
3 changes: 1 addition & 2 deletions lib/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,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' && typeof tabularData !== 'function'))
if (tabularData == null || typeof tabularData !== 'object')
return this.log(tabularData);

if (cliTable === undefined) cliTable = require('internal/cli_table');
Expand Down
1 change: 1 addition & 0 deletions test/parallel/test-console-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ test(undefined, 'undefined\n');
test(false, 'false\n');
test('hi', 'hi\n');
test(Symbol(), 'Symbol()\n');
test(function() {}, '[Function]\n');

test([1, 2, 3], `
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”
Expand Down

0 comments on commit 3fd6724

Please sign in to comment.