Skip to content

feat: console.table implementation#5218

Open
hunterchen7 wants to merge 3 commits intoboa-dev:mainfrom
hunterchen7:feat/console-table
Open

feat: console.table implementation#5218
hunterchen7 wants to merge 3 commits intoboa-dev:mainfrom
hunterchen7:feat/console-table

Conversation

@hunterchen7
Copy link

This Pull Request closes #3806

summary

  • implements console.table(tabularData, properties) per the WHATWG Console spec.
  • adds a table() method to the Logger trait with a default comfy-table rendering
  • extracts table data into a backend-agnostic TableData struct in a separate table.rs module (as to not bloat mod.rs)
  • supports arrays of objects, plain objects, primitive arrays, mixed arrays, sparse columns, Map, Set, TypedArray, and deeply nested objects (rendered inline)
  • optional properties argument filters which columns are shown; non-array values throw TypeError
  • falls back to console.log for non-tabular input (primitives, empty collections)
  • behaviour attempts to match behaviour of Node.js & Bun (column naming, Map/Set layout, TypeError on invalid arguments, inline display of nested objects, etc)

tests

  • 24 unit tests based on console.table unit tests from Node.js and Bun
  • fallback (4): primitives, no arguments, empty arrays, empty objects/Maps
  • core rendering (3): array of objects, primitive array, object with primitive values
  • Map/Set/TypedArray (4): Map with Key/Values, Set, empty Map fallback, TypedArray
  • complex shapes (3): sparse columns, mixed arrays (objects + primitives), nested objects rendered inline
  • column filtering (5): basic filter, empty filter, nonexistent property, duplicate dedup, filter controls column order
  • nonexistent property (1): filtered columns not in the data still render as empty
  • Map/Set ignore filter (2): properties argument has no effect on Map/Set layout
  • validation (1): non-array second argument throws TypeError
  • security (1): ["__proto__"] filter does not pollute Object.prototype (this test I don't quite understand but it's from Node.js)

some examples

> console.table([{a: 1, b: 2}, {a: 3, b: 4}])
┌─────────┬───┬───┐
 (index)  a  b 
╞═════════╪═══╪═══╡
 0        1  2 
├╌╌╌╌╌╌╌╌╌┼╌╌╌┼╌╌╌┤
 1        3  4 
└─────────┴───┴───┘

> console.table({alice: {age: 30, role: "admin"}, bob: {age: 25, role: "user", active: true}})
┌─────────┬─────┬─────────┬────────┐
 (index)  age  role     active 
╞═════════╪═════╪═════════╪════════╡
 alice    30   "admin"         
├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
 bob      25   "user"   true   
└─────────┴─────┴─────────┴────────┘

> console.table({alice: {age: 30, role: "admin"}, bob: {age: 25, role: "user"}}, ["role"])
┌─────────┬─────────┐
 (index)  role    
╞═════════╪═════════╡
 alice    "admin" 
├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┤
 bob      "user"  
└─────────┴─────────┘

> console.table(new Map([["x", {a: 1}], ["y", {b: 2}]]))
┌───────────────────┬─────┬──────────┐
 (iteration index)  Key  Values   
╞═══════════════════╪═════╪══════════╡
 0                  "x"  { a: 1 } 
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
 1                  "y"  { b: 2 } 
└───────────────────┴─────┴──────────┘

> console.table(new Set(["apple", "banana", "cherry"]))
┌───────────────────┬──────────┐
 (iteration index)  Values   
╞═══════════════════╪══════════╡
 0                  "apple"  
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
 1                  "banana" 
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌┤
 2                  "cherry" 
└───────────────────┴──────────┘

> console.table([{name: "Alice", scores: {math: 95, eng: 88}}, {name: "Bob", scores: {math: 72, eng: 91}}])
┌─────────┬─────────┬───────────────────────┐
 (index)  name     scores                
╞═════════╪═════════╪═══════════════════════╡
 0        "Alice"  { math: 95, eng: 88 } 
├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
 1        "Bob"    { math: 72, eng: 91 } 
└─────────┴─────────┴───────────────────────┘

> console.table([10, 20, 30])
┌─────────┬────────┐
 (index)  Values 
╞═════════╪════════╡
 0        10     
├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
 1        20     
├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
 2        30     
└─────────┴────────┘

> console.table("hello")   // primitive fallback
hello

@hunterchen7 hunterchen7 requested a review from a team as a code owner March 22, 2026 05:37
@github-actions github-actions bot added Waiting On Review Waiting on reviews from the maintainers C-Dependencies Pull requests that update a dependency file C-Tests Issues and PRs related to the tests. C-Runtime Issues and PRs related to Boa's runtime features and removed Waiting On Review Waiting on reviews from the maintainers labels Mar 22, 2026
@github-actions github-actions bot added this to the v1.0.0 milestone Mar 22, 2026
@github-actions github-actions bot added the Waiting On Review Waiting on reviews from the maintainers label Mar 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-Dependencies Pull requests that update a dependency file C-Runtime Issues and PRs related to Boa's runtime features C-Tests Issues and PRs related to the tests. Waiting On Review Waiting on reviews from the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement console.table() method

1 participant