diff options
author | 2023-08-17 20:56:52 -0700 | |
---|---|---|
committer | 2023-08-17 20:56:52 -0700 | |
commit | 6fd0043f6bf766cc488a88339059e8879fa07161 (patch) | |
tree | d5289bcaf0880a3bf1e2f0b1c681aff93188fe51 | |
parent | 0424fd8f6e7549ed779788006acdc97a8467e287 (diff) | |
download | bun-6fd0043f6bf766cc488a88339059e8879fa07161.tar.gz bun-6fd0043f6bf766cc488a88339059e8879fa07161.tar.zst bun-6fd0043f6bf766cc488a88339059e8879fa07161.zip |
Add `util.inspect.custom` support to `util.inspect/Bun.inspect/console.log` (#4194)
* start work on util.inspect.custom
* asdf
* finish util inspect custom inspect
* inspect
* fix tests
* revert
* tidy
* revert
* oops
* test
* fix issues
-rw-r--r-- | packages/bun-types/bun.d.ts | 14 | ||||
-rw-r--r-- | src/bun.js/api/bun.zig | 76 | ||||
-rw-r--r-- | src/bun.js/bindings/ZigGlobalObject.cpp | 38 | ||||
-rw-r--r-- | src/bun.js/bindings/ZigGlobalObject.h | 7 | ||||
-rw-r--r-- | src/bun.js/bindings/bindings.cpp | 40 | ||||
-rw-r--r-- | src/bun.js/bindings/bindings.zig | 1 | ||||
-rw-r--r-- | src/bun.js/bindings/exports.zig | 134 | ||||
-rw-r--r-- | src/js/builtins/UtilInspect.ts | 17 | ||||
-rw-r--r-- | src/js/node/util.js | 53 | ||||
-rw-r--r-- | src/js/out/InternalModuleRegistryConstants.h | 6 | ||||
-rw-r--r-- | src/js/out/WebCoreJSBuiltins.cpp | 26 | ||||
-rw-r--r-- | src/js/out/WebCoreJSBuiltins.h | 92 | ||||
-rw-r--r-- | test/js/bun/util/inspect.test.js | 44 | ||||
-rw-r--r-- | test/js/node/util/bun-inspect.test.ts | 23 | ||||
-rw-r--r-- | test/js/node/util/custom-inspect.test.js | 155 |
15 files changed, 648 insertions, 78 deletions
diff --git a/packages/bun-types/bun.d.ts b/packages/bun-types/bun.d.ts index 7e8102c87..a89e943b3 100644 --- a/packages/bun-types/bun.d.ts +++ b/packages/bun-types/bun.d.ts @@ -2295,6 +2295,12 @@ declare module "bun" { */ export function allocUnsafe(size: number): Uint8Array; + export interface BunInspectOptions { + colors?: boolean; + depth?: number; + sorted?: boolean; + } + /** * Pretty-print an object the same as {@link console.log} to a `string` * @@ -2302,7 +2308,7 @@ declare module "bun" { * * @param args */ - export function inspect(...args: any): string; + export function inspect(arg: any, options: BunInspectOptions): string; interface MMapOptions { /** @@ -3623,16 +3629,16 @@ declare module "bun" { > : SyncSubprocess<Readable, Readable>; - type ReadableIO = ReadableStream<Buffer> | number | undefined; + type ReadableIO = ReadableStream<Uint8Array> | number | undefined; type ReadableToIO<X extends Readable> = X extends "pipe" | undefined - ? ReadableStream<Buffer> + ? ReadableStream<Uint8Array> : X extends BunFile | ArrayBufferView | number ? number : undefined; type ReadableToSyncIO<X extends Readable> = X extends "pipe" | undefined - ? Buffer + ? Uint8Array : undefined; type WritableIO = FileSink | number | undefined; 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); diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index 5524166c3..b6ac8e7ea 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -3270,6 +3270,41 @@ void GlobalObject::finishCreation(VM& vm) init.set(JSFunction::create(init.vm, init.owner, 4, "performMicrotaskVariadic"_s, jsFunctionPerformMicrotaskVariadic, ImplementationVisibility::Public)); }); + m_utilInspectFunction.initLater( + [](const Initializer<JSFunction>& init) { + JSValue nodeUtilValue = static_cast<Zig::GlobalObject*>(init.owner)->internalModuleRegistry()->requireId(init.owner, init.vm, Bun::InternalModuleRegistry::Field::NodeUtil); + RELEASE_ASSERT(nodeUtilValue.isObject()); + init.set(jsCast<JSFunction*>(nodeUtilValue.getObject()->getIfPropertyExists(init.owner, Identifier::fromString(init.vm, "inspect"_s)))); + }); + + m_utilInspectStylizeColorFunction.initLater( + [](const Initializer<JSFunction>& init) { + auto scope = DECLARE_THROW_SCOPE(init.vm); + JSC::JSFunction* getStylize = JSC::JSFunction::create(init.vm, utilInspectGetStylizeWithColorCodeGenerator(init.vm), init.owner); + // RETURN_IF_EXCEPTION(scope, {}); + + JSC::MarkedArgumentBuffer args; + args.append(static_cast<Zig::GlobalObject*>(init.owner)->utilInspectFunction()); + + auto clientData = WebCore::clientData(init.vm); + JSC::CallData callData = JSC::getCallData(getStylize); + + NakedPtr<JSC::Exception> returnedException = nullptr; + auto result = JSC::call(init.owner, getStylize, callData, jsNull(), args, returnedException); + // RETURN_IF_EXCEPTION(scope, {}); + + if (returnedException) { + throwException(init.owner, scope, returnedException.get()); + } + // RETURN_IF_EXCEPTION(scope, {}); + init.set(jsCast<JSFunction*>(result)); + }); + + m_utilInspectStylizeNoColorFunction.initLater( + [](const Initializer<JSFunction>& init) { + init.set(JSC::JSFunction::create(init.vm, utilInspectStylizeWithNoColorCodeGenerator(init.vm), init.owner)); + }); + m_nativeMicrotaskTrampoline.initLater( [](const Initializer<JSFunction>& init) { init.set(JSFunction::create(init.vm, init.owner, 2, ""_s, functionNativeMicrotaskTrampoline, ImplementationVisibility::Public)); @@ -4606,6 +4641,9 @@ void GlobalObject::visitChildrenImpl(JSCell* cell, Visitor& visitor) thisObject->m_pendingVirtualModuleResultStructure.visit(visitor); thisObject->m_performMicrotaskFunction.visit(visitor); thisObject->m_performMicrotaskVariadicFunction.visit(visitor); + thisObject->m_utilInspectFunction.visit(visitor); + thisObject->m_utilInspectStylizeColorFunction.visit(visitor); + thisObject->m_utilInspectStylizeNoColorFunction.visit(visitor); thisObject->m_lazyReadableStreamPrototypeMap.visit(visitor); thisObject->m_requireMap.visit(visitor); thisObject->m_encodeIntoObjectStructure.visit(visitor); diff --git a/src/bun.js/bindings/ZigGlobalObject.h b/src/bun.js/bindings/ZigGlobalObject.h index 0535b1e8f..68bd8aeb0 100644 --- a/src/bun.js/bindings/ZigGlobalObject.h +++ b/src/bun.js/bindings/ZigGlobalObject.h @@ -258,6 +258,10 @@ public: JSC::JSFunction* performMicrotaskFunction() { return m_performMicrotaskFunction.getInitializedOnMainThread(this); } JSC::JSFunction* performMicrotaskVariadicFunction() { return m_performMicrotaskVariadicFunction.getInitializedOnMainThread(this); } + JSC::JSFunction* utilInspectFunction() { return m_utilInspectFunction.getInitializedOnMainThread(this); } + JSC::JSFunction* utilInspectStylizeColorFunction() { return m_utilInspectStylizeColorFunction.getInitializedOnMainThread(this); } + JSC::JSFunction* utilInspectStylizeNoColorFunction() { return m_utilInspectStylizeNoColorFunction.getInitializedOnMainThread(this); } + JSC::JSFunction* emitReadableNextTickFunction() { return m_emitReadableNextTickFunction.getInitializedOnMainThread(this); } JSObject* requireFunctionUnbound() { return m_requireFunctionUnbound.getInitializedOnMainThread(this); } @@ -513,6 +517,9 @@ private: LazyProperty<JSGlobalObject, JSFunction> m_performMicrotaskFunction; LazyProperty<JSGlobalObject, JSFunction> m_nativeMicrotaskTrampoline; LazyProperty<JSGlobalObject, JSFunction> m_performMicrotaskVariadicFunction; + LazyProperty<JSGlobalObject, JSFunction> m_utilInspectFunction; + LazyProperty<JSGlobalObject, JSFunction> m_utilInspectStylizeColorFunction; + LazyProperty<JSGlobalObject, JSFunction> m_utilInspectStylizeNoColorFunction; LazyProperty<JSGlobalObject, JSFunction> m_emitReadableNextTickFunction; LazyProperty<JSGlobalObject, JSMap> m_lazyReadableStreamPrototypeMap; LazyProperty<JSGlobalObject, JSMap> m_requireMap; diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp index e1d6ba526..5e5f43c99 100644 --- a/src/bun.js/bindings/bindings.cpp +++ b/src/bun.js/bindings/bindings.cpp @@ -3957,6 +3957,7 @@ enum class BuiltinNamesMap : uint8_t { data, toString, redirect, + inspectCustom, }; static JSC::Identifier builtinNameMap(JSC::JSGlobalObject* globalObject, unsigned char name) @@ -3988,7 +3989,46 @@ static JSC::Identifier builtinNameMap(JSC::JSGlobalObject* globalObject, unsigne case BuiltinNamesMap::redirect: { return clientData->builtinNames().redirectPublicName(); } + case BuiltinNamesMap::inspectCustom: { + return Identifier::fromUid(vm.symbolRegistry().symbolForKey("nodejs.util.inspect.custom"_s)); } + } +} + +extern "C" EncodedJSValue JSC__JSValue__callCustomInspectFunction( + JSC::JSGlobalObject* lexicalGlobalObject, + JSC__JSValue encodedFunctionValue, + JSC__JSValue encodedThisValue, + unsigned depth, + unsigned max_depth, + bool colors) +{ + auto* globalObject = jsCast<Zig::GlobalObject*>(lexicalGlobalObject); + JSValue functionToCall = JSValue::decode(encodedFunctionValue); + JSValue thisValue = JSValue::decode(encodedThisValue); + JSC::VM& vm = globalObject->vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + + JSFunction* inspectFn = globalObject->utilInspectFunction(); + JSFunction* stylizeFn = colors ? globalObject->utilInspectStylizeColorFunction() : globalObject->utilInspectStylizeNoColorFunction(); + + JSObject* options = JSC::constructEmptyObject(globalObject); + options->putDirect(vm, Identifier::fromString(vm, "stylize"_s), stylizeFn); + options->putDirect(vm, Identifier::fromString(vm, "depth"_s), jsNumber(max_depth)); + options->putDirect(vm, Identifier::fromString(vm, "colors"_s), jsBoolean(colors)); + + auto callData = JSC::getCallData(functionToCall); + MarkedArgumentBuffer arguments; + arguments.append(jsNumber(depth)); + arguments.append(options); + arguments.append(inspectFn); + + auto inspectRet = JSC::call(globalObject, functionToCall, callData, thisValue, arguments); + if (auto exe = scope.exception()) { + scope.clearException(); + return JSValue::encode(exe); + } + RELEASE_AND_RETURN(scope, JSValue::encode(inspectRet)); } JSC__JSValue JSC__JSValue__fastGetDirect_(JSC__JSValue JSValue0, JSC__JSGlobalObject* globalObject, unsigned char arg2) diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig index 529315a59..dc9740865 100644 --- a/src/bun.js/bindings/bindings.zig +++ b/src/bun.js/bindings/bindings.zig @@ -4240,6 +4240,7 @@ pub const JSValue = enum(JSValueReprInt) { data, toString, redirect, + inspectCustom, }; // intended to be more lightweight than ZigString diff --git a/src/bun.js/bindings/exports.zig b/src/bun.js/bindings/exports.zig index bdfabaeee..0f234f876 100644 --- a/src/bun.js/bindings/exports.zig +++ b/src/bun.js/bindings/exports.zig @@ -1187,7 +1187,7 @@ pub const ZigConsoleClient = struct { tag = ZigConsoleClient.Formatter.Tag.get(this_value, global); if (tag.tag == .String and fmt.remaining_values.len > 0) { - tag.tag = .StringPossiblyFormatted; + tag.tag = .{ .StringPossiblyFormatted = {} }; } fmt.format(tag, Writer, writer, this_value, global, true); @@ -1209,7 +1209,7 @@ pub const ZigConsoleClient = struct { any = true; tag = ZigConsoleClient.Formatter.Tag.get(this_value, global); if (tag.tag == .String and fmt.remaining_values.len > 0) { - tag.tag = .StringPossiblyFormatted; + tag.tag = .{ .StringPossiblyFormatted = {} }; } fmt.format(tag, Writer, writer, this_value, global, false); @@ -1224,6 +1224,11 @@ pub const ZigConsoleClient = struct { if (options.add_newline) _ = writer.write("\n") catch 0; } + const CustomFormattedObject = struct { + function: JSValue = .zero, + this: JSValue = .zero, + }; + pub const Formatter = struct { remaining_values: []const JSValue = &[_]JSValue{}, map: Visited.Map = undefined, @@ -1239,6 +1244,7 @@ pub const ZigConsoleClient = struct { estimated_line_length: usize = 0, always_newline_scope: bool = false, ordered_properties: bool = false, + custom_formatted_object: CustomFormattedObject = .{}, pub fn goodTimeForANewLine(this: *@This()) bool { if (this.estimated_line_length > 80) { @@ -1311,8 +1317,10 @@ pub const ZigConsoleClient = struct { TypedArray, Map, Set, - Symbol, BigInt, + Symbol, + + CustomFormattedObject, GlobalObject, Private, @@ -1349,7 +1357,41 @@ pub const ZigConsoleClient = struct { } const Result = struct { - tag: Tag, + tag: union(Tag) { + StringPossiblyFormatted: void, + String: void, + Undefined: void, + Double: void, + Integer: void, + Null: void, + Boolean: void, + Array: void, + Object: void, + Function: void, + Class: void, + Error: void, + TypedArray: void, + Map: void, + Set: void, + BigInt: void, + Symbol: void, + GlobalObject: void, + Private: void, + Promise: void, + JSON: void, + toJSON: void, + NativeCode: void, + ArrayBuffer: void, + JSX: void, + Event: void, + Getter: void, + + CustomFormattedObject: CustomFormattedObject, + + pub fn isPrimitive(this: @This()) bool { + return @as(Tag, this).isPrimitive(); + } + }, cell: JSValue.JSType = JSValue.JSType.Cell, }; @@ -1364,37 +1406,37 @@ pub const ZigConsoleClient = struct { pub fn getAdvanced(value: JSValue, globalThis: *JSGlobalObject, opts: Options) Result { switch (@intFromEnum(value)) { 0, 0xa => return Result{ - .tag = .Undefined, + .tag = .{ .Undefined = {} }, }, 0x2 => return Result{ - .tag = .Null, + .tag = .{ .Null = {} }, }, else => {}, } if (value.isInt32()) { return .{ - .tag = .Integer, + .tag = .{ .Integer = {} }, }; } else if (value.isNumber()) { return .{ - .tag = .Double, + .tag = .{ .Double = {} }, }; } else if (value.isBoolean()) { return .{ - .tag = .Boolean, + .tag = .{ .Boolean = {} }, }; } if (!value.isCell()) return .{ - .tag = .NativeCode, + .tag = .{ .NativeCode = {} }, }; const js_type = value.jsType(); if (js_type.isHidden()) return .{ - .tag = .NativeCode, + .tag = .{ .NativeCode = {} }, .cell = js_type, }; @@ -1402,21 +1444,38 @@ pub const ZigConsoleClient = struct { // if we call JSObjectGetPrivate, it can segfault if (js_type == .Cell) { return .{ - .tag = .NativeCode, + .tag = .{ .NativeCode = {} }, .cell = js_type, }; } + if (js_type.canGet()) { + // Attempt to get custom formatter + if (value.fastGet(globalThis, .inspectCustom)) |callback_value| { + if (callback_value.isCallable(globalThis.vm())) { + return .{ + .tag = .{ + .CustomFormattedObject = .{ + .function = callback_value, + .this = value, + }, + }, + .cell = js_type, + }; + } + } + } + if (js_type == .DOMWrapper) { return .{ - .tag = .Private, + .tag = .{ .Private = {} }, .cell = js_type, }; } if (CAPI.JSObjectGetPrivate(value.asObjectRef()) != null) return .{ - .tag = .Private, + .tag = .{ .Private = {} }, .cell = js_type, }; @@ -1425,7 +1484,7 @@ pub const ZigConsoleClient = struct { if (js_type != .Object and value.isCallable(globalThis.vm())) { if (value.isClass(globalThis)) { return .{ - .tag = .Class, + .tag = .{ .Class = {} }, .cell = js_type, }; } @@ -1448,7 +1507,7 @@ pub const ZigConsoleClient = struct { ); } return .{ - .tag = .GlobalObject, + .tag = .{ .GlobalObject = {} }, .cell = js_type, }; } @@ -1460,7 +1519,7 @@ pub const ZigConsoleClient = struct { var react_fragment = ZigString.init("react.fragment"); if (JSValue.isSameValue(typeof_symbol, JSValue.symbolFor(globalThis, &reactElement), globalThis) or JSValue.isSameValue(typeof_symbol, JSValue.symbolFor(globalThis, &react_fragment), globalThis)) { - return .{ .tag = .JSX, .cell = js_type }; + return .{ .tag = .{ .JSX = {} }, .cell = js_type }; } } } @@ -1676,11 +1735,10 @@ pub const ZigConsoleClient = struct { comptime Writer: type, writer: Writer, ) !void { - const indent = @min(this.indent, 32); var buf = [_]u8{' '} ** 64; - var total_remain: usize = indent; + var total_remain: u32 = this.indent; while (total_remain > 0) { - const written = @min(32, total_remain); + const written: u8 = @min(32, total_remain); try writer.writeAll(buf[0 .. written * 2]); total_remain -|= written; } @@ -1899,6 +1957,15 @@ pub const ZigConsoleClient = struct { }; } + extern fn JSC__JSValue__callCustomInspectFunction( + *JSC.JSGlobalObject, + JSValue, + JSValue, + depth: u32, + max_depth: u32, + colors: bool, + ) JSValue; + pub fn printAs( this: *ZigConsoleClient.Formatter, comptime Format: ZigConsoleClient.Formatter.Tag, @@ -2068,6 +2135,24 @@ pub const ZigConsoleClient = struct { this.addForNewLine(4); writer.print(comptime Output.prettyFmt("<r><yellow>null<r>", enable_ansi_colors), .{}); }, + .CustomFormattedObject => { + // Call custom inspect function. Will return the error if there is one + // we'll need to pass the callback through to the "this" value in here + const result = JSC__JSValue__callCustomInspectFunction( + this.globalThis, + this.custom_formatted_object.function, + this.custom_formatted_object.this, + this.max_depth - this.depth, + this.max_depth, + enable_ansi_colors, + ); + // Strings are printed directly, otherwise we recurse. It is possible to end up in an infinite loop. + if (result.isString()) { + writer.print("{}", .{result.toBunString(this.globalThis)}); + } else { + this.format(ZigConsoleClient.Formatter.Tag.get(result, this.globalThis), Writer, writer_, result, this.globalThis, enable_ansi_colors); + } + }, .Symbol => { const description = value.getDescription(this.globalThis); this.addForNewLine("Symbol".len); @@ -2973,7 +3058,7 @@ pub const ZigConsoleClient = struct { // comptime var so we have to repeat it here. The rationale there is // it _should_ limit the stack usage because each version of the // function will be relatively small - return switch (result.tag) { + switch (result.tag) { .StringPossiblyFormatted => this.printAs(.StringPossiblyFormatted, Writer, writer, value, result.cell, enable_ansi_colors), .String => this.printAs(.String, Writer, writer, value, result.cell, enable_ansi_colors), .Undefined => this.printAs(.Undefined, Writer, writer, value, result.cell, enable_ansi_colors), @@ -3005,7 +3090,12 @@ pub const ZigConsoleClient = struct { .JSX => this.printAs(.JSX, Writer, writer, value, result.cell, enable_ansi_colors), .Event => this.printAs(.Event, Writer, writer, value, result.cell, enable_ansi_colors), .Getter => this.printAs(.Getter, Writer, writer, value, result.cell, enable_ansi_colors), - }; + + .CustomFormattedObject => |callback| { + this.custom_formatted_object = callback; + this.printAs(.CustomFormattedObject, Writer, writer, value, result.cell, enable_ansi_colors); + }, + } } }; diff --git a/src/js/builtins/UtilInspect.ts b/src/js/builtins/UtilInspect.ts new file mode 100644 index 000000000..586f03b57 --- /dev/null +++ b/src/js/builtins/UtilInspect.ts @@ -0,0 +1,17 @@ +type Inspect = typeof import("util").inspect; + +// This is passed to [util.inspect.custom](..., { stylize }) to help users colorize parts. +export function getStylizeWithColor(inspect: Inspect) { + return function stylizeWithColor(str: string, styleType: string) { + const style = inspect.styles[styleType]; + if (style !== undefined) { + const color = inspect.colors[style]; + if (color !== undefined) return `\u001b[${color[0]}m${str}\u001b[${color[1]}m`; + } + return str; + }; +} + +export function stylizeWithNoColor(str: string) { + return str; +} diff --git a/src/js/node/util.js b/src/js/node/util.js index 2a3bbfad1..10dc95e2e 100644 --- a/src/js/node/util.js +++ b/src/js/node/util.js @@ -123,6 +123,7 @@ function debuglog(set) { } return debugs[set]; } +var kInspectCustom = Symbol.for("nodejs.util.inspect.custom"); function inspect(obj, opts) { var ctx = { seen: [], @@ -167,13 +168,29 @@ inspect.styles = { date: "magenta", regexp: "red", }; +inspect.custom = kInspectCustom; +// JS polyfill doesnt support all these options +inspect.defaultOptions = { + showHidden: false, + depth: 2, + colors: false, + customInspect: true, + showProxy: false, + maxArrayLength: 100, + maxStringLength: 10000, + breakLength: 80, + compact: 3, + sorted: false, + getters: false, + numericSeparator: false, +}; function stylizeWithColor(str, styleType) { - var style = inspect.styles[styleType]; - if (style) { - return "\x1B[" + inspect.colors[style][0] + "m" + str + "\x1B[" + inspect.colors[style][1] + "m"; - } else { - return str; + const style = inspect.styles[styleType]; + if (style !== undefined) { + const color = inspect.colors[style]; + if (color !== undefined) return `\u001b[${color[0]}m${str}\u001b[${color[1]}m`; } + return str; } function stylizeNoColor(str, styleType) { return str; @@ -186,24 +203,21 @@ function arrayToHash(array) { return hash; } function formatValue(ctx, value, recurseTimes) { - if ( - ctx.customInspect && - value && - isFunction(value.inspect) && - value.inspect !== inspect && - !(value.constructor && value.constructor.prototype === value) - ) { - var ret = value.inspect(recurseTimes, ctx); - if (!isString(ret)) { - ret = formatValue(ctx, ret, recurseTimes); + if (ctx.customInspect && value) { + const customInspect = value[kInspectCustom]; + if (isFunction(customInspect)) { + var ret = customInspect.call(value, recurseTimes, ctx, inspect); + if (!isString(ret)) { + ret = formatValue(ctx, ret, recurseTimes); + } + return ret; } - return ret; } var primitive = formatPrimitive(ctx, value); if (primitive) { return primitive; } - var keys = Object.keys(value); + var keys = Object.keys(value).concat(Object.getOwnPropertySymbols(value)); var visibleKeys = arrayToHash(keys); if (ctx.showHidden) { keys = Object.getOwnPropertyNames(value); @@ -314,7 +328,10 @@ function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) { } } if (!hasOwnProperty(visibleKeys, key)) { - name = "[" + key + "]"; + name = "[" + (typeof key === "symbol" ? key.description : key) + "]"; + } + if (typeof key === "symbol") { + name = "[" + ctx.stylize(`Symbol(${key.description})`, "string") + "]"; } if (!str) { if (ctx.seen.indexOf(desc.value) < 0) { diff --git a/src/js/out/InternalModuleRegistryConstants.h b/src/js/out/InternalModuleRegistryConstants.h index 6f6c0676c..4e03279fa 100644 --- a/src/js/out/InternalModuleRegistryConstants.h +++ b/src/js/out/InternalModuleRegistryConstants.h @@ -178,7 +178,7 @@ static constexpr ASCIILiteral NodeUrlCode = "(function (){\"use strict\";// src/ // // -static constexpr ASCIILiteral NodeUtilCode = "(function (){\"use strict\";// src/js/out/tmp/node/util.ts\nvar isBufferInterface = function({ copy, fill, readUint8 }) {\n return typeof copy === \"function\" && typeof fill === \"function\" && typeof readUint8 === \"function\";\n}, isBuffer = function(value) {\n return Buffer.isBuffer(value) || typeof value === \"object\" && isBufferInterface(value || {});\n}, isFunction = function(value) {\n return typeof value === \"function\";\n}, formatWithOptions = function(inspectOptions, f) {\n if (!isString(f)) {\n var objects = [];\n for (var i = 0;i < arguments.length; i++)\n objects.push(inspect(arguments[i], inspectOptions));\n return objects.join(\" \");\n }\n var i = 2, args = arguments, len = args.length, str = String(f).replace(formatRegExp, function(x2) {\n if (x2 === \"%%\")\n return \"%\";\n if (i >= len)\n return x2;\n switch (x2) {\n case \"%s\":\n return String(args[i++]);\n case \"%f\":\n return Number(args[i++]);\n case \"%d\":\n return Math.round(Number(args[i++]));\n case \"%j\":\n try {\n return JSON.stringify(args[i++]);\n } catch (_) {\n return \"[Circular]\";\n }\n case \"%o\":\n return inspect(args[i++], { showHidden: !0, showProxy: !0, ...inspectOptions });\n case \"%O\":\n return inspect(args[i++], { showHidden: !0, showProxy: !0, ...inspectOptions });\n default:\n return x2;\n }\n });\n for (var x = args[i];i < len; x = args[++i])\n if (isNull(x) || !isObject(x))\n str += \" \" + x;\n else\n str += \" \" + inspect(x, inspectOptions);\n return str;\n}, format = function(...args) {\n return formatWithOptions({}, ...args);\n}, deprecate = function(fn, msg, code) {\n if (process.noDeprecation === !0)\n return fn;\n var warned = !1;\n function deprecated() {\n if (!warned) {\n if (process.throwDeprecation) {\n var err = new Error(msg);\n if (code)\n err.code = code;\n throw err;\n } else if (process.traceDeprecation)\n console.trace(msg);\n else\n console.error(msg);\n warned = !0;\n }\n return fn.apply(this, arguments);\n }\n return deprecated;\n}, debuglog = function(set) {\n if (set = set.toUpperCase(), !debugs[set])\n if (debugEnvRegex.test(set)) {\n var pid = process.pid;\n debugs[set] = function() {\n var msg = format.apply(cjs_exports, arguments);\n console.error(\"%s %d: %s\", set, pid, msg);\n };\n } else\n debugs[set] = function() {\n };\n return debugs[set];\n}, inspect = function(obj, opts) {\n var ctx = {\n seen: [],\n stylize: stylizeNoColor\n };\n if (arguments.length >= 3)\n ctx.depth = arguments[2];\n if (arguments.length >= 4)\n ctx.colors = arguments[3];\n if (isBoolean(opts))\n ctx.showHidden = opts;\n else if (opts)\n _extend(ctx, opts);\n if (isUndefined(ctx.showHidden))\n ctx.showHidden = !1;\n if (isUndefined(ctx.depth))\n ctx.depth = 2;\n if (isUndefined(ctx.colors))\n ctx.colors = !1;\n if (isUndefined(ctx.customInspect))\n ctx.customInspect = !0;\n if (ctx.colors)\n ctx.stylize = stylizeWithColor;\n return formatValue(ctx, obj, ctx.depth);\n}, stylizeWithColor = function(str, styleType) {\n var style = inspect.styles[styleType];\n if (style)\n return \"\\x1B[\" + inspect.colors[style][0] + \"m\" + str + \"\\x1B[\" + inspect.colors[style][1] + \"m\";\n else\n return str;\n}, stylizeNoColor = function(str, styleType) {\n return str;\n}, arrayToHash = function(array) {\n var hash = {};\n return array.forEach(function(val, idx) {\n hash[val] = !0;\n }), hash;\n}, formatValue = function(ctx, value, recurseTimes) {\n if (ctx.customInspect && value && isFunction(value.inspect) && value.inspect !== inspect && !(value.constructor && value.constructor.prototype === value)) {\n var ret = value.inspect(recurseTimes, ctx);\n if (!isString(ret))\n ret = formatValue(ctx, ret, recurseTimes);\n return ret;\n }\n var primitive = formatPrimitive(ctx, value);\n if (primitive)\n return primitive;\n var keys = Object.keys(value), visibleKeys = arrayToHash(keys);\n if (ctx.showHidden)\n keys = Object.getOwnPropertyNames(value);\n if (isError(value) && (keys.indexOf(\"message\") >= 0 || keys.indexOf(\"description\") >= 0))\n return formatError(value);\n if (keys.length === 0) {\n if (isFunction(value)) {\n var name = value.name \? \": \" + value.name : \"\";\n return ctx.stylize(\"[Function\" + name + \"]\", \"special\");\n }\n if (isRegExp(value))\n return ctx.stylize(RegExp.prototype.toString.call(value), \"regexp\");\n if (isDate(value))\n return ctx.stylize(Date.prototype.toString.call(value), \"date\");\n if (isError(value))\n return formatError(value);\n }\n var base = \"\", array = !1, braces = [\"{\", \"}\"];\n if (@isArray(value))\n array = !0, braces = [\"[\", \"]\"];\n if (isFunction(value)) {\n var n = value.name \? \": \" + value.name : \"\";\n base = \" [Function\" + n + \"]\";\n }\n if (isRegExp(value))\n base = \" \" + RegExp.prototype.toString.call(value);\n if (isDate(value))\n base = \" \" + Date.prototype.toUTCString.call(value);\n if (isError(value))\n base = \" \" + formatError(value);\n if (keys.length === 0 && (!array || value.length == 0))\n return braces[0] + base + braces[1];\n if (recurseTimes < 0)\n if (isRegExp(value))\n return ctx.stylize(RegExp.prototype.toString.call(value), \"regexp\");\n else\n return ctx.stylize(\"[Object]\", \"special\");\n ctx.seen.push(value);\n var output;\n if (array)\n output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);\n else\n output = keys.map(function(key) {\n return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);\n });\n return ctx.seen.pop(), reduceToSingleString(output, base, braces);\n}, formatPrimitive = function(ctx, value) {\n if (isUndefined(value))\n return ctx.stylize(\"undefined\", \"undefined\");\n if (isString(value)) {\n var simple = \"'\" + JSON.stringify(value).replace(/^\"|\"$/g, \"\").replace(/'/g, \"\\\\'\").replace(/\\\\\"/g, '\"') + \"'\";\n return ctx.stylize(simple, \"string\");\n }\n if (isNumber(value))\n return ctx.stylize(\"\" + value, \"number\");\n if (isBoolean(value))\n return ctx.stylize(\"\" + value, \"boolean\");\n if (isNull(value))\n return ctx.stylize(\"null\", \"null\");\n}, formatError = function(value) {\n return \"[\" + Error.prototype.toString.call(value) + \"]\";\n}, formatArray = function(ctx, value, recurseTimes, visibleKeys, keys) {\n var output = [];\n for (var i = 0, l = value.length;i < l; ++i)\n if (hasOwnProperty(value, String(i)))\n output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, String(i), !0));\n else\n output.push(\"\");\n return keys.forEach(function(key) {\n if (!key.match(/^\\d+$/))\n output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, key, !0));\n }), output;\n}, formatProperty = function(ctx, value, recurseTimes, visibleKeys, key, array) {\n var name, str, desc;\n if (desc = Object.getOwnPropertyDescriptor(value, key) || {\n value: value[key]\n }, desc.get)\n if (desc.set)\n str = ctx.stylize(\"[Getter/Setter]\", \"special\");\n else\n str = ctx.stylize(\"[Getter]\", \"special\");\n else if (desc.set)\n str = ctx.stylize(\"[Setter]\", \"special\");\n if (!hasOwnProperty(visibleKeys, key))\n name = \"[\" + key + \"]\";\n if (!str)\n if (ctx.seen.indexOf(desc.value) < 0) {\n if (isNull(recurseTimes))\n str = formatValue(ctx, desc.value, null);\n else\n str = formatValue(ctx, desc.value, recurseTimes - 1);\n if (str.indexOf(\"\\n\") > -1)\n if (array)\n str = str.split(\"\\n\").map(function(line) {\n return \" \" + line;\n }).join(\"\\n\").substr(2);\n else\n str = \"\\n\" + str.split(\"\\n\").map(function(line) {\n return \" \" + line;\n }).join(\"\\n\");\n } else\n str = ctx.stylize(\"[Circular]\", \"special\");\n if (isUndefined(name)) {\n if (array && key.match(/^\\d+$/))\n return str;\n if (name = JSON.stringify(\"\" + key), name.match(/^\"([a-zA-Z_][a-zA-Z_0-9]*)\"$/))\n name = name.substr(1, name.length - 2), name = ctx.stylize(name, \"name\");\n else\n name = name.replace(/'/g, \"\\\\'\").replace(/\\\\\"/g, '\"').replace(/(^\"|\"$)/g, \"'\"), name = ctx.stylize(name, \"string\");\n }\n return name + \": \" + str;\n}, reduceToSingleString = function(output, base, braces) {\n var numLinesEst = 0, length = output.reduce(function(prev, cur) {\n if (numLinesEst++, cur.indexOf(\"\\n\") >= 0)\n numLinesEst++;\n return prev + cur.replace(/\\u001b\\[\\d\\d\?m/g, \"\").length + 1;\n }, 0);\n if (length > 60)\n return braces[0] + (base === \"\" \? \"\" : base + \"\\n \") + \" \" + output.join(\",\\n \") + \" \" + braces[1];\n return braces[0] + base + \" \" + output.join(\", \") + \" \" + braces[1];\n}, isBoolean = function(arg) {\n return typeof arg === \"boolean\";\n}, isNull = function(arg) {\n return arg === null;\n}, isNullOrUndefined = function(arg) {\n return arg == null;\n}, isNumber = function(arg) {\n return typeof arg === \"number\";\n}, isString = function(arg) {\n return typeof arg === \"string\";\n}, isSymbol = function(arg) {\n return typeof arg === \"symbol\";\n}, isUndefined = function(arg) {\n return arg === void 0;\n}, isObject = function(arg) {\n return typeof arg === \"object\" && arg !== null;\n}, isPrimitive = function(arg) {\n return arg === null || typeof arg === \"boolean\" || typeof arg === \"number\" || typeof arg === \"string\" || typeof arg === \"symbol\" || typeof arg === \"undefined\";\n}, pad = function(n) {\n return n < 10 \? \"0\" + n.toString(10) : n.toString(10);\n}, timestamp = function() {\n var d = new Date, time = [pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].join(\":\");\n return [d.getDate(), months[d.getMonth()], time].join(\" \");\n}, hasOwnProperty = function(obj, prop) {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}, callbackifyOnRejected = function(reason, cb) {\n if (!reason) {\n var newReason = new Error(\"Promise was rejected with a falsy value\");\n newReason.reason = reason, newReason.code = \"ERR_FALSY_VALUE_REJECTION\", reason = newReason;\n }\n return cb(reason);\n}, callbackify = function(original) {\n if (typeof original !== \"function\")\n @throwTypeError('The \"original\" argument must be of type Function');\n function callbackified() {\n var args = Array.prototype.slice.call(arguments), maybeCb = args.pop();\n if (typeof maybeCb !== \"function\")\n @throwTypeError(\"The last argument must be of type Function\");\n var self = this, cb = function() {\n return maybeCb.apply(self, arguments);\n };\n original.apply(this, args).then(function(ret) {\n process.nextTick(cb, null, ret);\n }, function(rej) {\n process.nextTick(callbackifyOnRejected, rej, cb);\n });\n }\n return Object.setPrototypeOf(callbackified, Object.getPrototypeOf(original)), Object.defineProperties(callbackified, getOwnPropertyDescriptors(original)), callbackified;\n}, $, types = @requireNativeModule(\"node:util/types\"), cjs_exports = {}, deepEquals = Bun.deepEquals, isDeepStrictEqual = (a, b) => deepEquals(a, b, !0), getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors, formatRegExp = /%[sdjfoc%]/g, debugs = {}, debugEnvRegex = /^$/;\nif (process.env.NODE_DEBUG)\n debugEnv = process.env.NODE_DEBUG, debugEnv = debugEnv.replace(/[|\\\\{}()[\\]^$+\?.]/g, \"\\\\$&\").replace(/\\*/g, \".*\").replace(/,/g, \"$|^\").toUpperCase(), debugEnvRegex = new RegExp(\"^\" + debugEnv + \"$\", \"i\");\nvar debugEnv;\ninspect.colors = {\n bold: [1, 22],\n italic: [3, 23],\n underline: [4, 24],\n inverse: [7, 27],\n white: [37, 39],\n grey: [90, 39],\n black: [30, 39],\n blue: [34, 39],\n cyan: [36, 39],\n green: [32, 39],\n magenta: [35, 39],\n red: [31, 39],\n yellow: [33, 39]\n};\ninspect.styles = {\n special: \"cyan\",\n number: \"yellow\",\n boolean: \"yellow\",\n undefined: \"grey\",\n null: \"bold\",\n string: \"green\",\n date: \"magenta\",\n regexp: \"red\"\n};\nvar { isRegExp, isDate, isNativeError: isError } = types, months = [\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\"], log = function log2() {\n console.log(\"%s - %s\", timestamp(), format.apply(cjs_exports, arguments));\n}, inherits = function inherits2(ctor, superCtor) {\n ctor.super_ = superCtor, ctor.prototype = Object.create(superCtor.prototype, {\n constructor: {\n value: ctor,\n enumerable: !1,\n writable: !0,\n configurable: !0\n }\n });\n}, _extend = function(origin, add) {\n if (!add || !isObject(add))\n return origin;\n var keys = Object.keys(add), i = keys.length;\n while (i--)\n origin[keys[i]] = add[keys[i]];\n return origin;\n}, kCustomPromisifiedSymbol = Symbol.for(\"util.promisify.custom\"), promisify = function promisify2(original) {\n if (typeof original !== \"function\")\n @throwTypeError('The \"original\" argument must be of type Function');\n if (kCustomPromisifiedSymbol && original[kCustomPromisifiedSymbol]) {\n var fn = original[kCustomPromisifiedSymbol];\n if (typeof fn !== \"function\")\n @throwTypeError('The \"util.promisify.custom\" argument must be of type Function');\n return Object.defineProperty(fn, kCustomPromisifiedSymbol, {\n value: fn,\n enumerable: !1,\n writable: !1,\n configurable: !0\n }), fn;\n }\n function fn() {\n var promiseResolve, promiseReject, promise = new Promise(function(resolve, reject) {\n promiseResolve = resolve, promiseReject = reject;\n }), args = [];\n for (var i = 0;i < arguments.length; i++)\n args.push(arguments[i]);\n args.push(function(err, value) {\n if (err)\n promiseReject(err);\n else\n promiseResolve(value);\n });\n try {\n original.apply(this, args);\n } catch (err) {\n promiseReject(err);\n }\n return promise;\n }\n if (Object.setPrototypeOf(fn, Object.getPrototypeOf(original)), kCustomPromisifiedSymbol)\n Object.defineProperty(fn, kCustomPromisifiedSymbol, {\n value: fn,\n enumerable: !1,\n writable: !1,\n configurable: !0\n });\n return Object.defineProperties(fn, getOwnPropertyDescriptors(original));\n};\npromisify.custom = kCustomPromisifiedSymbol;\nvar toUSVString = (input) => {\n return (input + \"\").toWellFormed();\n};\n$ = Object.assign(cjs_exports, {\n format,\n formatWithOptions,\n deprecate,\n debuglog,\n _extend,\n inspect,\n types,\n isArray: @isArray,\n isBoolean,\n isNull,\n isNullOrUndefined,\n isNumber,\n isString,\n isSymbol,\n isUndefined,\n isRegExp,\n isObject,\n isDate,\n isFunction,\n isError,\n isPrimitive,\n isBuffer,\n log,\n inherits,\n toUSVString,\n promisify,\n callbackify,\n isDeepStrictEqual,\n TextDecoder,\n TextEncoder\n});\nreturn $})\n"_s; +static constexpr ASCIILiteral NodeUtilCode = "(function (){\"use strict\";// src/js/out/tmp/node/util.ts\nvar isBufferInterface = function({ copy, fill, readUint8 }) {\n return typeof copy === \"function\" && typeof fill === \"function\" && typeof readUint8 === \"function\";\n}, isBuffer = function(value) {\n return Buffer.isBuffer(value) || typeof value === \"object\" && isBufferInterface(value || {});\n}, isFunction = function(value) {\n return typeof value === \"function\";\n}, formatWithOptions = function(inspectOptions, f) {\n if (!isString(f)) {\n var objects = [];\n for (var i = 0;i < arguments.length; i++)\n objects.push(inspect(arguments[i], inspectOptions));\n return objects.join(\" \");\n }\n var i = 2, args = arguments, len = args.length, str = String(f).replace(formatRegExp, function(x2) {\n if (x2 === \"%%\")\n return \"%\";\n if (i >= len)\n return x2;\n switch (x2) {\n case \"%s\":\n return String(args[i++]);\n case \"%f\":\n return Number(args[i++]);\n case \"%d\":\n return Math.round(Number(args[i++]));\n case \"%j\":\n try {\n return JSON.stringify(args[i++]);\n } catch (_) {\n return \"[Circular]\";\n }\n case \"%o\":\n return inspect(args[i++], { showHidden: !0, showProxy: !0, ...inspectOptions });\n case \"%O\":\n return inspect(args[i++], { showHidden: !0, showProxy: !0, ...inspectOptions });\n default:\n return x2;\n }\n });\n for (var x = args[i];i < len; x = args[++i])\n if (isNull(x) || !isObject(x))\n str += \" \" + x;\n else\n str += \" \" + inspect(x, inspectOptions);\n return str;\n}, format = function(...args) {\n return formatWithOptions({}, ...args);\n}, deprecate = function(fn, msg, code) {\n if (process.noDeprecation === !0)\n return fn;\n var warned = !1;\n function deprecated() {\n if (!warned) {\n if (process.throwDeprecation) {\n var err = new Error(msg);\n if (code)\n err.code = code;\n throw err;\n } else if (process.traceDeprecation)\n console.trace(msg);\n else\n console.error(msg);\n warned = !0;\n }\n return fn.apply(this, arguments);\n }\n return deprecated;\n}, debuglog = function(set) {\n if (set = set.toUpperCase(), !debugs[set])\n if (debugEnvRegex.test(set)) {\n var pid = process.pid;\n debugs[set] = function() {\n var msg = format.apply(cjs_exports, arguments);\n console.error(\"%s %d: %s\", set, pid, msg);\n };\n } else\n debugs[set] = function() {\n };\n return debugs[set];\n}, inspect = function(obj, opts) {\n var ctx = {\n seen: [],\n stylize: stylizeNoColor\n };\n if (arguments.length >= 3)\n ctx.depth = arguments[2];\n if (arguments.length >= 4)\n ctx.colors = arguments[3];\n if (isBoolean(opts))\n ctx.showHidden = opts;\n else if (opts)\n _extend(ctx, opts);\n if (isUndefined(ctx.showHidden))\n ctx.showHidden = !1;\n if (isUndefined(ctx.depth))\n ctx.depth = 2;\n if (isUndefined(ctx.colors))\n ctx.colors = !1;\n if (isUndefined(ctx.customInspect))\n ctx.customInspect = !0;\n if (ctx.colors)\n ctx.stylize = stylizeWithColor;\n return formatValue(ctx, obj, ctx.depth);\n}, stylizeWithColor = function(str, styleType) {\n const style = inspect.styles[styleType];\n if (style !== void 0) {\n const color = inspect.colors[style];\n if (color !== void 0)\n return `\\x1B[${color[0]}m${str}\\x1B[${color[1]}m`;\n }\n return str;\n}, stylizeNoColor = function(str, styleType) {\n return str;\n}, arrayToHash = function(array) {\n var hash = {};\n return array.forEach(function(val, idx) {\n hash[val] = !0;\n }), hash;\n}, formatValue = function(ctx, value, recurseTimes) {\n if (ctx.customInspect && value) {\n const customInspect = value[kInspectCustom];\n if (isFunction(customInspect)) {\n var ret = customInspect.call(value, recurseTimes, ctx, inspect);\n if (!isString(ret))\n ret = formatValue(ctx, ret, recurseTimes);\n return ret;\n }\n }\n var primitive = formatPrimitive(ctx, value);\n if (primitive)\n return primitive;\n var keys = Object.keys(value).concat(Object.getOwnPropertySymbols(value)), visibleKeys = arrayToHash(keys);\n if (ctx.showHidden)\n keys = Object.getOwnPropertyNames(value);\n if (isError(value) && (keys.indexOf(\"message\") >= 0 || keys.indexOf(\"description\") >= 0))\n return formatError(value);\n if (keys.length === 0) {\n if (isFunction(value)) {\n var name = value.name \? \": \" + value.name : \"\";\n return ctx.stylize(\"[Function\" + name + \"]\", \"special\");\n }\n if (isRegExp(value))\n return ctx.stylize(RegExp.prototype.toString.call(value), \"regexp\");\n if (isDate(value))\n return ctx.stylize(Date.prototype.toString.call(value), \"date\");\n if (isError(value))\n return formatError(value);\n }\n var base = \"\", array = !1, braces = [\"{\", \"}\"];\n if (@isArray(value))\n array = !0, braces = [\"[\", \"]\"];\n if (isFunction(value)) {\n var n = value.name \? \": \" + value.name : \"\";\n base = \" [Function\" + n + \"]\";\n }\n if (isRegExp(value))\n base = \" \" + RegExp.prototype.toString.call(value);\n if (isDate(value))\n base = \" \" + Date.prototype.toUTCString.call(value);\n if (isError(value))\n base = \" \" + formatError(value);\n if (keys.length === 0 && (!array || value.length == 0))\n return braces[0] + base + braces[1];\n if (recurseTimes < 0)\n if (isRegExp(value))\n return ctx.stylize(RegExp.prototype.toString.call(value), \"regexp\");\n else\n return ctx.stylize(\"[Object]\", \"special\");\n ctx.seen.push(value);\n var output;\n if (array)\n output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);\n else\n output = keys.map(function(key) {\n return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);\n });\n return ctx.seen.pop(), reduceToSingleString(output, base, braces);\n}, formatPrimitive = function(ctx, value) {\n if (isUndefined(value))\n return ctx.stylize(\"undefined\", \"undefined\");\n if (isString(value)) {\n var simple = \"'\" + JSON.stringify(value).replace(/^\"|\"$/g, \"\").replace(/'/g, \"\\\\'\").replace(/\\\\\"/g, '\"') + \"'\";\n return ctx.stylize(simple, \"string\");\n }\n if (isNumber(value))\n return ctx.stylize(\"\" + value, \"number\");\n if (isBoolean(value))\n return ctx.stylize(\"\" + value, \"boolean\");\n if (isNull(value))\n return ctx.stylize(\"null\", \"null\");\n}, formatError = function(value) {\n return \"[\" + Error.prototype.toString.call(value) + \"]\";\n}, formatArray = function(ctx, value, recurseTimes, visibleKeys, keys) {\n var output = [];\n for (var i = 0, l = value.length;i < l; ++i)\n if (hasOwnProperty(value, String(i)))\n output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, String(i), !0));\n else\n output.push(\"\");\n return keys.forEach(function(key) {\n if (!key.match(/^\\d+$/))\n output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, key, !0));\n }), output;\n}, formatProperty = function(ctx, value, recurseTimes, visibleKeys, key, array) {\n var name, str, desc;\n if (desc = Object.getOwnPropertyDescriptor(value, key) || {\n value: value[key]\n }, desc.get)\n if (desc.set)\n str = ctx.stylize(\"[Getter/Setter]\", \"special\");\n else\n str = ctx.stylize(\"[Getter]\", \"special\");\n else if (desc.set)\n str = ctx.stylize(\"[Setter]\", \"special\");\n if (!hasOwnProperty(visibleKeys, key))\n name = \"[\" + (typeof key === \"symbol\" \? key.description : key) + \"]\";\n if (typeof key === \"symbol\")\n name = \"[\" + ctx.stylize(`Symbol(${key.description})`, \"string\") + \"]\";\n if (!str)\n if (ctx.seen.indexOf(desc.value) < 0) {\n if (isNull(recurseTimes))\n str = formatValue(ctx, desc.value, null);\n else\n str = formatValue(ctx, desc.value, recurseTimes - 1);\n if (str.indexOf(\"\\n\") > -1)\n if (array)\n str = str.split(\"\\n\").map(function(line) {\n return \" \" + line;\n }).join(\"\\n\").substr(2);\n else\n str = \"\\n\" + str.split(\"\\n\").map(function(line) {\n return \" \" + line;\n }).join(\"\\n\");\n } else\n str = ctx.stylize(\"[Circular]\", \"special\");\n if (isUndefined(name)) {\n if (array && key.match(/^\\d+$/))\n return str;\n if (name = JSON.stringify(\"\" + key), name.match(/^\"([a-zA-Z_][a-zA-Z_0-9]*)\"$/))\n name = name.substr(1, name.length - 2), name = ctx.stylize(name, \"name\");\n else\n name = name.replace(/'/g, \"\\\\'\").replace(/\\\\\"/g, '\"').replace(/(^\"|\"$)/g, \"'\"), name = ctx.stylize(name, \"string\");\n }\n return name + \": \" + str;\n}, reduceToSingleString = function(output, base, braces) {\n var numLinesEst = 0, length = output.reduce(function(prev, cur) {\n if (numLinesEst++, cur.indexOf(\"\\n\") >= 0)\n numLinesEst++;\n return prev + cur.replace(/\\u001b\\[\\d\\d\?m/g, \"\").length + 1;\n }, 0);\n if (length > 60)\n return braces[0] + (base === \"\" \? \"\" : base + \"\\n \") + \" \" + output.join(\",\\n \") + \" \" + braces[1];\n return braces[0] + base + \" \" + output.join(\", \") + \" \" + braces[1];\n}, isBoolean = function(arg) {\n return typeof arg === \"boolean\";\n}, isNull = function(arg) {\n return arg === null;\n}, isNullOrUndefined = function(arg) {\n return arg == null;\n}, isNumber = function(arg) {\n return typeof arg === \"number\";\n}, isString = function(arg) {\n return typeof arg === \"string\";\n}, isSymbol = function(arg) {\n return typeof arg === \"symbol\";\n}, isUndefined = function(arg) {\n return arg === void 0;\n}, isObject = function(arg) {\n return typeof arg === \"object\" && arg !== null;\n}, isPrimitive = function(arg) {\n return arg === null || typeof arg === \"boolean\" || typeof arg === \"number\" || typeof arg === \"string\" || typeof arg === \"symbol\" || typeof arg === \"undefined\";\n}, pad = function(n) {\n return n < 10 \? \"0\" + n.toString(10) : n.toString(10);\n}, timestamp = function() {\n var d = new Date, time = [pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].join(\":\");\n return [d.getDate(), months[d.getMonth()], time].join(\" \");\n}, hasOwnProperty = function(obj, prop) {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}, callbackifyOnRejected = function(reason, cb) {\n if (!reason) {\n var newReason = new Error(\"Promise was rejected with a falsy value\");\n newReason.reason = reason, newReason.code = \"ERR_FALSY_VALUE_REJECTION\", reason = newReason;\n }\n return cb(reason);\n}, callbackify = function(original) {\n if (typeof original !== \"function\")\n @throwTypeError('The \"original\" argument must be of type Function');\n function callbackified() {\n var args = Array.prototype.slice.call(arguments), maybeCb = args.pop();\n if (typeof maybeCb !== \"function\")\n @throwTypeError(\"The last argument must be of type Function\");\n var self = this, cb = function() {\n return maybeCb.apply(self, arguments);\n };\n original.apply(this, args).then(function(ret) {\n process.nextTick(cb, null, ret);\n }, function(rej) {\n process.nextTick(callbackifyOnRejected, rej, cb);\n });\n }\n return Object.setPrototypeOf(callbackified, Object.getPrototypeOf(original)), Object.defineProperties(callbackified, getOwnPropertyDescriptors(original)), callbackified;\n}, $, types = @requireNativeModule(\"node:util/types\"), cjs_exports = {}, deepEquals = Bun.deepEquals, isDeepStrictEqual = (a, b) => deepEquals(a, b, !0), getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors, formatRegExp = /%[sdjfoc%]/g, debugs = {}, debugEnvRegex = /^$/;\nif (process.env.NODE_DEBUG)\n debugEnv = process.env.NODE_DEBUG, debugEnv = debugEnv.replace(/[|\\\\{}()[\\]^$+\?.]/g, \"\\\\$&\").replace(/\\*/g, \".*\").replace(/,/g, \"$|^\").toUpperCase(), debugEnvRegex = new RegExp(\"^\" + debugEnv + \"$\", \"i\");\nvar debugEnv, kInspectCustom = Symbol.for(\"nodejs.util.inspect.custom\");\ninspect.colors = {\n bold: [1, 22],\n italic: [3, 23],\n underline: [4, 24],\n inverse: [7, 27],\n white: [37, 39],\n grey: [90, 39],\n black: [30, 39],\n blue: [34, 39],\n cyan: [36, 39],\n green: [32, 39],\n magenta: [35, 39],\n red: [31, 39],\n yellow: [33, 39]\n};\ninspect.styles = {\n special: \"cyan\",\n number: \"yellow\",\n boolean: \"yellow\",\n undefined: \"grey\",\n null: \"bold\",\n string: \"green\",\n date: \"magenta\",\n regexp: \"red\"\n};\ninspect.custom = kInspectCustom;\ninspect.defaultOptions = {\n showHidden: !1,\n depth: 2,\n colors: !1,\n customInspect: !0,\n showProxy: !1,\n maxArrayLength: 100,\n maxStringLength: 1e4,\n breakLength: 80,\n compact: 3,\n sorted: !1,\n getters: !1,\n numericSeparator: !1\n};\nvar { isRegExp, isDate, isNativeError: isError } = types, months = [\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\"], log = function log2() {\n console.log(\"%s - %s\", timestamp(), format.apply(cjs_exports, arguments));\n}, inherits = function inherits2(ctor, superCtor) {\n ctor.super_ = superCtor, ctor.prototype = Object.create(superCtor.prototype, {\n constructor: {\n value: ctor,\n enumerable: !1,\n writable: !0,\n configurable: !0\n }\n });\n}, _extend = function(origin, add) {\n if (!add || !isObject(add))\n return origin;\n var keys = Object.keys(add), i = keys.length;\n while (i--)\n origin[keys[i]] = add[keys[i]];\n return origin;\n}, kCustomPromisifiedSymbol = Symbol.for(\"util.promisify.custom\"), promisify = function promisify2(original) {\n if (typeof original !== \"function\")\n @throwTypeError('The \"original\" argument must be of type Function');\n if (kCustomPromisifiedSymbol && original[kCustomPromisifiedSymbol]) {\n var fn = original[kCustomPromisifiedSymbol];\n if (typeof fn !== \"function\")\n @throwTypeError('The \"util.promisify.custom\" argument must be of type Function');\n return Object.defineProperty(fn, kCustomPromisifiedSymbol, {\n value: fn,\n enumerable: !1,\n writable: !1,\n configurable: !0\n }), fn;\n }\n function fn() {\n var promiseResolve, promiseReject, promise = new Promise(function(resolve, reject) {\n promiseResolve = resolve, promiseReject = reject;\n }), args = [];\n for (var i = 0;i < arguments.length; i++)\n args.push(arguments[i]);\n args.push(function(err, value) {\n if (err)\n promiseReject(err);\n else\n promiseResolve(value);\n });\n try {\n original.apply(this, args);\n } catch (err) {\n promiseReject(err);\n }\n return promise;\n }\n if (Object.setPrototypeOf(fn, Object.getPrototypeOf(original)), kCustomPromisifiedSymbol)\n Object.defineProperty(fn, kCustomPromisifiedSymbol, {\n value: fn,\n enumerable: !1,\n writable: !1,\n configurable: !0\n });\n return Object.defineProperties(fn, getOwnPropertyDescriptors(original));\n};\npromisify.custom = kCustomPromisifiedSymbol;\nvar toUSVString = (input) => {\n return (input + \"\").toWellFormed();\n};\n$ = Object.assign(cjs_exports, {\n format,\n formatWithOptions,\n deprecate,\n debuglog,\n _extend,\n inspect,\n types,\n isArray: @isArray,\n isBoolean,\n isNull,\n isNullOrUndefined,\n isNumber,\n isString,\n isSymbol,\n isUndefined,\n isRegExp,\n isObject,\n isDate,\n isFunction,\n isError,\n isPrimitive,\n isBuffer,\n log,\n inherits,\n toUSVString,\n promisify,\n callbackify,\n isDeepStrictEqual,\n TextDecoder,\n TextEncoder\n});\nreturn $})\n"_s; // // @@ -407,7 +407,7 @@ static constexpr ASCIILiteral NodeUrlCode = "(function (){\"use strict\";// src/ // // -static constexpr ASCIILiteral NodeUtilCode = "(function (){\"use strict\";// src/js/out/tmp/node/util.ts\nvar isBufferInterface = function({ copy, fill, readUint8 }) {\n return typeof copy === \"function\" && typeof fill === \"function\" && typeof readUint8 === \"function\";\n}, isBuffer = function(value) {\n return Buffer.isBuffer(value) || typeof value === \"object\" && isBufferInterface(value || {});\n}, isFunction = function(value) {\n return typeof value === \"function\";\n}, formatWithOptions = function(inspectOptions, f) {\n if (!isString(f)) {\n var objects = [];\n for (var i = 0;i < arguments.length; i++)\n objects.push(inspect(arguments[i], inspectOptions));\n return objects.join(\" \");\n }\n var i = 2, args = arguments, len = args.length, str = String(f).replace(formatRegExp, function(x2) {\n if (x2 === \"%%\")\n return \"%\";\n if (i >= len)\n return x2;\n switch (x2) {\n case \"%s\":\n return String(args[i++]);\n case \"%f\":\n return Number(args[i++]);\n case \"%d\":\n return Math.round(Number(args[i++]));\n case \"%j\":\n try {\n return JSON.stringify(args[i++]);\n } catch (_) {\n return \"[Circular]\";\n }\n case \"%o\":\n return inspect(args[i++], { showHidden: !0, showProxy: !0, ...inspectOptions });\n case \"%O\":\n return inspect(args[i++], { showHidden: !0, showProxy: !0, ...inspectOptions });\n default:\n return x2;\n }\n });\n for (var x = args[i];i < len; x = args[++i])\n if (isNull(x) || !isObject(x))\n str += \" \" + x;\n else\n str += \" \" + inspect(x, inspectOptions);\n return str;\n}, format = function(...args) {\n return formatWithOptions({}, ...args);\n}, deprecate = function(fn, msg, code) {\n if (process.noDeprecation === !0)\n return fn;\n var warned = !1;\n function deprecated() {\n if (!warned) {\n if (process.throwDeprecation) {\n var err = new Error(msg);\n if (code)\n err.code = code;\n throw err;\n } else if (process.traceDeprecation)\n console.trace(msg);\n else\n console.error(msg);\n warned = !0;\n }\n return fn.apply(this, arguments);\n }\n return deprecated;\n}, debuglog = function(set) {\n if (set = set.toUpperCase(), !debugs[set])\n if (debugEnvRegex.test(set)) {\n var pid = process.pid;\n debugs[set] = function() {\n var msg = format.apply(cjs_exports, arguments);\n console.error(\"%s %d: %s\", set, pid, msg);\n };\n } else\n debugs[set] = function() {\n };\n return debugs[set];\n}, inspect = function(obj, opts) {\n var ctx = {\n seen: [],\n stylize: stylizeNoColor\n };\n if (arguments.length >= 3)\n ctx.depth = arguments[2];\n if (arguments.length >= 4)\n ctx.colors = arguments[3];\n if (isBoolean(opts))\n ctx.showHidden = opts;\n else if (opts)\n _extend(ctx, opts);\n if (isUndefined(ctx.showHidden))\n ctx.showHidden = !1;\n if (isUndefined(ctx.depth))\n ctx.depth = 2;\n if (isUndefined(ctx.colors))\n ctx.colors = !1;\n if (isUndefined(ctx.customInspect))\n ctx.customInspect = !0;\n if (ctx.colors)\n ctx.stylize = stylizeWithColor;\n return formatValue(ctx, obj, ctx.depth);\n}, stylizeWithColor = function(str, styleType) {\n var style = inspect.styles[styleType];\n if (style)\n return \"\\x1B[\" + inspect.colors[style][0] + \"m\" + str + \"\\x1B[\" + inspect.colors[style][1] + \"m\";\n else\n return str;\n}, stylizeNoColor = function(str, styleType) {\n return str;\n}, arrayToHash = function(array) {\n var hash = {};\n return array.forEach(function(val, idx) {\n hash[val] = !0;\n }), hash;\n}, formatValue = function(ctx, value, recurseTimes) {\n if (ctx.customInspect && value && isFunction(value.inspect) && value.inspect !== inspect && !(value.constructor && value.constructor.prototype === value)) {\n var ret = value.inspect(recurseTimes, ctx);\n if (!isString(ret))\n ret = formatValue(ctx, ret, recurseTimes);\n return ret;\n }\n var primitive = formatPrimitive(ctx, value);\n if (primitive)\n return primitive;\n var keys = Object.keys(value), visibleKeys = arrayToHash(keys);\n if (ctx.showHidden)\n keys = Object.getOwnPropertyNames(value);\n if (isError(value) && (keys.indexOf(\"message\") >= 0 || keys.indexOf(\"description\") >= 0))\n return formatError(value);\n if (keys.length === 0) {\n if (isFunction(value)) {\n var name = value.name \? \": \" + value.name : \"\";\n return ctx.stylize(\"[Function\" + name + \"]\", \"special\");\n }\n if (isRegExp(value))\n return ctx.stylize(RegExp.prototype.toString.call(value), \"regexp\");\n if (isDate(value))\n return ctx.stylize(Date.prototype.toString.call(value), \"date\");\n if (isError(value))\n return formatError(value);\n }\n var base = \"\", array = !1, braces = [\"{\", \"}\"];\n if (@isArray(value))\n array = !0, braces = [\"[\", \"]\"];\n if (isFunction(value)) {\n var n = value.name \? \": \" + value.name : \"\";\n base = \" [Function\" + n + \"]\";\n }\n if (isRegExp(value))\n base = \" \" + RegExp.prototype.toString.call(value);\n if (isDate(value))\n base = \" \" + Date.prototype.toUTCString.call(value);\n if (isError(value))\n base = \" \" + formatError(value);\n if (keys.length === 0 && (!array || value.length == 0))\n return braces[0] + base + braces[1];\n if (recurseTimes < 0)\n if (isRegExp(value))\n return ctx.stylize(RegExp.prototype.toString.call(value), \"regexp\");\n else\n return ctx.stylize(\"[Object]\", \"special\");\n ctx.seen.push(value);\n var output;\n if (array)\n output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);\n else\n output = keys.map(function(key) {\n return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);\n });\n return ctx.seen.pop(), reduceToSingleString(output, base, braces);\n}, formatPrimitive = function(ctx, value) {\n if (isUndefined(value))\n return ctx.stylize(\"undefined\", \"undefined\");\n if (isString(value)) {\n var simple = \"'\" + JSON.stringify(value).replace(/^\"|\"$/g, \"\").replace(/'/g, \"\\\\'\").replace(/\\\\\"/g, '\"') + \"'\";\n return ctx.stylize(simple, \"string\");\n }\n if (isNumber(value))\n return ctx.stylize(\"\" + value, \"number\");\n if (isBoolean(value))\n return ctx.stylize(\"\" + value, \"boolean\");\n if (isNull(value))\n return ctx.stylize(\"null\", \"null\");\n}, formatError = function(value) {\n return \"[\" + Error.prototype.toString.call(value) + \"]\";\n}, formatArray = function(ctx, value, recurseTimes, visibleKeys, keys) {\n var output = [];\n for (var i = 0, l = value.length;i < l; ++i)\n if (hasOwnProperty(value, String(i)))\n output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, String(i), !0));\n else\n output.push(\"\");\n return keys.forEach(function(key) {\n if (!key.match(/^\\d+$/))\n output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, key, !0));\n }), output;\n}, formatProperty = function(ctx, value, recurseTimes, visibleKeys, key, array) {\n var name, str, desc;\n if (desc = Object.getOwnPropertyDescriptor(value, key) || {\n value: value[key]\n }, desc.get)\n if (desc.set)\n str = ctx.stylize(\"[Getter/Setter]\", \"special\");\n else\n str = ctx.stylize(\"[Getter]\", \"special\");\n else if (desc.set)\n str = ctx.stylize(\"[Setter]\", \"special\");\n if (!hasOwnProperty(visibleKeys, key))\n name = \"[\" + key + \"]\";\n if (!str)\n if (ctx.seen.indexOf(desc.value) < 0) {\n if (isNull(recurseTimes))\n str = formatValue(ctx, desc.value, null);\n else\n str = formatValue(ctx, desc.value, recurseTimes - 1);\n if (str.indexOf(\"\\n\") > -1)\n if (array)\n str = str.split(\"\\n\").map(function(line) {\n return \" \" + line;\n }).join(\"\\n\").substr(2);\n else\n str = \"\\n\" + str.split(\"\\n\").map(function(line) {\n return \" \" + line;\n }).join(\"\\n\");\n } else\n str = ctx.stylize(\"[Circular]\", \"special\");\n if (isUndefined(name)) {\n if (array && key.match(/^\\d+$/))\n return str;\n if (name = JSON.stringify(\"\" + key), name.match(/^\"([a-zA-Z_][a-zA-Z_0-9]*)\"$/))\n name = name.substr(1, name.length - 2), name = ctx.stylize(name, \"name\");\n else\n name = name.replace(/'/g, \"\\\\'\").replace(/\\\\\"/g, '\"').replace(/(^\"|\"$)/g, \"'\"), name = ctx.stylize(name, \"string\");\n }\n return name + \": \" + str;\n}, reduceToSingleString = function(output, base, braces) {\n var numLinesEst = 0, length = output.reduce(function(prev, cur) {\n if (numLinesEst++, cur.indexOf(\"\\n\") >= 0)\n numLinesEst++;\n return prev + cur.replace(/\\u001b\\[\\d\\d\?m/g, \"\").length + 1;\n }, 0);\n if (length > 60)\n return braces[0] + (base === \"\" \? \"\" : base + \"\\n \") + \" \" + output.join(\",\\n \") + \" \" + braces[1];\n return braces[0] + base + \" \" + output.join(\", \") + \" \" + braces[1];\n}, isBoolean = function(arg) {\n return typeof arg === \"boolean\";\n}, isNull = function(arg) {\n return arg === null;\n}, isNullOrUndefined = function(arg) {\n return arg == null;\n}, isNumber = function(arg) {\n return typeof arg === \"number\";\n}, isString = function(arg) {\n return typeof arg === \"string\";\n}, isSymbol = function(arg) {\n return typeof arg === \"symbol\";\n}, isUndefined = function(arg) {\n return arg === void 0;\n}, isObject = function(arg) {\n return typeof arg === \"object\" && arg !== null;\n}, isPrimitive = function(arg) {\n return arg === null || typeof arg === \"boolean\" || typeof arg === \"number\" || typeof arg === \"string\" || typeof arg === \"symbol\" || typeof arg === \"undefined\";\n}, pad = function(n) {\n return n < 10 \? \"0\" + n.toString(10) : n.toString(10);\n}, timestamp = function() {\n var d = new Date, time = [pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].join(\":\");\n return [d.getDate(), months[d.getMonth()], time].join(\" \");\n}, hasOwnProperty = function(obj, prop) {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}, callbackifyOnRejected = function(reason, cb) {\n if (!reason) {\n var newReason = new Error(\"Promise was rejected with a falsy value\");\n newReason.reason = reason, newReason.code = \"ERR_FALSY_VALUE_REJECTION\", reason = newReason;\n }\n return cb(reason);\n}, callbackify = function(original) {\n if (typeof original !== \"function\")\n @throwTypeError('The \"original\" argument must be of type Function');\n function callbackified() {\n var args = Array.prototype.slice.call(arguments), maybeCb = args.pop();\n if (typeof maybeCb !== \"function\")\n @throwTypeError(\"The last argument must be of type Function\");\n var self = this, cb = function() {\n return maybeCb.apply(self, arguments);\n };\n original.apply(this, args).then(function(ret) {\n process.nextTick(cb, null, ret);\n }, function(rej) {\n process.nextTick(callbackifyOnRejected, rej, cb);\n });\n }\n return Object.setPrototypeOf(callbackified, Object.getPrototypeOf(original)), Object.defineProperties(callbackified, getOwnPropertyDescriptors(original)), callbackified;\n}, $, types = @requireNativeModule(\"node:util/types\"), cjs_exports = {}, deepEquals = Bun.deepEquals, isDeepStrictEqual = (a, b) => deepEquals(a, b, !0), getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors, formatRegExp = /%[sdjfoc%]/g, debugs = {}, debugEnvRegex = /^$/;\nif (process.env.NODE_DEBUG)\n debugEnv = process.env.NODE_DEBUG, debugEnv = debugEnv.replace(/[|\\\\{}()[\\]^$+\?.]/g, \"\\\\$&\").replace(/\\*/g, \".*\").replace(/,/g, \"$|^\").toUpperCase(), debugEnvRegex = new RegExp(\"^\" + debugEnv + \"$\", \"i\");\nvar debugEnv;\ninspect.colors = {\n bold: [1, 22],\n italic: [3, 23],\n underline: [4, 24],\n inverse: [7, 27],\n white: [37, 39],\n grey: [90, 39],\n black: [30, 39],\n blue: [34, 39],\n cyan: [36, 39],\n green: [32, 39],\n magenta: [35, 39],\n red: [31, 39],\n yellow: [33, 39]\n};\ninspect.styles = {\n special: \"cyan\",\n number: \"yellow\",\n boolean: \"yellow\",\n undefined: \"grey\",\n null: \"bold\",\n string: \"green\",\n date: \"magenta\",\n regexp: \"red\"\n};\nvar { isRegExp, isDate, isNativeError: isError } = types, months = [\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\"], log = function log2() {\n console.log(\"%s - %s\", timestamp(), format.apply(cjs_exports, arguments));\n}, inherits = function inherits2(ctor, superCtor) {\n ctor.super_ = superCtor, ctor.prototype = Object.create(superCtor.prototype, {\n constructor: {\n value: ctor,\n enumerable: !1,\n writable: !0,\n configurable: !0\n }\n });\n}, _extend = function(origin, add) {\n if (!add || !isObject(add))\n return origin;\n var keys = Object.keys(add), i = keys.length;\n while (i--)\n origin[keys[i]] = add[keys[i]];\n return origin;\n}, kCustomPromisifiedSymbol = Symbol.for(\"util.promisify.custom\"), promisify = function promisify2(original) {\n if (typeof original !== \"function\")\n @throwTypeError('The \"original\" argument must be of type Function');\n if (kCustomPromisifiedSymbol && original[kCustomPromisifiedSymbol]) {\n var fn = original[kCustomPromisifiedSymbol];\n if (typeof fn !== \"function\")\n @throwTypeError('The \"util.promisify.custom\" argument must be of type Function');\n return Object.defineProperty(fn, kCustomPromisifiedSymbol, {\n value: fn,\n enumerable: !1,\n writable: !1,\n configurable: !0\n }), fn;\n }\n function fn() {\n var promiseResolve, promiseReject, promise = new Promise(function(resolve, reject) {\n promiseResolve = resolve, promiseReject = reject;\n }), args = [];\n for (var i = 0;i < arguments.length; i++)\n args.push(arguments[i]);\n args.push(function(err, value) {\n if (err)\n promiseReject(err);\n else\n promiseResolve(value);\n });\n try {\n original.apply(this, args);\n } catch (err) {\n promiseReject(err);\n }\n return promise;\n }\n if (Object.setPrototypeOf(fn, Object.getPrototypeOf(original)), kCustomPromisifiedSymbol)\n Object.defineProperty(fn, kCustomPromisifiedSymbol, {\n value: fn,\n enumerable: !1,\n writable: !1,\n configurable: !0\n });\n return Object.defineProperties(fn, getOwnPropertyDescriptors(original));\n};\npromisify.custom = kCustomPromisifiedSymbol;\nvar toUSVString = (input) => {\n return (input + \"\").toWellFormed();\n};\n$ = Object.assign(cjs_exports, {\n format,\n formatWithOptions,\n deprecate,\n debuglog,\n _extend,\n inspect,\n types,\n isArray: @isArray,\n isBoolean,\n isNull,\n isNullOrUndefined,\n isNumber,\n isString,\n isSymbol,\n isUndefined,\n isRegExp,\n isObject,\n isDate,\n isFunction,\n isError,\n isPrimitive,\n isBuffer,\n log,\n inherits,\n toUSVString,\n promisify,\n callbackify,\n isDeepStrictEqual,\n TextDecoder,\n TextEncoder\n});\nreturn $})\n"_s; +static constexpr ASCIILiteral NodeUtilCode = "(function (){\"use strict\";// src/js/out/tmp/node/util.ts\nvar isBufferInterface = function({ copy, fill, readUint8 }) {\n return typeof copy === \"function\" && typeof fill === \"function\" && typeof readUint8 === \"function\";\n}, isBuffer = function(value) {\n return Buffer.isBuffer(value) || typeof value === \"object\" && isBufferInterface(value || {});\n}, isFunction = function(value) {\n return typeof value === \"function\";\n}, formatWithOptions = function(inspectOptions, f) {\n if (!isString(f)) {\n var objects = [];\n for (var i = 0;i < arguments.length; i++)\n objects.push(inspect(arguments[i], inspectOptions));\n return objects.join(\" \");\n }\n var i = 2, args = arguments, len = args.length, str = String(f).replace(formatRegExp, function(x2) {\n if (x2 === \"%%\")\n return \"%\";\n if (i >= len)\n return x2;\n switch (x2) {\n case \"%s\":\n return String(args[i++]);\n case \"%f\":\n return Number(args[i++]);\n case \"%d\":\n return Math.round(Number(args[i++]));\n case \"%j\":\n try {\n return JSON.stringify(args[i++]);\n } catch (_) {\n return \"[Circular]\";\n }\n case \"%o\":\n return inspect(args[i++], { showHidden: !0, showProxy: !0, ...inspectOptions });\n case \"%O\":\n return inspect(args[i++], { showHidden: !0, showProxy: !0, ...inspectOptions });\n default:\n return x2;\n }\n });\n for (var x = args[i];i < len; x = args[++i])\n if (isNull(x) || !isObject(x))\n str += \" \" + x;\n else\n str += \" \" + inspect(x, inspectOptions);\n return str;\n}, format = function(...args) {\n return formatWithOptions({}, ...args);\n}, deprecate = function(fn, msg, code) {\n if (process.noDeprecation === !0)\n return fn;\n var warned = !1;\n function deprecated() {\n if (!warned) {\n if (process.throwDeprecation) {\n var err = new Error(msg);\n if (code)\n err.code = code;\n throw err;\n } else if (process.traceDeprecation)\n console.trace(msg);\n else\n console.error(msg);\n warned = !0;\n }\n return fn.apply(this, arguments);\n }\n return deprecated;\n}, debuglog = function(set) {\n if (set = set.toUpperCase(), !debugs[set])\n if (debugEnvRegex.test(set)) {\n var pid = process.pid;\n debugs[set] = function() {\n var msg = format.apply(cjs_exports, arguments);\n console.error(\"%s %d: %s\", set, pid, msg);\n };\n } else\n debugs[set] = function() {\n };\n return debugs[set];\n}, inspect = function(obj, opts) {\n var ctx = {\n seen: [],\n stylize: stylizeNoColor\n };\n if (arguments.length >= 3)\n ctx.depth = arguments[2];\n if (arguments.length >= 4)\n ctx.colors = arguments[3];\n if (isBoolean(opts))\n ctx.showHidden = opts;\n else if (opts)\n _extend(ctx, opts);\n if (isUndefined(ctx.showHidden))\n ctx.showHidden = !1;\n if (isUndefined(ctx.depth))\n ctx.depth = 2;\n if (isUndefined(ctx.colors))\n ctx.colors = !1;\n if (isUndefined(ctx.customInspect))\n ctx.customInspect = !0;\n if (ctx.colors)\n ctx.stylize = stylizeWithColor;\n return formatValue(ctx, obj, ctx.depth);\n}, stylizeWithColor = function(str, styleType) {\n const style = inspect.styles[styleType];\n if (style !== void 0) {\n const color = inspect.colors[style];\n if (color !== void 0)\n return `\\x1B[${color[0]}m${str}\\x1B[${color[1]}m`;\n }\n return str;\n}, stylizeNoColor = function(str, styleType) {\n return str;\n}, arrayToHash = function(array) {\n var hash = {};\n return array.forEach(function(val, idx) {\n hash[val] = !0;\n }), hash;\n}, formatValue = function(ctx, value, recurseTimes) {\n if (ctx.customInspect && value) {\n const customInspect = value[kInspectCustom];\n if (isFunction(customInspect)) {\n var ret = customInspect.call(value, recurseTimes, ctx, inspect);\n if (!isString(ret))\n ret = formatValue(ctx, ret, recurseTimes);\n return ret;\n }\n }\n var primitive = formatPrimitive(ctx, value);\n if (primitive)\n return primitive;\n var keys = Object.keys(value).concat(Object.getOwnPropertySymbols(value)), visibleKeys = arrayToHash(keys);\n if (ctx.showHidden)\n keys = Object.getOwnPropertyNames(value);\n if (isError(value) && (keys.indexOf(\"message\") >= 0 || keys.indexOf(\"description\") >= 0))\n return formatError(value);\n if (keys.length === 0) {\n if (isFunction(value)) {\n var name = value.name \? \": \" + value.name : \"\";\n return ctx.stylize(\"[Function\" + name + \"]\", \"special\");\n }\n if (isRegExp(value))\n return ctx.stylize(RegExp.prototype.toString.call(value), \"regexp\");\n if (isDate(value))\n return ctx.stylize(Date.prototype.toString.call(value), \"date\");\n if (isError(value))\n return formatError(value);\n }\n var base = \"\", array = !1, braces = [\"{\", \"}\"];\n if (@isArray(value))\n array = !0, braces = [\"[\", \"]\"];\n if (isFunction(value)) {\n var n = value.name \? \": \" + value.name : \"\";\n base = \" [Function\" + n + \"]\";\n }\n if (isRegExp(value))\n base = \" \" + RegExp.prototype.toString.call(value);\n if (isDate(value))\n base = \" \" + Date.prototype.toUTCString.call(value);\n if (isError(value))\n base = \" \" + formatError(value);\n if (keys.length === 0 && (!array || value.length == 0))\n return braces[0] + base + braces[1];\n if (recurseTimes < 0)\n if (isRegExp(value))\n return ctx.stylize(RegExp.prototype.toString.call(value), \"regexp\");\n else\n return ctx.stylize(\"[Object]\", \"special\");\n ctx.seen.push(value);\n var output;\n if (array)\n output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);\n else\n output = keys.map(function(key) {\n return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);\n });\n return ctx.seen.pop(), reduceToSingleString(output, base, braces);\n}, formatPrimitive = function(ctx, value) {\n if (isUndefined(value))\n return ctx.stylize(\"undefined\", \"undefined\");\n if (isString(value)) {\n var simple = \"'\" + JSON.stringify(value).replace(/^\"|\"$/g, \"\").replace(/'/g, \"\\\\'\").replace(/\\\\\"/g, '\"') + \"'\";\n return ctx.stylize(simple, \"string\");\n }\n if (isNumber(value))\n return ctx.stylize(\"\" + value, \"number\");\n if (isBoolean(value))\n return ctx.stylize(\"\" + value, \"boolean\");\n if (isNull(value))\n return ctx.stylize(\"null\", \"null\");\n}, formatError = function(value) {\n return \"[\" + Error.prototype.toString.call(value) + \"]\";\n}, formatArray = function(ctx, value, recurseTimes, visibleKeys, keys) {\n var output = [];\n for (var i = 0, l = value.length;i < l; ++i)\n if (hasOwnProperty(value, String(i)))\n output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, String(i), !0));\n else\n output.push(\"\");\n return keys.forEach(function(key) {\n if (!key.match(/^\\d+$/))\n output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, key, !0));\n }), output;\n}, formatProperty = function(ctx, value, recurseTimes, visibleKeys, key, array) {\n var name, str, desc;\n if (desc = Object.getOwnPropertyDescriptor(value, key) || {\n value: value[key]\n }, desc.get)\n if (desc.set)\n str = ctx.stylize(\"[Getter/Setter]\", \"special\");\n else\n str = ctx.stylize(\"[Getter]\", \"special\");\n else if (desc.set)\n str = ctx.stylize(\"[Setter]\", \"special\");\n if (!hasOwnProperty(visibleKeys, key))\n name = \"[\" + (typeof key === \"symbol\" \? key.description : key) + \"]\";\n if (typeof key === \"symbol\")\n name = \"[\" + ctx.stylize(`Symbol(${key.description})`, \"string\") + \"]\";\n if (!str)\n if (ctx.seen.indexOf(desc.value) < 0) {\n if (isNull(recurseTimes))\n str = formatValue(ctx, desc.value, null);\n else\n str = formatValue(ctx, desc.value, recurseTimes - 1);\n if (str.indexOf(\"\\n\") > -1)\n if (array)\n str = str.split(\"\\n\").map(function(line) {\n return \" \" + line;\n }).join(\"\\n\").substr(2);\n else\n str = \"\\n\" + str.split(\"\\n\").map(function(line) {\n return \" \" + line;\n }).join(\"\\n\");\n } else\n str = ctx.stylize(\"[Circular]\", \"special\");\n if (isUndefined(name)) {\n if (array && key.match(/^\\d+$/))\n return str;\n if (name = JSON.stringify(\"\" + key), name.match(/^\"([a-zA-Z_][a-zA-Z_0-9]*)\"$/))\n name = name.substr(1, name.length - 2), name = ctx.stylize(name, \"name\");\n else\n name = name.replace(/'/g, \"\\\\'\").replace(/\\\\\"/g, '\"').replace(/(^\"|\"$)/g, \"'\"), name = ctx.stylize(name, \"string\");\n }\n return name + \": \" + str;\n}, reduceToSingleString = function(output, base, braces) {\n var numLinesEst = 0, length = output.reduce(function(prev, cur) {\n if (numLinesEst++, cur.indexOf(\"\\n\") >= 0)\n numLinesEst++;\n return prev + cur.replace(/\\u001b\\[\\d\\d\?m/g, \"\").length + 1;\n }, 0);\n if (length > 60)\n return braces[0] + (base === \"\" \? \"\" : base + \"\\n \") + \" \" + output.join(\",\\n \") + \" \" + braces[1];\n return braces[0] + base + \" \" + output.join(\", \") + \" \" + braces[1];\n}, isBoolean = function(arg) {\n return typeof arg === \"boolean\";\n}, isNull = function(arg) {\n return arg === null;\n}, isNullOrUndefined = function(arg) {\n return arg == null;\n}, isNumber = function(arg) {\n return typeof arg === \"number\";\n}, isString = function(arg) {\n return typeof arg === \"string\";\n}, isSymbol = function(arg) {\n return typeof arg === \"symbol\";\n}, isUndefined = function(arg) {\n return arg === void 0;\n}, isObject = function(arg) {\n return typeof arg === \"object\" && arg !== null;\n}, isPrimitive = function(arg) {\n return arg === null || typeof arg === \"boolean\" || typeof arg === \"number\" || typeof arg === \"string\" || typeof arg === \"symbol\" || typeof arg === \"undefined\";\n}, pad = function(n) {\n return n < 10 \? \"0\" + n.toString(10) : n.toString(10);\n}, timestamp = function() {\n var d = new Date, time = [pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].join(\":\");\n return [d.getDate(), months[d.getMonth()], time].join(\" \");\n}, hasOwnProperty = function(obj, prop) {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}, callbackifyOnRejected = function(reason, cb) {\n if (!reason) {\n var newReason = new Error(\"Promise was rejected with a falsy value\");\n newReason.reason = reason, newReason.code = \"ERR_FALSY_VALUE_REJECTION\", reason = newReason;\n }\n return cb(reason);\n}, callbackify = function(original) {\n if (typeof original !== \"function\")\n @throwTypeError('The \"original\" argument must be of type Function');\n function callbackified() {\n var args = Array.prototype.slice.call(arguments), maybeCb = args.pop();\n if (typeof maybeCb !== \"function\")\n @throwTypeError(\"The last argument must be of type Function\");\n var self = this, cb = function() {\n return maybeCb.apply(self, arguments);\n };\n original.apply(this, args).then(function(ret) {\n process.nextTick(cb, null, ret);\n }, function(rej) {\n process.nextTick(callbackifyOnRejected, rej, cb);\n });\n }\n return Object.setPrototypeOf(callbackified, Object.getPrototypeOf(original)), Object.defineProperties(callbackified, getOwnPropertyDescriptors(original)), callbackified;\n}, $, types = @requireNativeModule(\"node:util/types\"), cjs_exports = {}, deepEquals = Bun.deepEquals, isDeepStrictEqual = (a, b) => deepEquals(a, b, !0), getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors, formatRegExp = /%[sdjfoc%]/g, debugs = {}, debugEnvRegex = /^$/;\nif (process.env.NODE_DEBUG)\n debugEnv = process.env.NODE_DEBUG, debugEnv = debugEnv.replace(/[|\\\\{}()[\\]^$+\?.]/g, \"\\\\$&\").replace(/\\*/g, \".*\").replace(/,/g, \"$|^\").toUpperCase(), debugEnvRegex = new RegExp(\"^\" + debugEnv + \"$\", \"i\");\nvar debugEnv, kInspectCustom = Symbol.for(\"nodejs.util.inspect.custom\");\ninspect.colors = {\n bold: [1, 22],\n italic: [3, 23],\n underline: [4, 24],\n inverse: [7, 27],\n white: [37, 39],\n grey: [90, 39],\n black: [30, 39],\n blue: [34, 39],\n cyan: [36, 39],\n green: [32, 39],\n magenta: [35, 39],\n red: [31, 39],\n yellow: [33, 39]\n};\ninspect.styles = {\n special: \"cyan\",\n number: \"yellow\",\n boolean: \"yellow\",\n undefined: \"grey\",\n null: \"bold\",\n string: \"green\",\n date: \"magenta\",\n regexp: \"red\"\n};\ninspect.custom = kInspectCustom;\ninspect.defaultOptions = {\n showHidden: !1,\n depth: 2,\n colors: !1,\n customInspect: !0,\n showProxy: !1,\n maxArrayLength: 100,\n maxStringLength: 1e4,\n breakLength: 80,\n compact: 3,\n sorted: !1,\n getters: !1,\n numericSeparator: !1\n};\nvar { isRegExp, isDate, isNativeError: isError } = types, months = [\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\"], log = function log2() {\n console.log(\"%s - %s\", timestamp(), format.apply(cjs_exports, arguments));\n}, inherits = function inherits2(ctor, superCtor) {\n ctor.super_ = superCtor, ctor.prototype = Object.create(superCtor.prototype, {\n constructor: {\n value: ctor,\n enumerable: !1,\n writable: !0,\n configurable: !0\n }\n });\n}, _extend = function(origin, add) {\n if (!add || !isObject(add))\n return origin;\n var keys = Object.keys(add), i = keys.length;\n while (i--)\n origin[keys[i]] = add[keys[i]];\n return origin;\n}, kCustomPromisifiedSymbol = Symbol.for(\"util.promisify.custom\"), promisify = function promisify2(original) {\n if (typeof original !== \"function\")\n @throwTypeError('The \"original\" argument must be of type Function');\n if (kCustomPromisifiedSymbol && original[kCustomPromisifiedSymbol]) {\n var fn = original[kCustomPromisifiedSymbol];\n if (typeof fn !== \"function\")\n @throwTypeError('The \"util.promisify.custom\" argument must be of type Function');\n return Object.defineProperty(fn, kCustomPromisifiedSymbol, {\n value: fn,\n enumerable: !1,\n writable: !1,\n configurable: !0\n }), fn;\n }\n function fn() {\n var promiseResolve, promiseReject, promise = new Promise(function(resolve, reject) {\n promiseResolve = resolve, promiseReject = reject;\n }), args = [];\n for (var i = 0;i < arguments.length; i++)\n args.push(arguments[i]);\n args.push(function(err, value) {\n if (err)\n promiseReject(err);\n else\n promiseResolve(value);\n });\n try {\n original.apply(this, args);\n } catch (err) {\n promiseReject(err);\n }\n return promise;\n }\n if (Object.setPrototypeOf(fn, Object.getPrototypeOf(original)), kCustomPromisifiedSymbol)\n Object.defineProperty(fn, kCustomPromisifiedSymbol, {\n value: fn,\n enumerable: !1,\n writable: !1,\n configurable: !0\n });\n return Object.defineProperties(fn, getOwnPropertyDescriptors(original));\n};\npromisify.custom = kCustomPromisifiedSymbol;\nvar toUSVString = (input) => {\n return (input + \"\").toWellFormed();\n};\n$ = Object.assign(cjs_exports, {\n format,\n formatWithOptions,\n deprecate,\n debuglog,\n _extend,\n inspect,\n types,\n isArray: @isArray,\n isBoolean,\n isNull,\n isNullOrUndefined,\n isNumber,\n isString,\n isSymbol,\n isUndefined,\n isRegExp,\n isObject,\n isDate,\n isFunction,\n isError,\n isPrimitive,\n isBuffer,\n log,\n inherits,\n toUSVString,\n promisify,\n callbackify,\n isDeepStrictEqual,\n TextDecoder,\n TextEncoder\n});\nreturn $})\n"_s; // // @@ -637,7 +637,7 @@ static constexpr ASCIILiteral NodeUrlCode = "(function (){\"use strict\";// src/ // // -static constexpr ASCIILiteral NodeUtilCode = "(function (){\"use strict\";// src/js/out/tmp/node/util.ts\nvar isBufferInterface = function({ copy, fill, readUint8 }) {\n return typeof copy === \"function\" && typeof fill === \"function\" && typeof readUint8 === \"function\";\n}, isBuffer = function(value) {\n return Buffer.isBuffer(value) || typeof value === \"object\" && isBufferInterface(value || {});\n}, isFunction = function(value) {\n return typeof value === \"function\";\n}, formatWithOptions = function(inspectOptions, f) {\n if (!isString(f)) {\n var objects = [];\n for (var i = 0;i < arguments.length; i++)\n objects.push(inspect(arguments[i], inspectOptions));\n return objects.join(\" \");\n }\n var i = 2, args = arguments, len = args.length, str = String(f).replace(formatRegExp, function(x2) {\n if (x2 === \"%%\")\n return \"%\";\n if (i >= len)\n return x2;\n switch (x2) {\n case \"%s\":\n return String(args[i++]);\n case \"%f\":\n return Number(args[i++]);\n case \"%d\":\n return Math.round(Number(args[i++]));\n case \"%j\":\n try {\n return JSON.stringify(args[i++]);\n } catch (_) {\n return \"[Circular]\";\n }\n case \"%o\":\n return inspect(args[i++], { showHidden: !0, showProxy: !0, ...inspectOptions });\n case \"%O\":\n return inspect(args[i++], { showHidden: !0, showProxy: !0, ...inspectOptions });\n default:\n return x2;\n }\n });\n for (var x = args[i];i < len; x = args[++i])\n if (isNull(x) || !isObject(x))\n str += \" \" + x;\n else\n str += \" \" + inspect(x, inspectOptions);\n return str;\n}, format = function(...args) {\n return formatWithOptions({}, ...args);\n}, deprecate = function(fn, msg, code) {\n if (process.noDeprecation === !0)\n return fn;\n var warned = !1;\n function deprecated() {\n if (!warned) {\n if (process.throwDeprecation) {\n var err = new Error(msg);\n if (code)\n err.code = code;\n throw err;\n } else if (process.traceDeprecation)\n console.trace(msg);\n else\n console.error(msg);\n warned = !0;\n }\n return fn.apply(this, arguments);\n }\n return deprecated;\n}, debuglog = function(set) {\n if (set = set.toUpperCase(), !debugs[set])\n if (debugEnvRegex.test(set)) {\n var pid = process.pid;\n debugs[set] = function() {\n var msg = format.apply(cjs_exports, arguments);\n console.error(\"%s %d: %s\", set, pid, msg);\n };\n } else\n debugs[set] = function() {\n };\n return debugs[set];\n}, inspect = function(obj, opts) {\n var ctx = {\n seen: [],\n stylize: stylizeNoColor\n };\n if (arguments.length >= 3)\n ctx.depth = arguments[2];\n if (arguments.length >= 4)\n ctx.colors = arguments[3];\n if (isBoolean(opts))\n ctx.showHidden = opts;\n else if (opts)\n _extend(ctx, opts);\n if (isUndefined(ctx.showHidden))\n ctx.showHidden = !1;\n if (isUndefined(ctx.depth))\n ctx.depth = 2;\n if (isUndefined(ctx.colors))\n ctx.colors = !1;\n if (isUndefined(ctx.customInspect))\n ctx.customInspect = !0;\n if (ctx.colors)\n ctx.stylize = stylizeWithColor;\n return formatValue(ctx, obj, ctx.depth);\n}, stylizeWithColor = function(str, styleType) {\n var style = inspect.styles[styleType];\n if (style)\n return \"\\x1B[\" + inspect.colors[style][0] + \"m\" + str + \"\\x1B[\" + inspect.colors[style][1] + \"m\";\n else\n return str;\n}, stylizeNoColor = function(str, styleType) {\n return str;\n}, arrayToHash = function(array) {\n var hash = {};\n return array.forEach(function(val, idx) {\n hash[val] = !0;\n }), hash;\n}, formatValue = function(ctx, value, recurseTimes) {\n if (ctx.customInspect && value && isFunction(value.inspect) && value.inspect !== inspect && !(value.constructor && value.constructor.prototype === value)) {\n var ret = value.inspect(recurseTimes, ctx);\n if (!isString(ret))\n ret = formatValue(ctx, ret, recurseTimes);\n return ret;\n }\n var primitive = formatPrimitive(ctx, value);\n if (primitive)\n return primitive;\n var keys = Object.keys(value), visibleKeys = arrayToHash(keys);\n if (ctx.showHidden)\n keys = Object.getOwnPropertyNames(value);\n if (isError(value) && (keys.indexOf(\"message\") >= 0 || keys.indexOf(\"description\") >= 0))\n return formatError(value);\n if (keys.length === 0) {\n if (isFunction(value)) {\n var name = value.name \? \": \" + value.name : \"\";\n return ctx.stylize(\"[Function\" + name + \"]\", \"special\");\n }\n if (isRegExp(value))\n return ctx.stylize(RegExp.prototype.toString.call(value), \"regexp\");\n if (isDate(value))\n return ctx.stylize(Date.prototype.toString.call(value), \"date\");\n if (isError(value))\n return formatError(value);\n }\n var base = \"\", array = !1, braces = [\"{\", \"}\"];\n if (@isArray(value))\n array = !0, braces = [\"[\", \"]\"];\n if (isFunction(value)) {\n var n = value.name \? \": \" + value.name : \"\";\n base = \" [Function\" + n + \"]\";\n }\n if (isRegExp(value))\n base = \" \" + RegExp.prototype.toString.call(value);\n if (isDate(value))\n base = \" \" + Date.prototype.toUTCString.call(value);\n if (isError(value))\n base = \" \" + formatError(value);\n if (keys.length === 0 && (!array || value.length == 0))\n return braces[0] + base + braces[1];\n if (recurseTimes < 0)\n if (isRegExp(value))\n return ctx.stylize(RegExp.prototype.toString.call(value), \"regexp\");\n else\n return ctx.stylize(\"[Object]\", \"special\");\n ctx.seen.push(value);\n var output;\n if (array)\n output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);\n else\n output = keys.map(function(key) {\n return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);\n });\n return ctx.seen.pop(), reduceToSingleString(output, base, braces);\n}, formatPrimitive = function(ctx, value) {\n if (isUndefined(value))\n return ctx.stylize(\"undefined\", \"undefined\");\n if (isString(value)) {\n var simple = \"'\" + JSON.stringify(value).replace(/^\"|\"$/g, \"\").replace(/'/g, \"\\\\'\").replace(/\\\\\"/g, '\"') + \"'\";\n return ctx.stylize(simple, \"string\");\n }\n if (isNumber(value))\n return ctx.stylize(\"\" + value, \"number\");\n if (isBoolean(value))\n return ctx.stylize(\"\" + value, \"boolean\");\n if (isNull(value))\n return ctx.stylize(\"null\", \"null\");\n}, formatError = function(value) {\n return \"[\" + Error.prototype.toString.call(value) + \"]\";\n}, formatArray = function(ctx, value, recurseTimes, visibleKeys, keys) {\n var output = [];\n for (var i = 0, l = value.length;i < l; ++i)\n if (hasOwnProperty(value, String(i)))\n output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, String(i), !0));\n else\n output.push(\"\");\n return keys.forEach(function(key) {\n if (!key.match(/^\\d+$/))\n output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, key, !0));\n }), output;\n}, formatProperty = function(ctx, value, recurseTimes, visibleKeys, key, array) {\n var name, str, desc;\n if (desc = Object.getOwnPropertyDescriptor(value, key) || {\n value: value[key]\n }, desc.get)\n if (desc.set)\n str = ctx.stylize(\"[Getter/Setter]\", \"special\");\n else\n str = ctx.stylize(\"[Getter]\", \"special\");\n else if (desc.set)\n str = ctx.stylize(\"[Setter]\", \"special\");\n if (!hasOwnProperty(visibleKeys, key))\n name = \"[\" + key + \"]\";\n if (!str)\n if (ctx.seen.indexOf(desc.value) < 0) {\n if (isNull(recurseTimes))\n str = formatValue(ctx, desc.value, null);\n else\n str = formatValue(ctx, desc.value, recurseTimes - 1);\n if (str.indexOf(\"\\n\") > -1)\n if (array)\n str = str.split(\"\\n\").map(function(line) {\n return \" \" + line;\n }).join(\"\\n\").substr(2);\n else\n str = \"\\n\" + str.split(\"\\n\").map(function(line) {\n return \" \" + line;\n }).join(\"\\n\");\n } else\n str = ctx.stylize(\"[Circular]\", \"special\");\n if (isUndefined(name)) {\n if (array && key.match(/^\\d+$/))\n return str;\n if (name = JSON.stringify(\"\" + key), name.match(/^\"([a-zA-Z_][a-zA-Z_0-9]*)\"$/))\n name = name.substr(1, name.length - 2), name = ctx.stylize(name, \"name\");\n else\n name = name.replace(/'/g, \"\\\\'\").replace(/\\\\\"/g, '\"').replace(/(^\"|\"$)/g, \"'\"), name = ctx.stylize(name, \"string\");\n }\n return name + \": \" + str;\n}, reduceToSingleString = function(output, base, braces) {\n var numLinesEst = 0, length = output.reduce(function(prev, cur) {\n if (numLinesEst++, cur.indexOf(\"\\n\") >= 0)\n numLinesEst++;\n return prev + cur.replace(/\\u001b\\[\\d\\d\?m/g, \"\").length + 1;\n }, 0);\n if (length > 60)\n return braces[0] + (base === \"\" \? \"\" : base + \"\\n \") + \" \" + output.join(\",\\n \") + \" \" + braces[1];\n return braces[0] + base + \" \" + output.join(\", \") + \" \" + braces[1];\n}, isBoolean = function(arg) {\n return typeof arg === \"boolean\";\n}, isNull = function(arg) {\n return arg === null;\n}, isNullOrUndefined = function(arg) {\n return arg == null;\n}, isNumber = function(arg) {\n return typeof arg === \"number\";\n}, isString = function(arg) {\n return typeof arg === \"string\";\n}, isSymbol = function(arg) {\n return typeof arg === \"symbol\";\n}, isUndefined = function(arg) {\n return arg === void 0;\n}, isObject = function(arg) {\n return typeof arg === \"object\" && arg !== null;\n}, isPrimitive = function(arg) {\n return arg === null || typeof arg === \"boolean\" || typeof arg === \"number\" || typeof arg === \"string\" || typeof arg === \"symbol\" || typeof arg === \"undefined\";\n}, pad = function(n) {\n return n < 10 \? \"0\" + n.toString(10) : n.toString(10);\n}, timestamp = function() {\n var d = new Date, time = [pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].join(\":\");\n return [d.getDate(), months[d.getMonth()], time].join(\" \");\n}, hasOwnProperty = function(obj, prop) {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}, callbackifyOnRejected = function(reason, cb) {\n if (!reason) {\n var newReason = new Error(\"Promise was rejected with a falsy value\");\n newReason.reason = reason, newReason.code = \"ERR_FALSY_VALUE_REJECTION\", reason = newReason;\n }\n return cb(reason);\n}, callbackify = function(original) {\n if (typeof original !== \"function\")\n @throwTypeError('The \"original\" argument must be of type Function');\n function callbackified() {\n var args = Array.prototype.slice.call(arguments), maybeCb = args.pop();\n if (typeof maybeCb !== \"function\")\n @throwTypeError(\"The last argument must be of type Function\");\n var self = this, cb = function() {\n return maybeCb.apply(self, arguments);\n };\n original.apply(this, args).then(function(ret) {\n process.nextTick(cb, null, ret);\n }, function(rej) {\n process.nextTick(callbackifyOnRejected, rej, cb);\n });\n }\n return Object.setPrototypeOf(callbackified, Object.getPrototypeOf(original)), Object.defineProperties(callbackified, getOwnPropertyDescriptors(original)), callbackified;\n}, $, types = @requireNativeModule(\"node:util/types\"), cjs_exports = {}, deepEquals = Bun.deepEquals, isDeepStrictEqual = (a, b) => deepEquals(a, b, !0), getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors, formatRegExp = /%[sdjfoc%]/g, debugs = {}, debugEnvRegex = /^$/;\nif (process.env.NODE_DEBUG)\n debugEnv = process.env.NODE_DEBUG, debugEnv = debugEnv.replace(/[|\\\\{}()[\\]^$+\?.]/g, \"\\\\$&\").replace(/\\*/g, \".*\").replace(/,/g, \"$|^\").toUpperCase(), debugEnvRegex = new RegExp(\"^\" + debugEnv + \"$\", \"i\");\nvar debugEnv;\ninspect.colors = {\n bold: [1, 22],\n italic: [3, 23],\n underline: [4, 24],\n inverse: [7, 27],\n white: [37, 39],\n grey: [90, 39],\n black: [30, 39],\n blue: [34, 39],\n cyan: [36, 39],\n green: [32, 39],\n magenta: [35, 39],\n red: [31, 39],\n yellow: [33, 39]\n};\ninspect.styles = {\n special: \"cyan\",\n number: \"yellow\",\n boolean: \"yellow\",\n undefined: \"grey\",\n null: \"bold\",\n string: \"green\",\n date: \"magenta\",\n regexp: \"red\"\n};\nvar { isRegExp, isDate, isNativeError: isError } = types, months = [\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\"], log = function log2() {\n console.log(\"%s - %s\", timestamp(), format.apply(cjs_exports, arguments));\n}, inherits = function inherits2(ctor, superCtor) {\n ctor.super_ = superCtor, ctor.prototype = Object.create(superCtor.prototype, {\n constructor: {\n value: ctor,\n enumerable: !1,\n writable: !0,\n configurable: !0\n }\n });\n}, _extend = function(origin, add) {\n if (!add || !isObject(add))\n return origin;\n var keys = Object.keys(add), i = keys.length;\n while (i--)\n origin[keys[i]] = add[keys[i]];\n return origin;\n}, kCustomPromisifiedSymbol = Symbol.for(\"util.promisify.custom\"), promisify = function promisify2(original) {\n if (typeof original !== \"function\")\n @throwTypeError('The \"original\" argument must be of type Function');\n if (kCustomPromisifiedSymbol && original[kCustomPromisifiedSymbol]) {\n var fn = original[kCustomPromisifiedSymbol];\n if (typeof fn !== \"function\")\n @throwTypeError('The \"util.promisify.custom\" argument must be of type Function');\n return Object.defineProperty(fn, kCustomPromisifiedSymbol, {\n value: fn,\n enumerable: !1,\n writable: !1,\n configurable: !0\n }), fn;\n }\n function fn() {\n var promiseResolve, promiseReject, promise = new Promise(function(resolve, reject) {\n promiseResolve = resolve, promiseReject = reject;\n }), args = [];\n for (var i = 0;i < arguments.length; i++)\n args.push(arguments[i]);\n args.push(function(err, value) {\n if (err)\n promiseReject(err);\n else\n promiseResolve(value);\n });\n try {\n original.apply(this, args);\n } catch (err) {\n promiseReject(err);\n }\n return promise;\n }\n if (Object.setPrototypeOf(fn, Object.getPrototypeOf(original)), kCustomPromisifiedSymbol)\n Object.defineProperty(fn, kCustomPromisifiedSymbol, {\n value: fn,\n enumerable: !1,\n writable: !1,\n configurable: !0\n });\n return Object.defineProperties(fn, getOwnPropertyDescriptors(original));\n};\npromisify.custom = kCustomPromisifiedSymbol;\nvar toUSVString = (input) => {\n return (input + \"\").toWellFormed();\n};\n$ = Object.assign(cjs_exports, {\n format,\n formatWithOptions,\n deprecate,\n debuglog,\n _extend,\n inspect,\n types,\n isArray: @isArray,\n isBoolean,\n isNull,\n isNullOrUndefined,\n isNumber,\n isString,\n isSymbol,\n isUndefined,\n isRegExp,\n isObject,\n isDate,\n isFunction,\n isError,\n isPrimitive,\n isBuffer,\n log,\n inherits,\n toUSVString,\n promisify,\n callbackify,\n isDeepStrictEqual,\n TextDecoder,\n TextEncoder\n});\nreturn $})\n"_s; +static constexpr ASCIILiteral NodeUtilCode = "(function (){\"use strict\";// src/js/out/tmp/node/util.ts\nvar isBufferInterface = function({ copy, fill, readUint8 }) {\n return typeof copy === \"function\" && typeof fill === \"function\" && typeof readUint8 === \"function\";\n}, isBuffer = function(value) {\n return Buffer.isBuffer(value) || typeof value === \"object\" && isBufferInterface(value || {});\n}, isFunction = function(value) {\n return typeof value === \"function\";\n}, formatWithOptions = function(inspectOptions, f) {\n if (!isString(f)) {\n var objects = [];\n for (var i = 0;i < arguments.length; i++)\n objects.push(inspect(arguments[i], inspectOptions));\n return objects.join(\" \");\n }\n var i = 2, args = arguments, len = args.length, str = String(f).replace(formatRegExp, function(x2) {\n if (x2 === \"%%\")\n return \"%\";\n if (i >= len)\n return x2;\n switch (x2) {\n case \"%s\":\n return String(args[i++]);\n case \"%f\":\n return Number(args[i++]);\n case \"%d\":\n return Math.round(Number(args[i++]));\n case \"%j\":\n try {\n return JSON.stringify(args[i++]);\n } catch (_) {\n return \"[Circular]\";\n }\n case \"%o\":\n return inspect(args[i++], { showHidden: !0, showProxy: !0, ...inspectOptions });\n case \"%O\":\n return inspect(args[i++], { showHidden: !0, showProxy: !0, ...inspectOptions });\n default:\n return x2;\n }\n });\n for (var x = args[i];i < len; x = args[++i])\n if (isNull(x) || !isObject(x))\n str += \" \" + x;\n else\n str += \" \" + inspect(x, inspectOptions);\n return str;\n}, format = function(...args) {\n return formatWithOptions({}, ...args);\n}, deprecate = function(fn, msg, code) {\n if (process.noDeprecation === !0)\n return fn;\n var warned = !1;\n function deprecated() {\n if (!warned) {\n if (process.throwDeprecation) {\n var err = new Error(msg);\n if (code)\n err.code = code;\n throw err;\n } else if (process.traceDeprecation)\n console.trace(msg);\n else\n console.error(msg);\n warned = !0;\n }\n return fn.apply(this, arguments);\n }\n return deprecated;\n}, debuglog = function(set) {\n if (set = set.toUpperCase(), !debugs[set])\n if (debugEnvRegex.test(set)) {\n var pid = process.pid;\n debugs[set] = function() {\n var msg = format.apply(cjs_exports, arguments);\n console.error(\"%s %d: %s\", set, pid, msg);\n };\n } else\n debugs[set] = function() {\n };\n return debugs[set];\n}, inspect = function(obj, opts) {\n var ctx = {\n seen: [],\n stylize: stylizeNoColor\n };\n if (arguments.length >= 3)\n ctx.depth = arguments[2];\n if (arguments.length >= 4)\n ctx.colors = arguments[3];\n if (isBoolean(opts))\n ctx.showHidden = opts;\n else if (opts)\n _extend(ctx, opts);\n if (isUndefined(ctx.showHidden))\n ctx.showHidden = !1;\n if (isUndefined(ctx.depth))\n ctx.depth = 2;\n if (isUndefined(ctx.colors))\n ctx.colors = !1;\n if (isUndefined(ctx.customInspect))\n ctx.customInspect = !0;\n if (ctx.colors)\n ctx.stylize = stylizeWithColor;\n return formatValue(ctx, obj, ctx.depth);\n}, stylizeWithColor = function(str, styleType) {\n const style = inspect.styles[styleType];\n if (style !== void 0) {\n const color = inspect.colors[style];\n if (color !== void 0)\n return `\\x1B[${color[0]}m${str}\\x1B[${color[1]}m`;\n }\n return str;\n}, stylizeNoColor = function(str, styleType) {\n return str;\n}, arrayToHash = function(array) {\n var hash = {};\n return array.forEach(function(val, idx) {\n hash[val] = !0;\n }), hash;\n}, formatValue = function(ctx, value, recurseTimes) {\n if (ctx.customInspect && value) {\n const customInspect = value[kInspectCustom];\n if (isFunction(customInspect)) {\n var ret = customInspect.call(value, recurseTimes, ctx, inspect);\n if (!isString(ret))\n ret = formatValue(ctx, ret, recurseTimes);\n return ret;\n }\n }\n var primitive = formatPrimitive(ctx, value);\n if (primitive)\n return primitive;\n var keys = Object.keys(value).concat(Object.getOwnPropertySymbols(value)), visibleKeys = arrayToHash(keys);\n if (ctx.showHidden)\n keys = Object.getOwnPropertyNames(value);\n if (isError(value) && (keys.indexOf(\"message\") >= 0 || keys.indexOf(\"description\") >= 0))\n return formatError(value);\n if (keys.length === 0) {\n if (isFunction(value)) {\n var name = value.name \? \": \" + value.name : \"\";\n return ctx.stylize(\"[Function\" + name + \"]\", \"special\");\n }\n if (isRegExp(value))\n return ctx.stylize(RegExp.prototype.toString.call(value), \"regexp\");\n if (isDate(value))\n return ctx.stylize(Date.prototype.toString.call(value), \"date\");\n if (isError(value))\n return formatError(value);\n }\n var base = \"\", array = !1, braces = [\"{\", \"}\"];\n if (@isArray(value))\n array = !0, braces = [\"[\", \"]\"];\n if (isFunction(value)) {\n var n = value.name \? \": \" + value.name : \"\";\n base = \" [Function\" + n + \"]\";\n }\n if (isRegExp(value))\n base = \" \" + RegExp.prototype.toString.call(value);\n if (isDate(value))\n base = \" \" + Date.prototype.toUTCString.call(value);\n if (isError(value))\n base = \" \" + formatError(value);\n if (keys.length === 0 && (!array || value.length == 0))\n return braces[0] + base + braces[1];\n if (recurseTimes < 0)\n if (isRegExp(value))\n return ctx.stylize(RegExp.prototype.toString.call(value), \"regexp\");\n else\n return ctx.stylize(\"[Object]\", \"special\");\n ctx.seen.push(value);\n var output;\n if (array)\n output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);\n else\n output = keys.map(function(key) {\n return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);\n });\n return ctx.seen.pop(), reduceToSingleString(output, base, braces);\n}, formatPrimitive = function(ctx, value) {\n if (isUndefined(value))\n return ctx.stylize(\"undefined\", \"undefined\");\n if (isString(value)) {\n var simple = \"'\" + JSON.stringify(value).replace(/^\"|\"$/g, \"\").replace(/'/g, \"\\\\'\").replace(/\\\\\"/g, '\"') + \"'\";\n return ctx.stylize(simple, \"string\");\n }\n if (isNumber(value))\n return ctx.stylize(\"\" + value, \"number\");\n if (isBoolean(value))\n return ctx.stylize(\"\" + value, \"boolean\");\n if (isNull(value))\n return ctx.stylize(\"null\", \"null\");\n}, formatError = function(value) {\n return \"[\" + Error.prototype.toString.call(value) + \"]\";\n}, formatArray = function(ctx, value, recurseTimes, visibleKeys, keys) {\n var output = [];\n for (var i = 0, l = value.length;i < l; ++i)\n if (hasOwnProperty(value, String(i)))\n output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, String(i), !0));\n else\n output.push(\"\");\n return keys.forEach(function(key) {\n if (!key.match(/^\\d+$/))\n output.push(formatProperty(ctx, value, recurseTimes, visibleKeys, key, !0));\n }), output;\n}, formatProperty = function(ctx, value, recurseTimes, visibleKeys, key, array) {\n var name, str, desc;\n if (desc = Object.getOwnPropertyDescriptor(value, key) || {\n value: value[key]\n }, desc.get)\n if (desc.set)\n str = ctx.stylize(\"[Getter/Setter]\", \"special\");\n else\n str = ctx.stylize(\"[Getter]\", \"special\");\n else if (desc.set)\n str = ctx.stylize(\"[Setter]\", \"special\");\n if (!hasOwnProperty(visibleKeys, key))\n name = \"[\" + (typeof key === \"symbol\" \? key.description : key) + \"]\";\n if (typeof key === \"symbol\")\n name = \"[\" + ctx.stylize(`Symbol(${key.description})`, \"string\") + \"]\";\n if (!str)\n if (ctx.seen.indexOf(desc.value) < 0) {\n if (isNull(recurseTimes))\n str = formatValue(ctx, desc.value, null);\n else\n str = formatValue(ctx, desc.value, recurseTimes - 1);\n if (str.indexOf(\"\\n\") > -1)\n if (array)\n str = str.split(\"\\n\").map(function(line) {\n return \" \" + line;\n }).join(\"\\n\").substr(2);\n else\n str = \"\\n\" + str.split(\"\\n\").map(function(line) {\n return \" \" + line;\n }).join(\"\\n\");\n } else\n str = ctx.stylize(\"[Circular]\", \"special\");\n if (isUndefined(name)) {\n if (array && key.match(/^\\d+$/))\n return str;\n if (name = JSON.stringify(\"\" + key), name.match(/^\"([a-zA-Z_][a-zA-Z_0-9]*)\"$/))\n name = name.substr(1, name.length - 2), name = ctx.stylize(name, \"name\");\n else\n name = name.replace(/'/g, \"\\\\'\").replace(/\\\\\"/g, '\"').replace(/(^\"|\"$)/g, \"'\"), name = ctx.stylize(name, \"string\");\n }\n return name + \": \" + str;\n}, reduceToSingleString = function(output, base, braces) {\n var numLinesEst = 0, length = output.reduce(function(prev, cur) {\n if (numLinesEst++, cur.indexOf(\"\\n\") >= 0)\n numLinesEst++;\n return prev + cur.replace(/\\u001b\\[\\d\\d\?m/g, \"\").length + 1;\n }, 0);\n if (length > 60)\n return braces[0] + (base === \"\" \? \"\" : base + \"\\n \") + \" \" + output.join(\",\\n \") + \" \" + braces[1];\n return braces[0] + base + \" \" + output.join(\", \") + \" \" + braces[1];\n}, isBoolean = function(arg) {\n return typeof arg === \"boolean\";\n}, isNull = function(arg) {\n return arg === null;\n}, isNullOrUndefined = function(arg) {\n return arg == null;\n}, isNumber = function(arg) {\n return typeof arg === \"number\";\n}, isString = function(arg) {\n return typeof arg === \"string\";\n}, isSymbol = function(arg) {\n return typeof arg === \"symbol\";\n}, isUndefined = function(arg) {\n return arg === void 0;\n}, isObject = function(arg) {\n return typeof arg === \"object\" && arg !== null;\n}, isPrimitive = function(arg) {\n return arg === null || typeof arg === \"boolean\" || typeof arg === \"number\" || typeof arg === \"string\" || typeof arg === \"symbol\" || typeof arg === \"undefined\";\n}, pad = function(n) {\n return n < 10 \? \"0\" + n.toString(10) : n.toString(10);\n}, timestamp = function() {\n var d = new Date, time = [pad(d.getHours()), pad(d.getMinutes()), pad(d.getSeconds())].join(\":\");\n return [d.getDate(), months[d.getMonth()], time].join(\" \");\n}, hasOwnProperty = function(obj, prop) {\n return Object.prototype.hasOwnProperty.call(obj, prop);\n}, callbackifyOnRejected = function(reason, cb) {\n if (!reason) {\n var newReason = new Error(\"Promise was rejected with a falsy value\");\n newReason.reason = reason, newReason.code = \"ERR_FALSY_VALUE_REJECTION\", reason = newReason;\n }\n return cb(reason);\n}, callbackify = function(original) {\n if (typeof original !== \"function\")\n @throwTypeError('The \"original\" argument must be of type Function');\n function callbackified() {\n var args = Array.prototype.slice.call(arguments), maybeCb = args.pop();\n if (typeof maybeCb !== \"function\")\n @throwTypeError(\"The last argument must be of type Function\");\n var self = this, cb = function() {\n return maybeCb.apply(self, arguments);\n };\n original.apply(this, args).then(function(ret) {\n process.nextTick(cb, null, ret);\n }, function(rej) {\n process.nextTick(callbackifyOnRejected, rej, cb);\n });\n }\n return Object.setPrototypeOf(callbackified, Object.getPrototypeOf(original)), Object.defineProperties(callbackified, getOwnPropertyDescriptors(original)), callbackified;\n}, $, types = @requireNativeModule(\"node:util/types\"), cjs_exports = {}, deepEquals = Bun.deepEquals, isDeepStrictEqual = (a, b) => deepEquals(a, b, !0), getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors, formatRegExp = /%[sdjfoc%]/g, debugs = {}, debugEnvRegex = /^$/;\nif (process.env.NODE_DEBUG)\n debugEnv = process.env.NODE_DEBUG, debugEnv = debugEnv.replace(/[|\\\\{}()[\\]^$+\?.]/g, \"\\\\$&\").replace(/\\*/g, \".*\").replace(/,/g, \"$|^\").toUpperCase(), debugEnvRegex = new RegExp(\"^\" + debugEnv + \"$\", \"i\");\nvar debugEnv, kInspectCustom = Symbol.for(\"nodejs.util.inspect.custom\");\ninspect.colors = {\n bold: [1, 22],\n italic: [3, 23],\n underline: [4, 24],\n inverse: [7, 27],\n white: [37, 39],\n grey: [90, 39],\n black: [30, 39],\n blue: [34, 39],\n cyan: [36, 39],\n green: [32, 39],\n magenta: [35, 39],\n red: [31, 39],\n yellow: [33, 39]\n};\ninspect.styles = {\n special: \"cyan\",\n number: \"yellow\",\n boolean: \"yellow\",\n undefined: \"grey\",\n null: \"bold\",\n string: \"green\",\n date: \"magenta\",\n regexp: \"red\"\n};\ninspect.custom = kInspectCustom;\ninspect.defaultOptions = {\n showHidden: !1,\n depth: 2,\n colors: !1,\n customInspect: !0,\n showProxy: !1,\n maxArrayLength: 100,\n maxStringLength: 1e4,\n breakLength: 80,\n compact: 3,\n sorted: !1,\n getters: !1,\n numericSeparator: !1\n};\nvar { isRegExp, isDate, isNativeError: isError } = types, months = [\"Jan\", \"Feb\", \"Mar\", \"Apr\", \"May\", \"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\"], log = function log2() {\n console.log(\"%s - %s\", timestamp(), format.apply(cjs_exports, arguments));\n}, inherits = function inherits2(ctor, superCtor) {\n ctor.super_ = superCtor, ctor.prototype = Object.create(superCtor.prototype, {\n constructor: {\n value: ctor,\n enumerable: !1,\n writable: !0,\n configurable: !0\n }\n });\n}, _extend = function(origin, add) {\n if (!add || !isObject(add))\n return origin;\n var keys = Object.keys(add), i = keys.length;\n while (i--)\n origin[keys[i]] = add[keys[i]];\n return origin;\n}, kCustomPromisifiedSymbol = Symbol.for(\"util.promisify.custom\"), promisify = function promisify2(original) {\n if (typeof original !== \"function\")\n @throwTypeError('The \"original\" argument must be of type Function');\n if (kCustomPromisifiedSymbol && original[kCustomPromisifiedSymbol]) {\n var fn = original[kCustomPromisifiedSymbol];\n if (typeof fn !== \"function\")\n @throwTypeError('The \"util.promisify.custom\" argument must be of type Function');\n return Object.defineProperty(fn, kCustomPromisifiedSymbol, {\n value: fn,\n enumerable: !1,\n writable: !1,\n configurable: !0\n }), fn;\n }\n function fn() {\n var promiseResolve, promiseReject, promise = new Promise(function(resolve, reject) {\n promiseResolve = resolve, promiseReject = reject;\n }), args = [];\n for (var i = 0;i < arguments.length; i++)\n args.push(arguments[i]);\n args.push(function(err, value) {\n if (err)\n promiseReject(err);\n else\n promiseResolve(value);\n });\n try {\n original.apply(this, args);\n } catch (err) {\n promiseReject(err);\n }\n return promise;\n }\n if (Object.setPrototypeOf(fn, Object.getPrototypeOf(original)), kCustomPromisifiedSymbol)\n Object.defineProperty(fn, kCustomPromisifiedSymbol, {\n value: fn,\n enumerable: !1,\n writable: !1,\n configurable: !0\n });\n return Object.defineProperties(fn, getOwnPropertyDescriptors(original));\n};\npromisify.custom = kCustomPromisifiedSymbol;\nvar toUSVString = (input) => {\n return (input + \"\").toWellFormed();\n};\n$ = Object.assign(cjs_exports, {\n format,\n formatWithOptions,\n deprecate,\n debuglog,\n _extend,\n inspect,\n types,\n isArray: @isArray,\n isBoolean,\n isNull,\n isNullOrUndefined,\n isNumber,\n isString,\n isSymbol,\n isUndefined,\n isRegExp,\n isObject,\n isDate,\n isFunction,\n isError,\n isPrimitive,\n isBuffer,\n log,\n inherits,\n toUSVString,\n promisify,\n callbackify,\n isDeepStrictEqual,\n TextDecoder,\n TextEncoder\n});\nreturn $})\n"_s; // // diff --git a/src/js/out/WebCoreJSBuiltins.cpp b/src/js/out/WebCoreJSBuiltins.cpp index f789f3d25..38114bab6 100644 --- a/src/js/out/WebCoreJSBuiltins.cpp +++ b/src/js/out/WebCoreJSBuiltins.cpp @@ -1339,6 +1339,32 @@ JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \ WEBCORE_FOREACH_READABLEBYTESTREAMCONTROLLER_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR) #undef DEFINE_BUILTIN_GENERATOR +/* UtilInspect.ts */ +// getStylizeWithColor +const JSC::ConstructAbility s_utilInspectGetStylizeWithColorCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; +const JSC::ConstructorKind s_utilInspectGetStylizeWithColorCodeConstructorKind = JSC::ConstructorKind::None; +const JSC::ImplementationVisibility s_utilInspectGetStylizeWithColorCodeImplementationVisibility = JSC::ImplementationVisibility::Public; +const int s_utilInspectGetStylizeWithColorCodeLength = 261; +static const JSC::Intrinsic s_utilInspectGetStylizeWithColorCodeIntrinsic = JSC::NoIntrinsic; +const char* const s_utilInspectGetStylizeWithColorCode = "(function (inspect){\"use strict\";return function stylizeWithColor(str,styleType){const style=inspect.styles[styleType];if(style!==@undefined){const color=inspect.colors[style];if(color!==@undefined)return`\\x1B[${color[0]}m${str}\\x1B[${color[1]}m`}return str}})\n"; + +// stylizeWithNoColor +const JSC::ConstructAbility s_utilInspectStylizeWithNoColorCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; +const JSC::ConstructorKind s_utilInspectStylizeWithNoColorCodeConstructorKind = JSC::ConstructorKind::None; +const JSC::ImplementationVisibility s_utilInspectStylizeWithNoColorCodeImplementationVisibility = JSC::ImplementationVisibility::Public; +const int s_utilInspectStylizeWithNoColorCodeLength = 42; +static const JSC::Intrinsic s_utilInspectStylizeWithNoColorCodeIntrinsic = JSC::NoIntrinsic; +const char* const s_utilInspectStylizeWithNoColorCode = "(function (str){\"use strict\";return str})\n"; + +#define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \ +JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \ +{\ + JSVMClientData* clientData = static_cast<JSVMClientData*>(vm.clientData); \ + return clientData->builtinFunctions().utilInspectBuiltins().codeName##Executable()->link(vm, nullptr, clientData->builtinFunctions().utilInspectBuiltins().codeName##Source(), std::nullopt, s_##codeName##Intrinsic); \ +} +WEBCORE_FOREACH_UTILINSPECT_BUILTIN_CODE(DEFINE_BUILTIN_GENERATOR) +#undef DEFINE_BUILTIN_GENERATOR + /* ConsoleObject.ts */ // asyncIterator const JSC::ConstructAbility s_consoleObjectAsyncIteratorCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; diff --git a/src/js/out/WebCoreJSBuiltins.h b/src/js/out/WebCoreJSBuiltins.h index e540facb9..e2ecb32d8 100644 --- a/src/js/out/WebCoreJSBuiltins.h +++ b/src/js/out/WebCoreJSBuiltins.h @@ -2391,6 +2391,95 @@ inline void ReadableByteStreamControllerBuiltinsWrapper::exportNames() WEBCORE_FOREACH_READABLEBYTESTREAMCONTROLLER_BUILTIN_FUNCTION_NAME(EXPORT_FUNCTION_NAME) #undef EXPORT_FUNCTION_NAME } +/* UtilInspect.ts */ +// getStylizeWithColor +#define WEBCORE_BUILTIN_UTILINSPECT_GETSTYLIZEWITHCOLOR 1 +extern const char* const s_utilInspectGetStylizeWithColorCode; +extern const int s_utilInspectGetStylizeWithColorCodeLength; +extern const JSC::ConstructAbility s_utilInspectGetStylizeWithColorCodeConstructAbility; +extern const JSC::ConstructorKind s_utilInspectGetStylizeWithColorCodeConstructorKind; +extern const JSC::ImplementationVisibility s_utilInspectGetStylizeWithColorCodeImplementationVisibility; + +// stylizeWithNoColor +#define WEBCORE_BUILTIN_UTILINSPECT_STYLIZEWITHNOCOLOR 1 +extern const char* const s_utilInspectStylizeWithNoColorCode; +extern const int s_utilInspectStylizeWithNoColorCodeLength; +extern const JSC::ConstructAbility s_utilInspectStylizeWithNoColorCodeConstructAbility; +extern const JSC::ConstructorKind s_utilInspectStylizeWithNoColorCodeConstructorKind; +extern const JSC::ImplementationVisibility s_utilInspectStylizeWithNoColorCodeImplementationVisibility; + +#define WEBCORE_FOREACH_UTILINSPECT_BUILTIN_DATA(macro) \ + macro(getStylizeWithColor, utilInspectGetStylizeWithColor, 1) \ + macro(stylizeWithNoColor, utilInspectStylizeWithNoColor, 1) \ + +#define WEBCORE_FOREACH_UTILINSPECT_BUILTIN_CODE(macro) \ + macro(utilInspectGetStylizeWithColorCode, getStylizeWithColor, ASCIILiteral(), s_utilInspectGetStylizeWithColorCodeLength) \ + macro(utilInspectStylizeWithNoColorCode, stylizeWithNoColor, ASCIILiteral(), s_utilInspectStylizeWithNoColorCodeLength) \ + +#define WEBCORE_FOREACH_UTILINSPECT_BUILTIN_FUNCTION_NAME(macro) \ + macro(getStylizeWithColor) \ + macro(stylizeWithNoColor) \ + +#define DECLARE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \ + JSC::FunctionExecutable* codeName##Generator(JSC::VM&); + +WEBCORE_FOREACH_UTILINSPECT_BUILTIN_CODE(DECLARE_BUILTIN_GENERATOR) +#undef DECLARE_BUILTIN_GENERATOR + +class UtilInspectBuiltinsWrapper : private JSC::WeakHandleOwner { +public: + explicit UtilInspectBuiltinsWrapper(JSC::VM& vm) + : m_vm(vm) + WEBCORE_FOREACH_UTILINSPECT_BUILTIN_FUNCTION_NAME(INITIALIZE_BUILTIN_NAMES) +#define INITIALIZE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) , m_##name##Source(JSC::makeSource(StringImpl::createWithoutCopying(s_##name, length), { })) + WEBCORE_FOREACH_UTILINSPECT_BUILTIN_CODE(INITIALIZE_BUILTIN_SOURCE_MEMBERS) +#undef INITIALIZE_BUILTIN_SOURCE_MEMBERS + { + } + +#define EXPOSE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \ + JSC::UnlinkedFunctionExecutable* name##Executable(); \ + const JSC::SourceCode& name##Source() const { return m_##name##Source; } + WEBCORE_FOREACH_UTILINSPECT_BUILTIN_CODE(EXPOSE_BUILTIN_EXECUTABLES) +#undef EXPOSE_BUILTIN_EXECUTABLES + + WEBCORE_FOREACH_UTILINSPECT_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR) + + void exportNames(); + +private: + JSC::VM& m_vm; + + WEBCORE_FOREACH_UTILINSPECT_BUILTIN_FUNCTION_NAME(DECLARE_BUILTIN_NAMES) + +#define DECLARE_BUILTIN_SOURCE_MEMBERS(name, functionName, overriddenName, length) \ + JSC::SourceCode m_##name##Source;\ + JSC::Weak<JSC::UnlinkedFunctionExecutable> m_##name##Executable; + WEBCORE_FOREACH_UTILINSPECT_BUILTIN_CODE(DECLARE_BUILTIN_SOURCE_MEMBERS) +#undef DECLARE_BUILTIN_SOURCE_MEMBERS + +}; + +#define DEFINE_BUILTIN_EXECUTABLES(name, functionName, overriddenName, length) \ +inline JSC::UnlinkedFunctionExecutable* UtilInspectBuiltinsWrapper::name##Executable() \ +{\ + if (!m_##name##Executable) {\ + JSC::Identifier executableName = functionName##PublicName();\ + if (overriddenName)\ + executableName = JSC::Identifier::fromString(m_vm, overriddenName);\ + m_##name##Executable = JSC::Weak<JSC::UnlinkedFunctionExecutable>(JSC::createBuiltinExecutable(m_vm, m_##name##Source, executableName, s_##name##ImplementationVisibility, s_##name##ConstructorKind, s_##name##ConstructAbility), this, &m_##name##Executable);\ + }\ + return m_##name##Executable.get();\ +} +WEBCORE_FOREACH_UTILINSPECT_BUILTIN_CODE(DEFINE_BUILTIN_EXECUTABLES) +#undef DEFINE_BUILTIN_EXECUTABLES + +inline void UtilInspectBuiltinsWrapper::exportNames() +{ +#define EXPORT_FUNCTION_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName()); + WEBCORE_FOREACH_UTILINSPECT_BUILTIN_FUNCTION_NAME(EXPORT_FUNCTION_NAME) +#undef EXPORT_FUNCTION_NAME +} /* ConsoleObject.ts */ // asyncIterator #define WEBCORE_BUILTIN_CONSOLEOBJECT_ASYNCITERATOR 1 @@ -5613,6 +5702,7 @@ public: , m_moduleBuiltins(m_vm) , m_jsBufferPrototypeBuiltins(m_vm) , m_readableByteStreamControllerBuiltins(m_vm) + , m_utilInspectBuiltins(m_vm) , m_consoleObjectBuiltins(m_vm) , m_readableStreamInternalsBuiltins(m_vm) , m_transformStreamDefaultControllerBuiltins(m_vm) @@ -5646,6 +5736,7 @@ public: ModuleBuiltinsWrapper& moduleBuiltins() { return m_moduleBuiltins; } JSBufferPrototypeBuiltinsWrapper& jsBufferPrototypeBuiltins() { return m_jsBufferPrototypeBuiltins; } ReadableByteStreamControllerBuiltinsWrapper& readableByteStreamControllerBuiltins() { return m_readableByteStreamControllerBuiltins; } + UtilInspectBuiltinsWrapper& utilInspectBuiltins() { return m_utilInspectBuiltins; } ConsoleObjectBuiltinsWrapper& consoleObjectBuiltins() { return m_consoleObjectBuiltins; } ReadableStreamInternalsBuiltinsWrapper& readableStreamInternalsBuiltins() { return m_readableStreamInternalsBuiltins; } TransformStreamDefaultControllerBuiltinsWrapper& transformStreamDefaultControllerBuiltins() { return m_transformStreamDefaultControllerBuiltins; } @@ -5674,6 +5765,7 @@ private: ModuleBuiltinsWrapper m_moduleBuiltins; JSBufferPrototypeBuiltinsWrapper m_jsBufferPrototypeBuiltins; ReadableByteStreamControllerBuiltinsWrapper m_readableByteStreamControllerBuiltins; + UtilInspectBuiltinsWrapper m_utilInspectBuiltins; ConsoleObjectBuiltinsWrapper m_consoleObjectBuiltins; ReadableStreamInternalsBuiltinsWrapper m_readableStreamInternalsBuiltins; TransformStreamDefaultControllerBuiltinsWrapper m_transformStreamDefaultControllerBuiltins; diff --git a/test/js/bun/util/inspect.test.js b/test/js/bun/util/inspect.test.js index 4d5165543..6ae9e9816 100644 --- a/test/js/bun/util/inspect.test.js +++ b/test/js/bun/util/inspect.test.js @@ -94,12 +94,12 @@ it("utf16 property name", () => { }); it("latin1", () => { - expect(Bun.inspect("English")).toBe("English"); - expect(Bun.inspect("Français")).toBe("Français"); - expect(Bun.inspect("Ελληνική")).toBe("Ελληνική"); - expect(Bun.inspect("日本語")).toBe("日本語"); - expect(Bun.inspect("Emoji😎")).toBe("Emoji😎"); - expect(Bun.inspect("Français / Ελληνική")).toBe("Français / Ελληνική"); + expect(Bun.inspect("English")).toBe('"English"'); + expect(Bun.inspect("Français")).toBe('"Français"'); + expect(Bun.inspect("Ελληνική")).toBe('"Ελληνική"'); + expect(Bun.inspect("日本語")).toBe('"日本語"'); + expect(Bun.inspect("Emoji😎")).toBe('"Emoji😎"'); + expect(Bun.inspect("Français / Ελληνική")).toBe('"Français / Ελληνική"'); }); it("Request object", () => { @@ -213,12 +213,11 @@ it("jsx with fragment", () => { it("inspect", () => { expect(Bun.inspect(new TypeError("what")).includes("TypeError: what")).toBe(true); - expect("hi").toBe("hi"); + expect(Bun.inspect("hi")).toBe('"hi"'); expect(Bun.inspect(1)).toBe("1"); expect(Bun.inspect(NaN)).toBe("NaN"); expect(Bun.inspect(Infinity)).toBe("Infinity"); expect(Bun.inspect(-Infinity)).toBe("-Infinity"); - expect(Bun.inspect(1, "hi")).toBe("1 hi"); expect(Bun.inspect([])).toBe("[]"); expect(Bun.inspect({})).toBe("{}"); expect(Bun.inspect({ hello: 1 })).toBe("{\n hello: 1\n}"); @@ -229,7 +228,7 @@ it("inspect", () => { while (str.length < 4096) { str += "123"; } - expect(Bun.inspect(str)).toBe(str); + expect(Bun.inspect(str)).toBe('"' + str + '"'); // expect(Bun.inspect(new Headers())).toBe("Headers (0 KB) {}"); expect(Bun.inspect(new Response()).length > 0).toBe(true); // expect( @@ -277,18 +276,15 @@ describe("latin1 supplemental", () => { it(`latin1 (input) \"${input}\" ${output}`, () => { expect(Bun.inspect(input)).toBe(output); }); - it(`latin1 (output) \"${output}\"`, () => { - expect(Bun.inspect(output)).toBe(output); - }); - // this test is failing: - // it(`latin1 (property key)`, () => { - // expect( - // Object.keys({ - // ä: 1, - // })[0].codePointAt(0), - // ).toBe(228); - // }); } + // this test is failing: + it(`latin1 (property key)`, () => { + expect( + Object.keys({ + ä: 1, + })[0].codePointAt(0), + ).toBe(228); + }); }); const fixture = [ @@ -329,7 +325,9 @@ describe("crash testing", () => { for (let input of fixture) { it(`inspecting "${input.toString().slice(0, 20).replaceAll("\n", "\\n")}" doesn't crash`, async () => { try { + console.log("asked" + input.toString().slice(0, 20).replaceAll("\n", "\\n")); Bun.inspect(await input()); + console.log("who"); } catch (e) { // this can throw its fine } @@ -338,7 +336,7 @@ describe("crash testing", () => { }); it("possibly formatted emojis log", () => { - expect(Bun.inspect("✔", "hey")).toBe("✔ hey"); + expect(Bun.inspect("✔")).toBe('"✔"'); }); it("new Date(..)", () => { @@ -352,8 +350,8 @@ it("new Date(..)", () => { } expect(Bun.inspect(new Date("March 27, 2023 " + hour + ":54:00"))).toBe("2023-03-27T09:54:00.000Z"); expect(Bun.inspect(new Date("2023-03-27T" + hour + ":54:00"))).toBe("2023-03-27T09:54:00.000Z"); - expect(Bun.inspect(new Date(2023, 02, 27, -offset))).toBe("2023-03-27T00:00:00.000Z"); - expect(Bun.inspect(new Date(2023, 02, 27, 09 - offset, 54, 0))).toBe("2023-03-27T09:54:00.000Z"); + expect(Bun.inspect(new Date(2023, 2, 27, -offset))).toBe("2023-03-27T00:00:00.000Z"); + expect(Bun.inspect(new Date(2023, 2, 27, 9 - offset, 54, 0))).toBe("2023-03-27T09:54:00.000Z"); expect(Bun.inspect(new Date("1679911059000"))).toBe("Invalid Date"); expect(Bun.inspect(new Date("hello world"))).toBe("Invalid Date"); diff --git a/test/js/node/util/bun-inspect.test.ts b/test/js/node/util/bun-inspect.test.ts new file mode 100644 index 000000000..308f275b9 --- /dev/null +++ b/test/js/node/util/bun-inspect.test.ts @@ -0,0 +1,23 @@ +import { describe, it, expect } from "bun:test"; + +describe("Bun.inspect", () => { + it("depth < 0 throws", () => { + expect(() => Bun.inspect({}, { depth: -1 })).toThrow(); + expect(() => Bun.inspect({}, { depth: -13210 })).toThrow(); + }); + it("depth = Infinity works", () => { + function createRecursiveObject(n: number): any { + if (n === 0) return { hi: true }; + return { a: createRecursiveObject(n - 1) }; + } + + const obj = createRecursiveObject(1000); + + expect(Bun.inspect(obj, { depth: Infinity })).toContain("hi"); + // this gets converted to u16, which if just truncating, will turn into 0 + expect(Bun.inspect(obj, { depth: 0x0fff0000 })).toContain("hi"); + }); + it("depth = 0", () => { + expect(Bun.inspect({ a: { b: { c: { d: 1 } } } }, { depth: 0 })).toEqual("{\n a: [Object ...]\n}"); + }); +}); diff --git a/test/js/node/util/custom-inspect.test.js b/test/js/node/util/custom-inspect.test.js new file mode 100644 index 000000000..06cad262a --- /dev/null +++ b/test/js/node/util/custom-inspect.test.js @@ -0,0 +1,155 @@ +// this file is compatible with jest to test node.js' util.inspect as well as bun's + +const util = require("util"); + +test("util.inspect.custom exists", () => { + expect(util.inspect.custom).toEqual(Symbol.for("nodejs.util.inspect.custom")); +}); + +const customSymbol = util.inspect.custom; + +for (const [name, inspect] of process.versions.bun + ? [ + ["util.inspect", util.inspect], + ["Bun.inspect", Bun.inspect], + ] + : [["util.inspect", util.inspect]]) { + test(name + " calls inspect.custom", () => { + const obj = { + [customSymbol]() { + return "42"; + }, + }; + + expect(inspect(obj)).toBe("42"); + }); + + test(name + " calls inspect.custom recursivly", () => { + const obj = { + [customSymbol]() { + return { + [customSymbol]() { + return "42"; + }, + }; + }, + }; + + expect(inspect(obj)).toBe("42"); + }); + + test(name + " calls inspect.custom recursivly nested", () => { + const obj = { + [customSymbol]() { + return { + prop: { + [customSymbol]() { + return "42"; + }, + }, + }; + }, + }; + + expect(inspect(obj).replace(/\s/g, "")).toBe("{prop:42}"); + }); + + test(name + " calls inspect.custom recursivly nested 2", () => { + const obj = { + prop: { + [customSymbol]() { + return { + [customSymbol]() { + return "42"; + }, + }; + }, + }, + }; + + expect(inspect(obj).replace(/\s/g, "")).toBe("{prop:42}"); + }); + + test(name + " calls inspect.custom with valid options", () => { + const obj = { + [customSymbol](depth, options, inspect) { + expect(this === obj).toBe(true); + expect(inspect).toBe(util.inspect); + expect(options.stylize).toBeDefined(); + expect(depth).toBeDefined(2); + return "good"; + }, + }; + + expect(inspect(obj).replace(/\s/g, "")).toBe("good"); + }); + + test(name + " stylize function works without color", () => { + const obj = { + [customSymbol](depth, options, inspect) { + expect(options.stylize).toBeDefined(); + expect(options.stylize("foo", "whatever")).toBe("foo"); + expect(options.stylize("hello", "string")).toBe("hello"); + return "good"; + }, + }; + + expect(inspect(obj).replace(/\s/g, "")).toBe("good"); + }); + + test(name + " stylize function works with color", () => { + const obj = { + [customSymbol](depth, options, inspect) { + expect(options.stylize).toBeDefined(); + expect(options.stylize("foo", "invalid")).toBe("foo"); + expect(options.stylize("foo", "boolean")).toBe("\u001b[33mfoo\u001b[39m"); + expect(options.stylize("hello", "string")).toBe("\u001b[32mhello\u001b[39m"); + return "good"; + }, + }; + + expect(inspect(obj, { colors: true }).replace(/\s/g, "")).toBe("good"); + }); + + test(name + " stylize function gives correct depth", () => { + const obj = { + [customSymbol](depth, options, inspect) { + return [depth, options.depth]; + }, + }; + expect(inspect(obj, { depth: 3 }).replace(/\s/g, "")).toBe("[3,3]"); + }); + test(name + " stylize function gives correct depth", () => { + const obj = { + prop: { + [customSymbol](depth, options, inspect) { + return [depth, options.depth]; + }, + }, + }; + expect(inspect(obj, { depth: 3 }).replace(/\s/g, "")).toBe("{prop:[2,3]}"); + }); + test(name + " non-callable does not get called", () => { + const obj = { + [customSymbol]: 512, + }; + expect(inspect(obj, { depth: 3 }).replace(/\s/g, "")).toBe("{[Symbol(nodejs.util.inspect.custom)]:512}"); + }); + + const exceptions = [new Error("don't crash!"), 42]; + + test.each(exceptions)(name + " handles exceptions %s", err => { + const obj = { + [customSymbol]() { + throw err; + }, + }; + + if (Bun.inspect === inspect) { + // make sure this doesnt crash + expect(inspect(obj)).toBeString(); + } else { + expect(() => inspect(obj)).toThrow(); + } + }); +} |