diff options
author | 2022-07-11 04:20:28 -0700 | |
---|---|---|
committer | 2022-07-11 04:20:28 -0700 | |
commit | 3609063d815a9e3fb437308d1bf712658abbc34b (patch) | |
tree | 07bed98e1a4f0076997572c76800783890dfd39d | |
parent | 7904f49b5dc48dc057729eb158067baf54f94cfb (diff) | |
download | bun-3609063d815a9e3fb437308d1bf712658abbc34b.tar.gz bun-3609063d815a9e3fb437308d1bf712658abbc34b.tar.zst bun-3609063d815a9e3fb437308d1bf712658abbc34b.zip |
[js] When `console.log` typed arrays, include the type name and limit printed count to 512
-rw-r--r-- | src/bun.js/bindings/exports.zig | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/src/bun.js/bindings/exports.zig b/src/bun.js/bindings/exports.zig index 9d4db4309..d37633772 100644 --- a/src/bun.js/bindings/exports.zig +++ b/src/bun.js/bindings/exports.zig @@ -2138,25 +2138,30 @@ pub const ZigConsoleClient = struct { writer.writeAll(" }"); }, .TypedArray => { - const len = value.getLengthOfArray(this.globalThis); - if (len == 0) { + const arrayBuffer = value.asArrayBuffer(this.globalThis).?; + if (arrayBuffer.len == 0) { writer.writeAll("[]"); return; } - writer.writeAll("[ "); - var i: u32 = 0; - var buffer = JSC.Buffer.fromJS(this.globalThis, value, null).?; - const slice = buffer.slice(); - while (i < len) : (i += 1) { - if (i > 0) { - this.printComma(Writer, writer_, enable_ansi_colors) catch unreachable; - writer.writeAll(" "); - } + writer.writeAll(std.mem.span(@tagName(arrayBuffer.typed_array_type))); + writer.print("({d}) [ ", .{arrayBuffer.len}); - writer.print(comptime Output.prettyFmt("<r><yellow>{d}<r>", enable_ansi_colors), .{slice[i]}); + const slice = arrayBuffer.slice(); + writer.print(comptime Output.prettyFmt("<r><yellow>{d}<r>", enable_ansi_colors), .{slice[0]}); + var leftover = slice[1..]; + const max = 512; + leftover = leftover[0..@minimum(leftover.len, max)]; + for (leftover) |el| { + this.printComma(Writer, writer_, enable_ansi_colors) catch unreachable; + writer.writeAll(" "); + + writer.print(comptime Output.prettyFmt("<r><yellow>{d}<r>", enable_ansi_colors), .{el}); } + if (slice.len > max + 1) { + writer.print(comptime Output.prettyFmt("<r><d>, ... {d} more<r>", enable_ansi_colors), .{slice.len - max - 1}); + } writer.writeAll(" ]"); }, else => {}, |