Closed Bug 1766984 Opened 4 years ago Closed 4 years ago

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)

Firefox 99
defect

Tracking

(firefox102 fixed)

RESOLVED FIXED
102 Branch
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()

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.

Component: Untriaged → Console
Product: Firefox → DevTools

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.

https://searchfox.org/mozilla-central/rev/ecd91b104714a8b2584a4c03175be50ccb3a7c67/devtools/client/webconsole/utils/messages.js#203-223

    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:

https://searchfox.org/mozilla-central/rev/ecd91b104714a8b2584a4c03175be50ccb3a7c67/devtools/server/actors/resources/console-messages.js#264-273

  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.

Status: UNCONFIRMED → NEW
Ever confirmed: true
Assignee: nobody → arai.unmht
Status: NEW → ASSIGNED
Pushed by arai_a@mac.com: https://hg.mozilla.org/integration/autoland/rev/778bbfdc537c Do not remove 3rd and remaining parameters when falling back to log from console.table. r=nchevobbe
Status: ASSIGNED → RESOLVED
Closed: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → 102 Branch
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: