Skip to content

feat(console): implement console.table()#4690

Open
ParthMozarkar wants to merge 7 commits intoboa-dev:mainfrom
ParthMozarkar:feat-console-table
Open

feat(console): implement console.table()#4690
ParthMozarkar wants to merge 7 commits intoboa-dev:mainfrom
ParthMozarkar:feat-console-table

Conversation

@ParthMozarkar
Copy link

Summary

Implements the console.table() method for the console builtin as requested in #3806.

This adds spec-aligned tabular rendering support to Boa's console implementation.

Implementation Details

  • Added a table method to the Logger trait.
  • Implemented structured tabular data extraction following the behavior described in the WHATWG Console specification.
  • Supports:
    • Objects
    • Arrays of objects
    • Arrays of primitives
  • Implements ASCII-based column formatting consistent with existing console output.
  • Handles optional properties argument to allow column filtering.
  • Ensures integration with Boa’s existing logging infrastructure (no direct stdout usage).

Behavior

  • Extracts enumerable own properties from input.
  • Computes column headers dynamically.
  • Aligns output into a readable ASCII table format.
  • Returns undefined, matching browser console behavior.

Tests

  • Added unit tests in core/runtime/src/console/tests.rs.
  • Tests cover:
    • Basic object input
    • Array input
    • Column filtering
    • Edge cases (empty input)

Notes

  • Implementation follows the current internal console architecture.
  • No changes to existing console behavior.
  • Passes cargo fmt, cargo clippy, and all tests.

Fixes #3806

@github-actions
Copy link

github-actions bot commented Feb 23, 2026

Test262 conformance changes

Test result main count PR count difference
Total 52,963 52,963 0
Passed 49,666 49,666 0
Ignored 2,284 2,284 0
Failed 1,013 1,013 0
Panics 0 0 0
Conformance 93.77% 93.77% 0.00%

Tested main commit: 70a6df29729f8b98fc303baebdb4a5676fdfd839
Tested PR commit: 31ad6733d6252cfd1806dc5f563dae3dd2050e03
Compare commits: 70a6df2...31ad673

@jedel1043 jedel1043 added enhancement New feature or request builtins PRs and Issues related to builtins/intrinsics labels Feb 25, 2026
///
/// [spec]: https://console.spec.whatwg.org/#table
/// [mdn]: https://developer.mozilla.org/en-US/docs/Web/API/console/table_static
#[allow(clippy::too_many_lines)]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Triggering this lint should've given you a hint that this code is kind of hard to follow 😅

Can you split it in smaller pieces?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea; we could have a crate feature to use the comfy-table crate. Bonus; it supports TTY terminals (setting width accordingly) and non-ANSI (using + and - and | instead of unicode box characters). It would also simplify the code.

Copy link
Author

@ParthMozarkar ParthMozarkar Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the feedback!

You're right the implementation grew larger than it should have.

I'll refactor the logic into smaller helper functions to improve readability and remove the clippy allowance.

Regarding the comfy-table suggestion, would you prefer keeping the implementation internal, or introducing a feature-gated dependency for formatting?

I'll push an update shortly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I'd like to see if all this code can be replaced with comfy-table. If not, we can add it in a separate PR with a feature.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion!

I'll explore whether the current implementation can be fully replaced using comfy-table. If it works cleanly, I'll update this PR accordingly.

If not, I'll open a separate PR introducing it as a feature as suggested.

@jedel1043 jedel1043 added the waiting-on-author Waiting on PR changes from the author label Feb 25, 2026
@ParthMozarkar ParthMozarkar requested a review from a team as a code owner February 25, 2026 19:55
@ParthMozarkar
Copy link
Author

Hi @jedel1043,

I've pushed the refactored implementation addressing the review comments.

Changes include:

Split the logic into smaller helper functions to improve readability.

Removed the clippy::too_many_lines allowance.

Improved structure and reduced complexity where possible.

Ensured proper error propagation (no expect() in runtime paths).

Verified with cargo check, cargo test, and cargo clippy.

Please let me know if you'd like any further refinements. Thanks again for the feedback !!

@jedel1043
Copy link
Member

Didn't see you address if you tried implementing everything with comfy-table. Was that done or are you planning on doing it in a later PR?

@ParthMozarkar
Copy link
Author

ParthMozarkar commented Mar 5, 2026

Didn't see you address if you tried implementing everything with comfy-table. Was that done or are you planning on doing it in a later PR?

I've currently only implemented it for the test output formatting. I am planning on migrating the actual console.table engine logic to use comfy-table entirely in a later PR to keep this PR's scope focused...

@codecov
Copy link

codecov bot commented Mar 6, 2026

Codecov Report

❌ Patch coverage is 90.56604% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.51%. Comparing base (6ddc2b4) to head (31ad673).
⚠️ Report is 768 commits behind head on main.

Files with missing lines Patch % Lines
core/runtime/src/console/mod.rs 90.56% 10 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##             main    #4690       +/-   ##
===========================================
+ Coverage   47.24%   57.51%   +10.27%     
===========================================
  Files         476      556       +80     
  Lines       46892    60817    +13925     
===========================================
+ Hits        22154    34981    +12827     
- Misses      24738    25836     +1098     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

ParthMozarkar added a commit to ParthMozarkar/boa that referenced this pull request Mar 6, 2026
ParthMozarkar added a commit to ParthMozarkar/boa that referenced this pull request Mar 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

builtins PRs and Issues related to builtins/intrinsics enhancement New feature or request waiting-on-author Waiting on PR changes from the author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement console.table() method

3 participants