console.table(...array) will only display the first 2 elements of the array, while console.log(...array) will display all elements of the array.
Categories
(DevTools :: Console, defect)
Tracking
(firefox102 fixed)
| Tracking | Status | |
|---|---|---|
| firefox102 | --- | fixed |
People
(Reporter: nawfal.elkhaznagi, Assigned: arai)
Details
(Keywords: parity-chrome, parity-safari)
Attachments
(1 file)
Steps to reproduce:
//create an array in js
const arr = [1,2,3];
//i'm using the new spread operator ...
console.table(...arr);
Actual results:
the console only displayed the first to elements of the array : 1 2
Expected results:
the console should have displayed all elements of the array : 1 2 3
which is the case with console.log()
Comment 1•4 years ago
|
||
The Bugbug bot thinks this bug should belong to the 'DevTools::Console' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.
| Assignee | ||
Comment 2•4 years ago
|
||
Just to be clear, that's not how console.table is supposed to be called.
https://developer.mozilla.org/en-US/docs/Web/API/console/table
Then, the behavior is different across browsers:
Chrome shows "1 2 3", in the same way as console.log.
Safari shows nothing.
Then, in Firefox, we have a fallback path for console.table with unsupported parameter,
that treats the call as console.log.
case "table":
const supportedClasses = [
"Object",
"Map",
"Set",
"WeakMap",
"WeakSet",
].concat(getArrayTypeNames());
if (
!Array.isArray(parameters) ||
parameters.length === 0 ||
!parameters[0] ||
!parameters[0].getGrip ||
!supportedClasses.includes(parameters[0].getGrip().class)
) {
// If the class of the first parameter is not supported,
// we handle the call as a simple console.log
type = "log";
}
break;
but 3rd and remaining parameters are removed:
if (message.level === "table") {
const tableItems = getConsoleTableMessageItems(targetActor, result);
if (tableItems) {
result.arguments[0].ownProperties = tableItems;
result.arguments[0].preview = null;
}
// Only return the 2 first params.
result.arguments = result.arguments.slice(0, 2);
}
We could perform the same fallback detection there as well, and remove the trailing parameters only if the first parameter is supported.
| Assignee | ||
Comment 3•4 years ago
|
||
Updated•4 years ago
|
Comment 5•4 years ago
|
||
| bugherder | ||
Description
•