aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js/api/bun.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/bun.js/api/bun.zig')
-rw-r--r--src/bun.js/api/bun.zig76
1 files changed, 68 insertions, 8 deletions
diff --git a/src/bun.js/api/bun.zig b/src/bun.js/api/bun.zig
index d230028ba..7685b8f80 100644
--- a/src/bun.js/api/bun.zig
+++ b/src/bun.js/api/bun.zig
@@ -227,6 +227,71 @@ pub fn inspect(
}
}
+ var formatOptions = ZigConsoleClient.FormatOptions{
+ .enable_colors = false,
+ .add_newline = false,
+ .flush = false,
+ .max_depth = 8,
+ .quote_strings = true,
+ .ordered_properties = false,
+ };
+ var value = JSC.JSValue.fromRef(arguments[0]);
+
+ if (arguments.len > 1) {
+ var arg1: JSC.JSValue = JSC.JSValue.fromRef(arguments[1]);
+
+ if (arg1.isObject()) {
+ if (arg1.getTruthy(ctx, "depth")) |opt| {
+ if (opt.isInt32()) {
+ const arg = opt.toInt32();
+ if (arg < 0) {
+ ctx.throwInvalidArguments("expected depth to be greater than or equal to 0, got {d}", .{arg});
+ return null;
+ }
+ formatOptions.max_depth = @as(u16, @truncate(@as(u32, @intCast(@min(arg, std.math.maxInt(u16))))));
+ } else if (opt.isNumber()) {
+ const v = opt.asDouble();
+ if (std.math.isInf(v)) {
+ formatOptions.max_depth = std.math.maxInt(u16);
+ } else {
+ ctx.throwInvalidArguments("expected depth to be an integer, got {d}", .{v});
+ return null;
+ }
+ }
+ }
+ if (arg1.getOptional(ctx, "colors", bool) catch return null) |opt| {
+ formatOptions.enable_colors = opt;
+ }
+ if (arg1.getOptional(ctx, "sorted", bool) catch return null) |opt| {
+ formatOptions.ordered_properties = opt;
+ }
+ } else {
+ // formatOptions.show_hidden = arg1.toBoolean();
+ if (arguments.len > 2) {
+ var depthArg = JSC.JSValue.fromRef(arguments[1]);
+ if (depthArg.isInt32()) {
+ const arg = depthArg.toInt32();
+ if (arg < 0) {
+ ctx.throwInvalidArguments("expected depth to be greater than or equal to 0, got {d}", .{arg});
+ return null;
+ }
+ formatOptions.max_depth = @as(u16, @truncate(@as(u32, @intCast(@min(arg, std.math.maxInt(u16))))));
+ } else if (depthArg.isNumber()) {
+ const v = depthArg.asDouble();
+ if (std.math.isInf(v)) {
+ formatOptions.max_depth = std.math.maxInt(u16);
+ } else {
+ ctx.throwInvalidArguments("expected depth to be an integer, got {d}", .{v});
+ return null;
+ }
+ }
+ if (arguments.len > 3) {
+ formatOptions.enable_colors = JSC.JSValue.fromRef(arguments[2]).toBoolean();
+ }
+ }
+ }
+ }
+
// very stable memory address
var array = MutableString.init(getAllocator(ctx), 0) catch unreachable;
var buffered_writer_ = MutableString.BufferedWriter{ .context = &array };
@@ -239,17 +304,12 @@ pub fn inspect(
ZigConsoleClient.format(
.Debug,
ctx.ptr(),
- @as([*]const JSValue, @ptrCast(arguments.ptr)),
- arguments.len,
+ @as([*]const JSValue, @ptrCast(&value)),
+ 1,
Writer,
Writer,
writer,
- .{
- .enable_colors = false,
- .add_newline = false,
- .flush = false,
- .max_depth = 32,
- },
+ formatOptions,
);
buffered_writer.flush() catch {
return JSC.C.JSValueMakeUndefined(ctx);