aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bun.js/bindings/exports.zig36
-rw-r--r--test/js/web/console/console-log.expected.txt18
-rw-r--r--test/js/web/console/console-log.js4
3 files changed, 50 insertions, 8 deletions
diff --git a/src/bun.js/bindings/exports.zig b/src/bun.js/bindings/exports.zig
index 10326bc7c..784a6289c 100644
--- a/src/bun.js/bindings/exports.zig
+++ b/src/bun.js/bindings/exports.zig
@@ -983,22 +983,42 @@ pub const ZigConsoleClient = struct {
else
console.writer;
var writer = buffered_writer.writer();
-
const Writer = @TypeOf(writer);
- if (len > 0)
+
+ var print_length = len;
+ var print_options: FormatOptions = .{
+ .enable_colors = enable_colors,
+ .add_newline = true,
+ .flush = true,
+ };
+
+ if (message_type == .Dir and len >= 2) {
+ print_length = 1;
+ var opts = vals[1];
+ if (opts.isObject()) {
+ if (opts.get(global, "depth")) |depth_prop| {
+ if (depth_prop.isNumber())
+ print_options.max_depth = depth_prop.toU16();
+ if (depth_prop.isNull() or depth_prop.toInt64() == std.math.maxInt(i64))
+ print_options.max_depth = std.math.maxInt(u16);
+ }
+ if (opts.get(global, "colors")) |colors_prop| {
+ if (colors_prop.isBoolean())
+ print_options.enable_colors = colors_prop.toBoolean();
+ }
+ }
+ }
+
+ if (print_length > 0)
format(
level,
global,
vals,
- len,
+ print_length,
@TypeOf(buffered_writer.unbuffered_writer.context),
Writer,
writer,
- .{
- .enable_colors = enable_colors,
- .add_newline = true,
- .flush = true,
- },
+ print_options,
)
else if (message_type == .Log) {
_ = console.writer.write("\n") catch 0;
diff --git a/test/js/web/console/console-log.expected.txt b/test/js/web/console/console-log.expected.txt
index 78afa857b..39db03722 100644
--- a/test/js/web/console/console-log.expected.txt
+++ b/test/js/web/console/console-log.expected.txt
@@ -57,3 +57,21 @@ String 123 should be 2nd word, 456 == 456 and percent s %s == What okay
}
}
}
+{
+ "1": [Object ...]
+}
+{
+ "1": [Object ...]
+}
+{
+ "1": {
+ "2": [Object ...]
+ }
+}
+{
+ "1": {
+ "2": {
+ "3": 3
+ }
+ }
+}
diff --git a/test/js/web/console/console-log.js b/test/js/web/console/console-log.js
index a70d5e061..95f419781 100644
--- a/test/js/web/console/console-log.js
+++ b/test/js/web/console/console-log.js
@@ -72,3 +72,7 @@ const nestedObject = {
},
};
console.log(nestedObject);
+console.dir({ 1: { 2: { 3: 3 } } }, { depth: 0, colors: false }, "Some ignored arg");
+console.dir({ 1: { 2: { 3: 3 } } }, { depth: -1, colors: false }, "Some ignored arg");
+console.dir({ 1: { 2: { 3: 3 } } }, { depth: 1.2, colors: false }, "Some ignored arg");
+console.dir({ 1: { 2: { 3: 3 } } }, { depth: Infinity, colors: false }, "Some ignored arg");