Skip to content

Commit

Permalink
feat: console.table implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
sumitparakh committed Jan 12, 2025
1 parent cf2aa58 commit f37f5e3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
16 changes: 16 additions & 0 deletions core/runtime/src/console/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,11 @@ impl Console {
js_string!("warn"),
0,
)
.function(
console_method(Self::table, state.clone(), logger.clone()),
js_string!("table"),
0
)
.function(
console_method_mut(Self::count, state.clone(), logger.clone()),
js_string!("count"),
Expand Down Expand Up @@ -548,6 +553,17 @@ impl Console {
Ok(JsValue::undefined())
}

fn table(
_: &JsValue,
args: &[JsValue],
console: &Self,
logger: &impl Logger,
context: &mut Context,
) -> JsResult<JsValue> {
logger.log(formatter(args, context)?, &console.state, context)?;
Ok(JsValue::undefined())
}

/// `console.trace(...data)`
///
/// Prints a stack trace with "trace" logLevel, optionally labelled by data.
Expand Down
2 changes: 2 additions & 0 deletions core/runtime/src/console/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ fn console_log_cyclic() {
let a = [1];
a[1] = a;
console.log(a);
let obj = {a: 1, b: 2};
console.table(obj);
"#})],
&mut context,
);
Expand Down

0 comments on commit f37f5e3

Please sign in to comment.