Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/jsc/ConsoleObject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2800,7 +2800,7 @@
/// conflict with the `&self` borrow `Formatter::write_indent` takes.
/// `self.indent` is a disjoint field read, so passing it by value here
/// keeps the borrow checker happy.
fn write_indent_n(indent: u32, writer: &mut dyn bun_io::Write) -> bun_io::Result<()> {
pub(super) fn write_indent_n(indent: u32, writer: &mut dyn bun_io::Write) -> bun_io::Result<()> {
let mut total_remain: u32 = indent;
while total_remain > 0 {
let written: u8 = total_remain.min(32) as u8;
Expand Down Expand Up @@ -5785,7 +5785,9 @@
} + 1;
*counter.value_ptr = current;

let default_indent = this.default_indent;
let writer = this.writer();
let _ = formatter::write_indent_n(u32::from(default_indent), writer);

Check warning on line 5790 in src/jsc/ConsoleObject.rs

View check run for this annotation

Claude / Claude Code Review

console.assert(false) with no message still not indented inside console.group — same-class sibling missed

Same bug class, sibling site: bare `console.assert(false)` (no message args) inside a `console.group()` still prints `Assertion failed` at column 0 — the `MessageType::Assert && len == 0` early return at [ConsoleObject.rs:419-432](../blob/HEAD/src/jsc/ConsoleObject.rs#L419-L432) writes directly to `error_writer()` and returns before `default_indent` is read. The `len == 0` fallthroughs at lines 543-551 (bare `console.log()` → `\n`, other types → `undefined\n`) share the same shape. Per REVIEW.md
Comment thread
robobun marked this conversation as resolved.
if Output::enable_ansi_colors_stdout() {
let _ = writeln!(
writer,
Expand Down Expand Up @@ -5856,7 +5858,7 @@
#[crate::host_call]
pub(crate) extern "C" fn Bun__ConsoleObject__timeEnd(
_console: *mut ConsoleObject,
_global: &JSGlobalObject,
global_this: &JSGlobalObject,
chars: *const u8,
len: usize,
) {
Expand All @@ -5873,6 +5875,10 @@
return;
};
let Some(value) = prev else { return };
// SAFETY: top-level JS-thread host call ⇒ exclusive access to the
// set-once `VirtualMachine.console` box.
let default_indent = unsafe { vm_console_mut(global_this) }.default_indent;
let _ = formatter::write_indent_n(u32::from(default_indent), Output::error_writer());
// get the duration in microseconds, then display it in milliseconds
Output::print_elapsed(
(value.read() / bun_core::time::NS_PER_US) as f64 / bun_core::time::US_PER_MS as f64,
Expand Down Expand Up @@ -5905,6 +5911,10 @@
let Some(Some(value)) = PENDING_TIME_LOGS.with_borrow(|m| m.get(&id).copied()) else {
return;
};
// SAFETY: top-level JS-thread host call ⇒ exclusive access to the
// set-once `VirtualMachine.console` box.
let default_indent = unsafe { vm_console_mut(global) }.default_indent;
let _ = formatter::write_indent_n(u32::from(default_indent), Output::error_writer());
// get the duration in microseconds, then display it in milliseconds
Output::print_elapsed(
(value.read() / bun_core::time::NS_PER_US) as f64 / bun_core::time::US_PER_MS as f64,
Expand Down
43 changes: 43 additions & 0 deletions test/js/web/console/console-log.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,49 @@ NamedError: console.error a named error
`);
});

it.concurrent("console.group indents console.count and console.time/timeLog/timeEnd", async () => {
const src = `
console.group("G1");
console.count("cnt");
console.count("cnt");
console.group("G2");
console.count("cnt");
console.time("t");
console.timeLog("t");
console.timeEnd("t");
console.groupEnd();
console.count("cnt");
console.groupEnd();
console.count("cnt");
console.time("u");
console.timeEnd("u");
`;
await using proc = Bun.spawn({
cmd: [bunExe(), "-e", src],
env: bunEnv,
stdout: "pipe",
stderr: "pipe",
});
const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);

expect(stdout.replaceAll("\r\n", "\n")).toBe(
"G1\n" + //
" cnt: 1\n" +
" cnt: 2\n" +
" G2\n" +
" cnt: 3\n" +
" cnt: 4\n" +
"cnt: 5\n",
);

const stderrLines = stderr.replaceAll("\r\n", "\n").replace(/\n$/, "").split("\n");
expect(stderrLines.length).toBe(3);
expect(stderrLines[0]).toMatch(/^ \[[\d.]+[mnµ]?s\] t$/);
expect(stderrLines[1]).toMatch(/^ \[[\d.]+[mnµ]?s\] t$/);
expect(stderrLines[2]).toMatch(/^\[[\d.]+[mnµ]?s\] u$/);
expect(exitCode).toBe(0);
});
Comment thread
coderabbitai[bot] marked this conversation as resolved.

it("console.log with SharedArrayBuffer", () => {
// console.log(x) === Bun.inspect(x) + "\n" written to stdout.
expect(Bun.inspect(new ArrayBuffer(0))).toBe("ArrayBuffer(0) []");
Expand Down
Loading