diff options
author | 2023-09-18 19:29:56 -0400 | |
---|---|---|
committer | 2023-09-18 16:29:56 -0700 | |
commit | 333e217c320fdf5a6b62fa31df18389f01887bdd (patch) | |
tree | 2959dfcf1fe6c3b8390390913f9ec42a7a811870 | |
parent | f77df12894e7952ea58605432bf9f6d252fff273 (diff) | |
download | bun-333e217c320fdf5a6b62fa31df18389f01887bdd.tar.gz bun-333e217c320fdf5a6b62fa31df18389f01887bdd.tar.zst bun-333e217c320fdf5a6b62fa31df18389f01887bdd.zip |
feat(runtime): Implement `console.Console` (#5448)
* prototype
* asdfg
* It works!
* okay its done now fr
* self review
* ok
* fix
* fix test
---------
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
-rw-r--r-- | packages/bun-types/globals.d.ts | 25 | ||||
m--------- | src/bun.js/WebKit | 0 | ||||
-rw-r--r-- | src/bun.js/bindings/ZigGlobalObject.cpp | 36 | ||||
-rw-r--r-- | src/js/builtins/ConsoleObject.ts | 760 | ||||
-rw-r--r-- | src/js/node/util.js | 2 | ||||
-rw-r--r-- | src/js/out/InternalModuleRegistryConstants.h | 6 | ||||
-rw-r--r-- | src/js/out/WebCoreJSBuiltins.cpp | 8 | ||||
-rw-r--r-- | src/js/out/WebCoreJSBuiltins.h | 11 | ||||
-rw-r--r-- | test/js/node/console/console-constructor.test.ts | 66 |
9 files changed, 906 insertions, 8 deletions
diff --git a/packages/bun-types/globals.d.ts b/packages/bun-types/globals.d.ts index 60bc40cd0..346342afd 100644 --- a/packages/bun-types/globals.d.ts +++ b/packages/bun-types/globals.d.ts @@ -1,5 +1,3 @@ -// import * as tls from 'node:tls'; - /** * "blob" is not supported yet */ @@ -105,6 +103,15 @@ type MultipleResolveListener = ( ) => void; // type WorkerListener = (worker: Worker) => void; +interface ConsoleOptions { + stdout: import("stream").Writable; + stderr?: import("stream").Writable; + ignoreErrors?: boolean; + colorMode?: boolean | "auto"; + inspectOptions?: import("util").InspectOptions; + groupIndentation?: number; +} + interface Console { /** * Asynchronously read lines from standard input (fd 0) @@ -205,7 +212,19 @@ interface Console { warn(...data: any[]): void; } -declare var console: Console; +declare var console: Console & { + /** + * Creates a new Console with one or two writable stream instances. stdout is a writable stream to print log or info output. stderr is used for warning or error output. If stderr is not provided, stdout is used for stderr. + */ + Console: { + new (options: ConsoleOptions): Console; + new ( + stdout: import("stream").Writable, + stderr?: import("stream").Writable, + ignoreErrors?: boolean, + ): Console; + }; +}; declare namespace NodeJS { interface RequireResolve { diff --git a/src/bun.js/WebKit b/src/bun.js/WebKit -Subproject a780bdf0255ae1a7ed15e4b3f31c14af705faca +Subproject 4d995edbc44062b251be638818edcd88d7d14dd diff --git a/src/bun.js/bindings/ZigGlobalObject.cpp b/src/bun.js/bindings/ZigGlobalObject.cpp index a75135844..9b36157fe 100644 --- a/src/bun.js/bindings/ZigGlobalObject.cpp +++ b/src/bun.js/bindings/ZigGlobalObject.cpp @@ -3315,11 +3315,44 @@ JSValue getEventSourceConstructor(VM& vm, JSObject* thisObject) if (returnedException) { throwException(globalObject, scope, returnedException.get()); + return jsUndefined(); } RELEASE_AND_RETURN(scope, result); } +// `console.Console` or `import { Console } from 'console';` +JSC_DEFINE_CUSTOM_GETTER(getConsoleConstructor, (JSGlobalObject * globalObject, EncodedJSValue thisValue, PropertyName property)) +{ + auto& vm = globalObject->vm(); + auto console = JSValue::decode(thisValue).getObject(); + JSC::JSFunction* createConsoleConstructor = JSC::JSFunction::create(vm, consoleObjectCreateConsoleConstructorCodeGenerator(vm), globalObject); + JSC::MarkedArgumentBuffer args; + args.append(console); + JSC::CallData callData = JSC::getCallData(createConsoleConstructor); + NakedPtr<JSC::Exception> returnedException = nullptr; + auto result = JSC::call(globalObject, createConsoleConstructor, callData, console, args, returnedException); + if (returnedException) { + auto scope = DECLARE_THROW_SCOPE(vm); + throwException(globalObject, scope, returnedException.get()); + } + console->putDirect(vm, property, result, 0); + return JSValue::encode(result); +} + +JSC_DEFINE_CUSTOM_SETTER(EventSource_setter, + (JSC::JSGlobalObject * globalObject, JSC::EncodedJSValue thisValue, + JSC::EncodedJSValue value, JSC::PropertyName property)) +{ + if (JSValue::decode(thisValue) != globalObject) { + return false; + } + + auto& vm = globalObject->vm(); + globalObject->putDirect(vm, property, JSValue::decode(value), 0); + return true; +} + EncodedJSValue GlobalObject::assignToStream(JSValue stream, JSValue controller) { JSC::VM& vm = this->vm(); @@ -3542,7 +3575,8 @@ void GlobalObject::addBuiltinGlobals(JSC::VM& vm) JSC::JSObject* consoleObject = this->get(this, JSC::Identifier::fromString(vm, "console"_s)).getObject(); consoleObject->putDirectBuiltinFunction(vm, this, vm.propertyNames->asyncIteratorSymbol, consoleObjectAsyncIteratorCodeGenerator(vm), PropertyAttribute::Builtin | 0); - consoleObject->putDirectBuiltinFunction(vm, this, clientData->builtinNames().writePublicName(), consoleObjectWriteCodeGenerator(vm), PropertyAttribute::Builtin | PropertyAttribute::ReadOnly | 0); + consoleObject->putDirectBuiltinFunction(vm, this, clientData->builtinNames().writePublicName(), consoleObjectWriteCodeGenerator(vm), PropertyAttribute::Builtin | 0); + consoleObject->putDirectCustomAccessor(vm, Identifier::fromString(vm, "Console"_s), CustomGetterSetter::create(vm, getConsoleConstructor, nullptr), 0); } extern "C" bool JSC__JSGlobalObject__startRemoteInspector(JSC__JSGlobalObject* globalObject, unsigned char* host, uint16_t arg1) diff --git a/src/js/builtins/ConsoleObject.ts b/src/js/builtins/ConsoleObject.ts index 2d657a78b..da316efdc 100644 --- a/src/js/builtins/ConsoleObject.ts +++ b/src/js/builtins/ConsoleObject.ts @@ -122,3 +122,763 @@ export function write(this: Console, input) { writer.flush(true); return wrote; } + +// This is the `console.Console` constructor. It is mostly copied from Node. +// https://github.com/nodejs/node/blob/d2c7c367741bdcb6f7f77f55ce95a745f0b29fef/lib/internal/console/constructor.js +// Some parts are copied from imported files and inlined here. Not too much of a performance issue +// to do extra work at startup, since most people do not need `console.Console`. +// TODO: probably could extract `getStringWidth`; probably make that a native function. note how it is copied from `readline.js` +export function createConsoleConstructor(console: typeof globalThis.console) { + const { inspect, formatWithOptions } = require("node:util"); + const { isBuffer } = require("node:buffer"); + + const StringPrototypeIncludes = String.prototype.includes; + const RegExpPrototypeSymbolReplace = RegExp.prototype[Symbol.replace]; + const ArrayPrototypeUnshift = Array.prototype.unshift; + const StringPrototypeRepeat = String.prototype.repeat; + const StringPrototypeSlice = String.prototype.slice; + const ObjectPrototypeHasOwnProperty = Object.prototype.hasOwnProperty; + const StringPrototypePadStart = String.prototype.padStart; + const StringPrototypeSplit = String.prototype.split; + const NumberPrototypeToFixed = Number.prototype.toFixed; + const StringPrototypeNormalize = String.prototype.normalize; + const StringPrototypeCodePointAt = String.prototype.codePointAt; + const ArrayPrototypeMap = Array.prototype.map; + const ArrayPrototypeJoin = Array.prototype.join; + const ArrayPrototypePush = Array.prototype.push; + + const kCounts = Symbol("counts"); + + const kSecond = 1000; + const kMinute = 60 * kSecond; + const kHour = 60 * kMinute; + + // Regex used for ansi escape code splitting + // Adopted from https://github.com/chalk/ansi-regex/blob/HEAD/index.js + // License: MIT, authors: @sindresorhus, Qix-, arjunmehta and LitoMore + // Matches all ansi escape code sequences in a string + var ansiPattern = + "[\\u001B\\u009B][[\\]()#;?]*" + + "(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*" + + "|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)" + + "|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))"; + var ansi = new RegExp(ansiPattern, "g"); + + /** + * Returns true if the character represented by a given + * Unicode code point is full-width. Otherwise returns false. + */ + var isFullWidthCodePoint = code => { + // Code points are partially derived from: + // https://www.unicode.org/Public/UNIDATA/EastAsianWidth.txt + return ( + code >= 0x1100 && + (code <= 0x115f || // Hangul Jamo + code === 0x2329 || // LEFT-POINTING ANGLE BRACKET + code === 0x232a || // RIGHT-POINTING ANGLE BRACKET + // CJK Radicals Supplement .. Enclosed CJK Letters and Months + (code >= 0x2e80 && code <= 0x3247 && code !== 0x303f) || + // Enclosed CJK Letters and Months .. CJK Unified Ideographs Extension A + (code >= 0x3250 && code <= 0x4dbf) || + // CJK Unified Ideographs .. Yi Radicals + (code >= 0x4e00 && code <= 0xa4c6) || + // Hangul Jamo Extended-A + (code >= 0xa960 && code <= 0xa97c) || + // Hangul Syllables + (code >= 0xac00 && code <= 0xd7a3) || + // CJK Compatibility Ideographs + (code >= 0xf900 && code <= 0xfaff) || + // Vertical Forms + (code >= 0xfe10 && code <= 0xfe19) || + // CJK Compatibility Forms .. Small Form Variants + (code >= 0xfe30 && code <= 0xfe6b) || + // Halfwidth and Fullwidth Forms + (code >= 0xff01 && code <= 0xff60) || + (code >= 0xffe0 && code <= 0xffe6) || + // Kana Supplement + (code >= 0x1b000 && code <= 0x1b001) || + // Enclosed Ideographic Supplement + (code >= 0x1f200 && code <= 0x1f251) || + // Miscellaneous Symbols and Pictographs 0x1f300 - 0x1f5ff + // Emoticons 0x1f600 - 0x1f64f + (code >= 0x1f300 && code <= 0x1f64f) || + // CJK Unified Ideographs Extension B .. Tertiary Ideographic Plane + (code >= 0x20000 && code <= 0x3fffd)) + ); + }; + + var isZeroWidthCodePoint = code => { + return ( + code <= 0x1f || // C0 control codes + (code >= 0x7f && code <= 0x9f) || // C1 control codes + (code >= 0x300 && code <= 0x36f) || // Combining Diacritical Marks + (code >= 0x200b && code <= 0x200f) || // Modifying Invisible Characters + // Combining Diacritical Marks for Symbols + (code >= 0x20d0 && code <= 0x20ff) || + (code >= 0xfe00 && code <= 0xfe0f) || // Variation Selectors + (code >= 0xfe20 && code <= 0xfe2f) || // Combining Half Marks + (code >= 0xe0100 && code <= 0xe01ef) + ); // Variation Selectors + }; + + function stripVTControlCharacters(str) { + return (RegExpPrototypeSymbolReplace as any).$call(ansi, str, ""); + } + + /** + * Returns the number of columns required to display the given string. + */ + var getStringWidth = function getStringWidth(str, removeControlChars = true) { + var width = 0; + + if (removeControlChars) str = stripVTControlCharacters(str); + str = StringPrototypeNormalize.$call(str, "NFC"); + for (var char of str) { + var code = StringPrototypeCodePointAt.$call(char, 0); + if (isFullWidthCodePoint(code)) { + width += 2; + } else if (!isZeroWidthCodePoint(code)) { + width++; + } + } + + return width; + }; + + const tableChars = { + middleMiddle: "─", + rowMiddle: "┼", + topRight: "┐", + topLeft: "┌", + leftMiddle: "├", + topMiddle: "┬", + bottomRight: "┘", + bottomLeft: "└", + bottomMiddle: "┴", + rightMiddle: "┤", + left: "│ ", + right: " │", + middle: " │ ", + }; + + const renderRow = (row, columnWidths) => { + let out = tableChars.left; + for (let i = 0; i < row.length; i++) { + const cell = row[i]; + const len = getStringWidth(cell); + const needed = (columnWidths[i] - len) / 2; + // round(needed) + ceil(needed) will always add up to the amount + // of spaces we need while also left justifying the output. + out += + (StringPrototypeRepeat as any).$call(" ", needed) + cell + StringPrototypeRepeat.$call(" ", Math.ceil(needed)); + if (i !== row.length - 1) out += tableChars.middle; + } + out += tableChars.right; + return out; + }; + + const table = (head, columns) => { + const columnWidths = ArrayPrototypeMap.call(head, h => getStringWidth(h)) as number[]; + const longestColumn = Math.max(...(ArrayPrototypeMap as any).$call(columns, a => a.length)); + const rows: any = $newArrayWithSize(longestColumn); + + for (let i = 0; i < head.length; i++) { + const column = columns[i]; + for (let j = 0; j < longestColumn; j++) { + if (rows[j] === undefined) rows[j] = []; + const value = (rows[j][i] = ObjectPrototypeHasOwnProperty.$call(column, j) ? column[j] : ""); + const width = columnWidths[i] || 0; + const counted = getStringWidth(value); + columnWidths[i] = Math.max(width, counted); + } + } + + const divider = ArrayPrototypeMap.$call(columnWidths, i => + StringPrototypeRepeat.$call(tableChars.middleMiddle, i + 2), + ); + + let result = + tableChars.topLeft + + ArrayPrototypeJoin.$call(divider, tableChars.topMiddle) + + tableChars.topRight + + "\n" + + renderRow(head, columnWidths) + + "\n" + + tableChars.leftMiddle + + ArrayPrototypeJoin.$call(divider, tableChars.rowMiddle) + + tableChars.rightMiddle + + "\n"; + + for (const row of rows) result += `${renderRow(row, columnWidths)}\n`; + + result += + tableChars.bottomLeft + ArrayPrototypeJoin.$call(divider, tableChars.bottomMiddle) + tableChars.bottomRight; + + return result; + }; + + // Track amount of indentation required via `console.group()`. + const kGroupIndent = Symbol("kGroupIndent"); + const kGroupIndentationWidth = Symbol("kGroupIndentWidth"); + const kFormatForStderr = Symbol("kFormatForStderr"); + const kFormatForStdout = Symbol("kFormatForStdout"); + const kGetInspectOptions = Symbol("kGetInspectOptions"); + const kColorMode = Symbol("kColorMode"); + const kIsConsole = Symbol("kIsConsole"); + const kWriteToConsole = Symbol("kWriteToConsole"); + const kBindProperties = Symbol("kBindProperties"); + const kBindStreamsEager = Symbol("kBindStreamsEager"); + const kBindStreamsLazy = Symbol("kBindStreamsLazy"); + const kUseStdout = Symbol("kUseStdout"); + const kUseStderr = Symbol("kUseStderr"); + + const optionsMap = new WeakMap<any, any>(); + function Console(this: any, options /* or: stdout, stderr, ignoreErrors = true */) { + // We have to test new.target here to see if this function is called + // with new, because we need to define a custom instanceof to accommodate + // the global console. + if (new.target === undefined) { + return Reflect.construct(Console, arguments); + } + + if (!options || typeof options.write === "function") { + options = { + stdout: options, + stderr: arguments[1], + ignoreErrors: arguments[2], + }; + } + + const { + stdout, + stderr = stdout, + ignoreErrors = true, + colorMode = "auto", + inspectOptions, + groupIndentation, + } = options; + + if (!stdout || typeof stdout.write !== "function") { + // throw new ERR_CONSOLE_WRITABLE_STREAM("stdout"); + throw new TypeError("stdout is not a writable stream"); + } + if (!stderr || typeof stderr.write !== "function") { + // throw new ERR_CONSOLE_WRITABLE_STREAM("stderr"); + throw new TypeError("stderr is not a writable stream"); + } + + if (typeof colorMode !== "boolean" && colorMode !== "auto") { + // throw new ERR_INVALID_ARG_VALUE("colorMode", colorMode); + throw new TypeError("colorMode must be a boolean or 'auto'"); + } + + if (groupIndentation !== undefined) { + // validateInteger(groupIndentation, "groupIndentation", 0, kMaxGroupIndentation); + } + + if (inspectOptions !== undefined) { + // validateObject(inspectOptions, "options.inspectOptions"); + + if (inspectOptions.colors !== undefined && options.colorMode !== undefined) { + // throw new ERR_INCOMPATIBLE_OPTION_PAIR("options.inspectOptions.color", "colorMode"); + } + optionsMap.set(this, inspectOptions); + } + + // Bind the prototype functions to this Console instance + Object.keys(Console.prototype).forEach(key => { + // We have to bind the methods grabbed from the instance instead of from + // the prototype so that users extending the Console can override them + // from the prototype chain of the subclass. + this[key] = this[key].bind(this); + Object.defineProperty(this[key], "name", { + value: key, + }); + }); + + this[kBindStreamsEager](stdout, stderr); + this[kBindProperties](ignoreErrors, colorMode, groupIndentation); + } + + const consolePropAttributes = { + writable: true, + enumerable: false, + configurable: true, + }; + + // Fixup global.console instanceof global.console.Console + Object.defineProperty(Console, Symbol.hasInstance, { + value(instance) { + return instance[kIsConsole] || instance === console; + }, + }); + + const kColorInspectOptions = { colors: true }; + const kNoColorInspectOptions = {}; + + Object.defineProperties((Console.prototype = {}), { + [kBindStreamsEager]: { + ...consolePropAttributes, + // Eager version for the Console constructor + value: function (stdout, stderr) { + Object.defineProperties(this, { + "_stdout": { ...consolePropAttributes, value: stdout }, + "_stderr": { ...consolePropAttributes, value: stderr }, + }); + }, + }, + [kBindStreamsLazy]: { + ...consolePropAttributes, + // Lazily load the stdout and stderr from an object so we don't + // create the stdio streams when they are not even accessed + value: function (object) { + let stdout; + let stderr; + Object.defineProperties(this, { + "_stdout": { + enumerable: false, + configurable: true, + get() { + if (!stdout) stdout = object.stdout; + return stdout; + }, + set(value) { + stdout = value; + }, + }, + "_stderr": { + enumerable: false, + configurable: true, + get() { + if (!stderr) { + stderr = object.stderr; + } + return stderr; + }, + set(value) { + stderr = value; + }, + }, + }); + }, + }, + [kBindProperties]: { + ...consolePropAttributes, + value: function (ignoreErrors, colorMode, groupIndentation = 2) { + Object.defineProperties(this, { + "_stdoutErrorHandler": { + ...consolePropAttributes, + value: createWriteErrorHandler(this, kUseStdout), + }, + "_stderrErrorHandler": { + ...consolePropAttributes, + value: createWriteErrorHandler(this, kUseStderr), + }, + "_ignoreErrors": { + ...consolePropAttributes, + value: Boolean(ignoreErrors), + }, + "_times": { ...consolePropAttributes, value: new Map() }, + // Corresponds to https://console.spec.whatwg.org/#count-map + [kCounts]: { ...consolePropAttributes, value: new Map() }, + [kColorMode]: { ...consolePropAttributes, value: colorMode }, + [kIsConsole]: { ...consolePropAttributes, value: true }, + [kGroupIndent]: { ...consolePropAttributes, value: "" }, + [kGroupIndentationWidth]: { + ...consolePropAttributes, + value: groupIndentation, + }, + [Symbol.toStringTag]: { + writable: false, + enumerable: false, + configurable: true, + value: "console", + }, + }); + }, + }, + [kWriteToConsole]: { + ...consolePropAttributes, + value: function (streamSymbol, string) { + const ignoreErrors = this._ignoreErrors; + const groupIndent = this[kGroupIndent]; + + const useStdout = streamSymbol === kUseStdout; + const stream = useStdout ? this._stdout : this._stderr; + const errorHandler = useStdout ? this._stdoutErrorHandler : this._stderrErrorHandler; + + if (groupIndent.length !== 0) { + if (StringPrototypeIncludes.call(string, "\n")) { + // ?! + string = (RegExpPrototypeSymbolReplace.$call as any)(/\n/g, string, `\n${groupIndent}`); + } + string = groupIndent + string; + } + string += "\n"; + + if (ignoreErrors === false) return stream.write(string); + + // There may be an error occurring synchronously (e.g. for files or TTYs + // on POSIX systems) or asynchronously (e.g. pipes on POSIX systems), so + // handle both situations. + try { + // Add and later remove a noop error handler to catch synchronous + // errors. + if (stream.listenerCount("error") === 0) stream.once("error", noop); + + stream.write(string, errorHandler); + } catch (e) { + // Console is a debugging utility, so it swallowing errors is not + // desirable even in edge cases such as low stack space. + // if (isStackOverflowError(e)) throw e; + // Sorry, there's no proper way to pass along the error here. + } finally { + stream.removeListener("error", noop); + } + }, + }, + [kGetInspectOptions]: { + ...consolePropAttributes, + value: function (stream) { + let color = this[kColorMode]; + if (color === "auto") { + if (process.env.FORCE_COLOR !== undefined) { + color = Bun.enableANSIColors; + } else { + color = stream.isTTY && (typeof stream.getColorDepth === "function" ? stream.getColorDepth() > 2 : true); + } + } + + const options = optionsMap.get(this); + if (options) { + if (options.colors === undefined) { + options.colors = color; + } + return options; + } + + return color ? kColorInspectOptions : kNoColorInspectOptions; + }, + }, + [kFormatForStdout]: { + ...consolePropAttributes, + value: function (args) { + const opts = this[kGetInspectOptions](this._stdout); + return formatWithOptions(opts, ...args); + }, + }, + [kFormatForStderr]: { + ...consolePropAttributes, + value: function (args) { + const opts = this[kGetInspectOptions](this._stderr); + return formatWithOptions(opts, ...args); + }, + }, + }); + + // Make a function that can serve as the callback passed to `stream.write()`. + function createWriteErrorHandler(instance, streamSymbol) { + return err => { + // This conditional evaluates to true if and only if there was an error + // that was not already emitted (which happens when the _write callback + // is invoked asynchronously). + const stream = streamSymbol === kUseStdout ? instance._stdout : instance._stderr; + if (err !== null && !stream._writableState.errorEmitted) { + // If there was an error, it will be emitted on `stream` as + // an `error` event. Adding a `once` listener will keep that error + // from becoming an uncaught exception, but since the handler is + // removed after the event, non-console.* writes won't be affected. + // we are only adding noop if there is no one else listening for 'error' + if (stream.listenerCount("error") === 0) { + stream.once("error", noop); + } + } + }; + } + + const consoleMethods: any = { + log(...args) { + this[kWriteToConsole](kUseStdout, this[kFormatForStdout](args)); + }, + + warn(...args) { + this[kWriteToConsole](kUseStderr, this[kFormatForStderr](args)); + }, + + dir(object, options) { + this[kWriteToConsole]( + kUseStdout, + inspect(object, { + customInspect: false, + ...this[kGetInspectOptions](this._stdout), + ...options, + }), + ); + }, + + time(label = "default") { + // Coerces everything other than Symbol to a string + label = `${label}`; + if (this._times.has(label)) { + process.emitWarning(`Label '${label}' already exists for console.time()`); + return; + } + // trace(kTraceBegin, kTraceConsoleCategory, `time::${label}`, 0); + this._times.set(label, process.hrtime()); + }, + + timeEnd(label = "default") { + // Coerces everything other than Symbol to a string + label = `${label}`; + const found = timeLogImpl(this, "timeEnd", label); + // trace(kTraceEnd, kTraceConsoleCategory, `time::${label}`, 0); + if (found) { + this._times.delete(label); + } + }, + + timeLog(label = "default", ...data) { + // Coerces everything other than Symbol to a string + label = `${label}`; + timeLogImpl(this, "timeLog", label, data); + // trace(kTraceInstant, kTraceConsoleCategory, `time::${label}`, 0); + }, + + trace: function trace(...args) { + const err: Error = { + name: "Trace", + message: this[kFormatForStderr](args), + }; + Error.captureStackTrace(err, trace); + this.error(err.stack); + }, + + assert(expression, ...args) { + if (!expression) { + args[0] = `Assertion failed${args.length === 0 ? "" : `: ${args[0]}`}`; + // The arguments will be formatted in warn() again + Reflect.apply(this.warn, this, args); + } + }, + + // Defined by: https://console.spec.whatwg.org/#clear + clear() { + // It only makes sense to clear if _stdout is a TTY. + // Otherwise, do nothing. + if (this._stdout.isTTY && process.env.TERM !== "dumb") { + this._stdout.write("\x1b[2J"); + this._stdout.write("\x1b[0f"); + } + }, + + // Defined by: https://console.spec.whatwg.org/#count + count(label = "default") { + // Ensures that label is a string, and only things that can be + // coerced to strings. e.g. Symbol is not allowed + label = `${label}`; + const counts = this[kCounts]; + let count = counts.get(label); + if (count === undefined) count = 1; + else count++; + counts.set(label, count); + // trace(kTraceCount, kTraceConsoleCategory, `count::${label}`, 0, count); + this.log(`${label}: ${count}`); + }, + + // Defined by: https://console.spec.whatwg.org/#countreset + countReset(label = "default") { + const counts = this[kCounts]; + if (!counts.has(label)) { + process.emitWarning(`Count for '${label}' does not exist`); + return; + } + // trace(kTraceCount, kTraceConsoleCategory, `count::${label}`, 0, 0); + counts.delete(`${label}`); + }, + + group(...data) { + if (data.length > 0) { + Reflect.apply(this.log, this, data); + } + this[kGroupIndent] += StringPrototypeRepeat.$call(" ", this[kGroupIndentationWidth]); + }, + + groupEnd() { + this[kGroupIndent] = StringPrototypeSlice.$call( + this[kGroupIndent], + 0, + this[kGroupIndent].length - this[kGroupIndentationWidth], + ); + }, + + // https://console.spec.whatwg.org/#table + table(tabularData, properties) { + if (properties !== undefined) { + // validateArray(properties, "properties"); + } + + if (tabularData === null || typeof tabularData !== "object") return this.log(tabularData); + const final = (k, v) => this.log(table(k, v)); + + const _inspect = v => { + const depth = v !== null && typeof v === "object" && !isArray(v) && Object.keys(v).length > 2 ? -1 : 0; + const opt = { + depth, + maxArrayLength: 3, + breakLength: Infinity, + ...this[kGetInspectOptions](this._stdout), + }; + return inspect(v, opt); + }; + const getIndexArray = length => Array.from({ length }, (_, i) => _inspect(i)); + + const mapIter = $isMapIterator(tabularData); + let isKeyValue = false; + let i = 0; + // if (mapIter) { + // const res = previewEntries(tabularData, true); + // tabularData = res[0]; + // isKeyValue = res[1]; + // } + + if (isKeyValue || $isMap(tabularData)) { + const keys = []; + const values = []; + let length = 0; + if (mapIter) { + for (; i < tabularData.length / 2; ++i) { + ArrayPrototypePush.$call(keys, _inspect(tabularData[i * 2])); + ArrayPrototypePush.$call(values, _inspect(tabularData[i * 2 + 1])); + length++; + } + } else { + for (const { 0: k, 1: v } of tabularData) { + ArrayPrototypePush.$call(keys, _inspect(k)); + ArrayPrototypePush.$call(values, _inspect(v)); + length++; + } + } + return final([iterKey, keyKey, valuesKey], [getIndexArray(length), keys, values]); + } + + const setIter = $isSetIterator(tabularData); + // if (setIter) tabularData = previewEntries(tabularData); + + const setlike = setIter || mapIter || $isSet(tabularData); + if (setlike) { + const values = []; + let length = 0; + for (const v of tabularData as Set<any>) { + ArrayPrototypePush.$call(values, _inspect(v)); + length++; + } + return final([iterKey, valuesKey], [getIndexArray(length), values]); + } + + const map = { __proto__: null }; + let hasPrimitives = false; + const valuesKeyArray: any = []; + const indexKeyArray = Object.keys(tabularData); + + for (; i < indexKeyArray.length; i++) { + const item = tabularData[indexKeyArray[i]]; + const primitive = item === null || (typeof item !== "function" && typeof item !== "object"); + if (properties === undefined && primitive) { + hasPrimitives = true; + valuesKeyArray[i] = _inspect(item); + } else { + const keys = properties || Object.keys(item); + for (const key of keys) { + map[key] ??= []; + if ((primitive && properties) || !ObjectPrototypeHasOwnProperty.$call(item, key)) map[key][i] = ""; + else map[key][i] = _inspect(item[key]); + } + } + } + + const keys = Object.keys(map); + const values = Object.values(map); + if (hasPrimitives) { + ArrayPrototypePush.$call(keys, valuesKey); + ArrayPrototypePush.$call(values, valuesKeyArray); + } + ArrayPrototypeUnshift.$call(keys, indexKey); + ArrayPrototypeUnshift.$call(values, indexKeyArray); + + return final(keys, values); + }, + }; + + // Returns true if label was found + function timeLogImpl(self, name, label, data?) { + const time = self._times.get(label); + if (time === undefined) { + process.emitWarning(`No such label '${label}' for console.${name}()`); + return false; + } + const duration = process.hrtime(time); + const ms = duration[0] * 1000 + duration[1] / 1e6; + + const formatted = formatTime(ms); + + if (data === undefined) { + self.log("%s: %s", label, formatted); + } else { + self.log("%s: %s", label, formatted, ...data); + } + return true; + } + + function pad(value) { + return StringPrototypePadStart.$call(`${value}`, 2, "0"); + } + + function formatTime(ms) { + let hours = 0; + let minutes = 0; + let seconds: string | number = 0; + + if (ms >= kSecond) { + if (ms >= kMinute) { + if (ms >= kHour) { + hours = Math.floor(ms / kHour); + ms = ms % kHour; + } + minutes = Math.floor(ms / kMinute); + ms = ms % kMinute; + } + seconds = ms / kSecond; + } + + if (hours !== 0 || minutes !== 0) { + ({ 0: seconds, 1: ms } = (StringPrototypeSplit.$call as any)(NumberPrototypeToFixed.$call(seconds, 3), ".")); + const res = hours !== 0 ? `${hours}:${pad(minutes)}` : minutes; + return `${res}:${pad(seconds)}.${ms} (${hours !== 0 ? "h:m" : ""}m:ss.mmm)`; + } + + if (seconds !== 0) { + return `${NumberPrototypeToFixed.$call(seconds, 3)}s`; + } + + return `${Number(NumberPrototypeToFixed.$call(ms, 3))}ms`; + } + + const keyKey = "Key"; + const valuesKey = "Values"; + const indexKey = "(index)"; + const iterKey = "(iteration index)"; + + const isArray = v => $isJSArray(v) || $isTypedArrayView(v) || isBuffer(v); + + function noop() {} + + for (const method of Reflect.ownKeys(consoleMethods)) Console.prototype[method] = consoleMethods[method]; + + Console.prototype.debug = Console.prototype.log; + Console.prototype.info = Console.prototype.log; + Console.prototype.dirxml = Console.prototype.log; + Console.prototype.error = Console.prototype.warn; + Console.prototype.groupCollapsed = Console.prototype.group; + + return Console; +} diff --git a/src/js/node/util.js b/src/js/node/util.js index 10dc95e2e..b19dce6fe 100644 --- a/src/js/node/util.js +++ b/src/js/node/util.js @@ -27,7 +27,7 @@ var formatRegExp = /%[sdjfoc%]/g; function formatWithOptions(inspectOptions, f) { if (!isString(f)) { var objects = []; - for (var i = 0; i < arguments.length; i++) { + for (var i = 1; i < arguments.length; i++) { objects.push(inspect(arguments[i], inspectOptions)); } return objects.join(" "); diff --git a/src/js/out/InternalModuleRegistryConstants.h b/src/js/out/InternalModuleRegistryConstants.h index 906f690a7..3c22b684d 100644 --- a/src/js/out/InternalModuleRegistryConstants.h +++ b/src/js/out/InternalModuleRegistryConstants.h @@ -190,7 +190,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 const style = inspect.styles[styleType];\n if (style !== @undefined) {\n const color = inspect.colors[style];\n if (color !== @undefined)\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(\"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; +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 = 1;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 !== @undefined) {\n const color = inspect.colors[style];\n if (color !== @undefined)\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(\"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; // // @@ -431,7 +431,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 const style = inspect.styles[styleType];\n if (style !== @undefined) {\n const color = inspect.colors[style];\n if (color !== @undefined)\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(\"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; +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 = 1;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 !== @undefined) {\n const color = inspect.colors[style];\n if (color !== @undefined)\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(\"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; // // @@ -673,7 +673,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 const style = inspect.styles[styleType];\n if (style !== @undefined) {\n const color = inspect.colors[style];\n if (color !== @undefined)\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(\"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; +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 = 1;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 !== @undefined) {\n const color = inspect.colors[style];\n if (color !== @undefined)\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(\"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 cc537687a..d161cd315 100644 --- a/src/js/out/WebCoreJSBuiltins.cpp +++ b/src/js/out/WebCoreJSBuiltins.cpp @@ -1382,6 +1382,14 @@ const int s_consoleObjectWriteCodeLength = 467; static const JSC::Intrinsic s_consoleObjectWriteCodeIntrinsic = JSC::NoIntrinsic; const char* const s_consoleObjectWriteCode = "(function (input) {\"use strict\";\n var writer = @getByIdDirectPrivate(this, \"writer\");\n if (!writer) {\n var length = @toLength(input\?.length \?\? 0);\n writer = Bun.stdout.writer({ highWaterMark: length > 65536 \? length : 65536 }), @putByIdDirectPrivate(this, \"writer\", writer);\n }\n var wrote = writer.write(input);\n const count = @argumentCount();\n for (var i = 1;i < count; i++)\n wrote += writer.write(@argument(i));\n return writer.flush(!0), wrote;\n})\n"; +// createConsoleConstructor +const JSC::ConstructAbility s_consoleObjectCreateConsoleConstructorCodeConstructAbility = JSC::ConstructAbility::CannotConstruct; +const JSC::ConstructorKind s_consoleObjectCreateConsoleConstructorCodeConstructorKind = JSC::ConstructorKind::None; +const JSC::ImplementationVisibility s_consoleObjectCreateConsoleConstructorCodeImplementationVisibility = JSC::ImplementationVisibility::Public; +const int s_consoleObjectCreateConsoleConstructorCodeLength = 18565; +static const JSC::Intrinsic s_consoleObjectCreateConsoleConstructorCodeIntrinsic = JSC::NoIntrinsic; +const char* const s_consoleObjectCreateConsoleConstructorCode = "(function (console) {\"use strict\";\n const { inspect, formatWithOptions } = @getInternalField(@internalModuleRegistry, 46) || @createInternalModuleById(46), { isBuffer } = @requireNativeModule(\"buffer\"), StringPrototypeIncludes = @String.prototype.includes, RegExpPrototypeSymbolReplace = @RegExp.prototype[Symbol.replace], ArrayPrototypeUnshift = @Array.prototype.unshift, StringPrototypeRepeat = @String.prototype.repeat, StringPrototypeSlice = @String.prototype.slice, ObjectPrototypeHasOwnProperty = Object.prototype.hasOwnProperty, StringPrototypePadStart = @String.prototype.padStart, StringPrototypeSplit = @String.prototype.split, NumberPrototypeToFixed = Number.prototype.toFixed, StringPrototypeNormalize = @String.prototype.normalize, StringPrototypeCodePointAt = @String.prototype.codePointAt, ArrayPrototypeMap = @Array.prototype.map, ArrayPrototypeJoin = @Array.prototype.join, ArrayPrototypePush = @Array.prototype.push, kCounts = Symbol(\"counts\");\n var ansiPattern = \"[\\\\u001B\\\\u009B][[\\\\]()#;\?]*(\?:(\?:(\?:(\?:;[-a-zA-Z\\\\d\\\\/#&.:=\?%@~_]+)*|[a-zA-Z\\\\d]+(\?:;[-a-zA-Z\\\\d\\\\/#&.:=\?%@~_]*)*)\?\\\\u0007)|(\?:(\?:\\\\d{1,4}(\?:;\\\\d{0,4})*)\?[\\\\dA-PR-TZcf-ntqry=><~]))\", ansi = new @RegExp(ansiPattern, \"g\"), isFullWidthCodePoint = (code) => {\n return code >= 4352 && (code <= 4447 || code === 9001 || code === 9002 || code >= 11904 && code <= 12871 && code !== 12351 || code >= 12880 && code <= 19903 || code >= 19968 && code <= 42182 || code >= 43360 && code <= 43388 || code >= 44032 && code <= 55203 || code >= 63744 && code <= 64255 || code >= 65040 && code <= 65049 || code >= 65072 && code <= 65131 || code >= 65281 && code <= 65376 || code >= 65504 && code <= 65510 || code >= 110592 && code <= 110593 || code >= 127488 && code <= 127569 || code >= 127744 && code <= 128591 || code >= 131072 && code <= 262141);\n }, isZeroWidthCodePoint = (code) => {\n return code <= 31 || code >= 127 && code <= 159 || code >= 768 && code <= 879 || code >= 8203 && code <= 8207 || code >= 8400 && code <= 8447 || code >= 65024 && code <= 65039 || code >= 65056 && code <= 65071 || code >= 917760 && code <= 917999;\n };\n function stripVTControlCharacters(str) {\n return RegExpPrototypeSymbolReplace.@call(ansi, str, \"\");\n }\n var getStringWidth = function getStringWidth(str, removeControlChars = !0) {\n var width = 0;\n if (removeControlChars)\n str = stripVTControlCharacters(str);\n str = StringPrototypeNormalize.@call(str, \"NFC\");\n for (var char of str) {\n var code = StringPrototypeCodePointAt.@call(char, 0);\n if (isFullWidthCodePoint(code))\n width += 2;\n else if (!isZeroWidthCodePoint(code))\n width++;\n }\n return width;\n };\n const tableChars = {\n middleMiddle: \"\\u2500\",\n rowMiddle: \"\\u253C\",\n topRight: \"\\u2510\",\n topLeft: \"\\u250C\",\n leftMiddle: \"\\u251C\",\n topMiddle: \"\\u252C\",\n bottomRight: \"\\u2518\",\n bottomLeft: \"\\u2514\",\n bottomMiddle: \"\\u2534\",\n rightMiddle: \"\\u2524\",\n left: \"\\u2502 \",\n right: \" \\u2502\",\n middle: \" \\u2502 \"\n }, renderRow = (row, columnWidths) => {\n let out = tableChars.left;\n for (let i = 0;i < row.length; i++) {\n const cell = row[i], len = getStringWidth(cell), needed = (columnWidths[i] - len) / 2;\n if (out += StringPrototypeRepeat.@call(\" \", needed) + cell + StringPrototypeRepeat.@call(\" \", Math.ceil(needed)), i !== row.length - 1)\n out += tableChars.middle;\n }\n return out += tableChars.right, out;\n }, table = (head, columns) => {\n const columnWidths = ArrayPrototypeMap.call(head, (h) => getStringWidth(h)), longestColumn = Math.max(...ArrayPrototypeMap.@call(columns, (a) => a.length)), rows = @newArrayWithSize(longestColumn);\n for (let i = 0;i < head.length; i++) {\n const column = columns[i];\n for (let j = 0;j < longestColumn; j++) {\n if (rows[j] === @undefined)\n rows[j] = [];\n const value = rows[j][i] = ObjectPrototypeHasOwnProperty.@call(column, j) \? column[j] : \"\", width = columnWidths[i] || 0, counted = getStringWidth(value);\n columnWidths[i] = Math.max(width, counted);\n }\n }\n const divider = ArrayPrototypeMap.@call(columnWidths, (i) => StringPrototypeRepeat.@call(tableChars.middleMiddle, i + 2));\n let result = tableChars.topLeft + ArrayPrototypeJoin.@call(divider, tableChars.topMiddle) + tableChars.topRight + \"\\n\" + renderRow(head, columnWidths) + \"\\n\" + tableChars.leftMiddle + ArrayPrototypeJoin.@call(divider, tableChars.rowMiddle) + tableChars.rightMiddle + \"\\n\";\n for (let row of rows)\n result += `${renderRow(row, columnWidths)}\\n`;\n return result += tableChars.bottomLeft + ArrayPrototypeJoin.@call(divider, tableChars.bottomMiddle) + tableChars.bottomRight, result;\n }, kGroupIndent = Symbol(\"kGroupIndent\"), kGroupIndentationWidth = Symbol(\"kGroupIndentWidth\"), kFormatForStderr = Symbol(\"kFormatForStderr\"), kFormatForStdout = Symbol(\"kFormatForStdout\"), kGetInspectOptions = Symbol(\"kGetInspectOptions\"), kColorMode = Symbol(\"kColorMode\"), kIsConsole = Symbol(\"kIsConsole\"), kWriteToConsole = Symbol(\"kWriteToConsole\"), kBindProperties = Symbol(\"kBindProperties\"), kBindStreamsEager = Symbol(\"kBindStreamsEager\"), kBindStreamsLazy = Symbol(\"kBindStreamsLazy\"), kUseStdout = Symbol(\"kUseStdout\"), kUseStderr = Symbol(\"kUseStderr\"), optionsMap = new WeakMap;\n function Console(options) {\n if (new.target === @undefined)\n return Reflect.construct(Console, arguments);\n if (!options || typeof options.write === \"function\")\n options = {\n stdout: options,\n stderr: arguments[1],\n ignoreErrors: arguments[2]\n };\n const {\n stdout,\n stderr = stdout,\n ignoreErrors = !0,\n colorMode = \"auto\",\n inspectOptions,\n groupIndentation\n } = options;\n if (!stdout || typeof stdout.write !== \"function\")\n @throwTypeError(\"stdout is not a writable stream\");\n if (!stderr || typeof stderr.write !== \"function\")\n @throwTypeError(\"stderr is not a writable stream\");\n if (typeof colorMode !== \"boolean\" && colorMode !== \"auto\")\n @throwTypeError(\"colorMode must be a boolean or 'auto'\");\n if (inspectOptions !== @undefined) {\n if (inspectOptions.colors !== @undefined && options.colorMode !== @undefined)\n ;\n optionsMap.set(this, inspectOptions);\n }\n Object.keys(Console.prototype).forEach((key) => {\n this[key] = this[key].bind(this), Object.defineProperty(this[key], \"name\", {\n value: key\n });\n }), this[kBindStreamsEager](stdout, stderr), this[kBindProperties](ignoreErrors, colorMode, groupIndentation);\n }\n const consolePropAttributes = {\n writable: !0,\n enumerable: !1,\n configurable: !0\n };\n Object.defineProperty(Console, Symbol.hasInstance, {\n value(instance) {\n return instance[kIsConsole] || instance === console;\n }\n });\n const kColorInspectOptions = { colors: !0 }, kNoColorInspectOptions = {};\n Object.defineProperties(Console.prototype = {}, {\n [kBindStreamsEager]: {\n ...consolePropAttributes,\n value: function(stdout, stderr) {\n Object.defineProperties(this, {\n _stdout: { ...consolePropAttributes, value: stdout },\n _stderr: { ...consolePropAttributes, value: stderr }\n });\n }\n },\n [kBindStreamsLazy]: {\n ...consolePropAttributes,\n value: function(object) {\n let stdout, stderr;\n Object.defineProperties(this, {\n _stdout: {\n enumerable: !1,\n configurable: !0,\n get() {\n if (!stdout)\n stdout = object.stdout;\n return stdout;\n },\n set(value) {\n stdout = value;\n }\n },\n _stderr: {\n enumerable: !1,\n configurable: !0,\n get() {\n if (!stderr)\n stderr = object.stderr;\n return stderr;\n },\n set(value) {\n stderr = value;\n }\n }\n });\n }\n },\n [kBindProperties]: {\n ...consolePropAttributes,\n value: function(ignoreErrors, colorMode, groupIndentation = 2) {\n Object.defineProperties(this, {\n _stdoutErrorHandler: {\n ...consolePropAttributes,\n value: createWriteErrorHandler(this, kUseStdout)\n },\n _stderrErrorHandler: {\n ...consolePropAttributes,\n value: createWriteErrorHandler(this, kUseStderr)\n },\n _ignoreErrors: {\n ...consolePropAttributes,\n value: Boolean(ignoreErrors)\n },\n _times: { ...consolePropAttributes, value: new Map },\n [kCounts]: { ...consolePropAttributes, value: new Map },\n [kColorMode]: { ...consolePropAttributes, value: colorMode },\n [kIsConsole]: { ...consolePropAttributes, value: !0 },\n [kGroupIndent]: { ...consolePropAttributes, value: \"\" },\n [kGroupIndentationWidth]: {\n ...consolePropAttributes,\n value: groupIndentation\n },\n [Symbol.toStringTag]: {\n writable: !1,\n enumerable: !1,\n configurable: !0,\n value: \"console\"\n }\n });\n }\n },\n [kWriteToConsole]: {\n ...consolePropAttributes,\n value: function(streamSymbol, string) {\n const ignoreErrors = this._ignoreErrors, groupIndent = this[kGroupIndent], useStdout = streamSymbol === kUseStdout, stream = useStdout \? this._stdout : this._stderr, errorHandler = useStdout \? this._stdoutErrorHandler : this._stderrErrorHandler;\n if (groupIndent.length !== 0) {\n if (StringPrototypeIncludes.call(string, \"\\n\"))\n string = RegExpPrototypeSymbolReplace.@call(/\\n/g, string, `\\n${groupIndent}`);\n string = groupIndent + string;\n }\n if (string += \"\\n\", ignoreErrors === !1)\n return stream.write(string);\n try {\n if (stream.listenerCount(\"error\") === 0)\n stream.once(\"error\", noop);\n stream.write(string, errorHandler);\n } catch (e) {\n } finally {\n stream.removeListener(\"error\", noop);\n }\n }\n },\n [kGetInspectOptions]: {\n ...consolePropAttributes,\n value: function(stream) {\n let color = this[kColorMode];\n if (color === \"auto\")\n if (process.env.FORCE_COLOR !== @undefined)\n color = Bun.enableANSIColors;\n else\n color = stream.isTTY && (typeof stream.getColorDepth === \"function\" \? stream.getColorDepth() > 2 : !0);\n const options = optionsMap.get(this);\n if (options) {\n if (options.colors === @undefined)\n options.colors = color;\n return options;\n }\n return color \? kColorInspectOptions : kNoColorInspectOptions;\n }\n },\n [kFormatForStdout]: {\n ...consolePropAttributes,\n value: function(args) {\n const opts = this[kGetInspectOptions](this._stdout);\n return formatWithOptions(opts, ...args);\n }\n },\n [kFormatForStderr]: {\n ...consolePropAttributes,\n value: function(args) {\n const opts = this[kGetInspectOptions](this._stderr);\n return formatWithOptions(opts, ...args);\n }\n }\n });\n function createWriteErrorHandler(instance, streamSymbol) {\n return (err) => {\n const stream = streamSymbol === kUseStdout \? instance._stdout : instance._stderr;\n if (err !== null && !stream._writableState.errorEmitted) {\n if (stream.listenerCount(\"error\") === 0)\n stream.once(\"error\", noop);\n }\n };\n }\n const consoleMethods = {\n log(...args) {\n this[kWriteToConsole](kUseStdout, this[kFormatForStdout](args));\n },\n warn(...args) {\n this[kWriteToConsole](kUseStderr, this[kFormatForStderr](args));\n },\n dir(object, options) {\n this[kWriteToConsole](kUseStdout, inspect(object, {\n customInspect: !1,\n ...this[kGetInspectOptions](this._stdout),\n ...options\n }));\n },\n time(label = \"default\") {\n if (label = `${label}`, this._times.has(label)) {\n process.emitWarning(`Label '${label}' already exists for console.time()`);\n return;\n }\n this._times.set(label, process.hrtime());\n },\n timeEnd(label = \"default\") {\n if (label = `${label}`, timeLogImpl(this, \"timeEnd\", label))\n this._times.delete(label);\n },\n timeLog(label = \"default\", ...data) {\n label = `${label}`, timeLogImpl(this, \"timeLog\", label, data);\n },\n trace: function trace(...args) {\n const err = {\n name: \"Trace\",\n message: this[kFormatForStderr](args)\n };\n Error.captureStackTrace(err, trace), this.error(err.stack);\n },\n assert(expression, ...args) {\n if (!expression)\n args[0] = `Assertion failed${args.length === 0 \? \"\" : `: ${args[0]}`}`, Reflect.apply(this.warn, this, args);\n },\n clear() {\n if (this._stdout.isTTY && process.env.TERM !== \"dumb\")\n this._stdout.write(\"\\x1B[2J\"), this._stdout.write(\"\\x1B[0f\");\n },\n count(label = \"default\") {\n label = `${label}`;\n const counts = this[kCounts];\n let count = counts.get(label);\n if (count === @undefined)\n count = 1;\n else\n count++;\n counts.set(label, count), this.log(`${label}: ${count}`);\n },\n countReset(label = \"default\") {\n const counts = this[kCounts];\n if (!counts.has(label)) {\n process.emitWarning(`Count for '${label}' does not exist`);\n return;\n }\n counts.delete(`${label}`);\n },\n group(...data) {\n if (data.length > 0)\n Reflect.apply(this.log, this, data);\n this[kGroupIndent] += StringPrototypeRepeat.@call(\" \", this[kGroupIndentationWidth]);\n },\n groupEnd() {\n this[kGroupIndent] = StringPrototypeSlice.@call(this[kGroupIndent], 0, this[kGroupIndent].length - this[kGroupIndentationWidth]);\n },\n table(tabularData, properties) {\n if (tabularData === null || typeof tabularData !== \"object\")\n return this.log(tabularData);\n const final = (k, v) => this.log(table(k, v)), _inspect = (v) => {\n const opt = {\n depth: v !== null && typeof v === \"object\" && !isArray(v) && Object.keys(v).length > 2 \? -1 : 0,\n maxArrayLength: 3,\n breakLength: @Infinity,\n ...this[kGetInspectOptions](this._stdout)\n };\n return inspect(v, opt);\n }, getIndexArray = (length) => @Array.from({ length }, (_, i2) => _inspect(i2)), mapIter = @isMapIterator(tabularData);\n let isKeyValue = !1, i = 0;\n if (isKeyValue || @isMap(tabularData)) {\n const keys2 = [], values2 = [];\n let length = 0;\n if (mapIter)\n for (;i < tabularData.length / 2; ++i)\n ArrayPrototypePush.@call(keys2, _inspect(tabularData[i * 2])), ArrayPrototypePush.@call(values2, _inspect(tabularData[i * 2 + 1])), length++;\n else\n for (let { 0: k, 1: v } of tabularData)\n ArrayPrototypePush.@call(keys2, _inspect(k)), ArrayPrototypePush.@call(values2, _inspect(v)), length++;\n return final([iterKey, keyKey, valuesKey], [getIndexArray(length), keys2, values2]);\n }\n if (@isSetIterator(tabularData) || mapIter || @isSet(tabularData)) {\n const values2 = [];\n let length = 0;\n for (let v of tabularData)\n ArrayPrototypePush.@call(values2, _inspect(v)), length++;\n return final([iterKey, valuesKey], [getIndexArray(length), values2]);\n }\n const map = { __proto__: null };\n let hasPrimitives = !1;\n const valuesKeyArray = [], indexKeyArray = Object.keys(tabularData);\n for (;i < indexKeyArray.length; i++) {\n const item = tabularData[indexKeyArray[i]], primitive = item === null || typeof item !== \"function\" && typeof item !== \"object\";\n if (properties === @undefined && primitive)\n hasPrimitives = !0, valuesKeyArray[i] = _inspect(item);\n else {\n const keys2 = properties || Object.keys(item);\n for (let key of keys2)\n if (map[key] \?\?= [], primitive && properties || !ObjectPrototypeHasOwnProperty.@call(item, key))\n map[key][i] = \"\";\n else\n map[key][i] = _inspect(item[key]);\n }\n }\n const keys = Object.keys(map), values = Object.values(map);\n if (hasPrimitives)\n ArrayPrototypePush.@call(keys, valuesKey), ArrayPrototypePush.@call(values, valuesKeyArray);\n return ArrayPrototypeUnshift.@call(keys, indexKey), ArrayPrototypeUnshift.@call(values, indexKeyArray), final(keys, values);\n }\n };\n function timeLogImpl(self, name, label, data) {\n const time = self._times.get(label);\n if (time === @undefined)\n return process.emitWarning(`No such label '${label}' for console.${name}()`), !1;\n const duration = process.hrtime(time), ms = duration[0] * 1000 + duration[1] / 1e6, formatted = formatTime(ms);\n if (data === @undefined)\n self.log(\"%s: %s\", label, formatted);\n else\n self.log(\"%s: %s\", label, formatted, ...data);\n return !0;\n }\n function pad(value) {\n return StringPrototypePadStart.@call(`${value}`, 2, \"0\");\n }\n function formatTime(ms) {\n let hours = 0, minutes = 0, seconds = 0;\n if (ms >= 1000) {\n if (ms >= 60000) {\n if (ms >= 3600000)\n hours = Math.floor(ms / 3600000), ms = ms % 3600000;\n minutes = Math.floor(ms / 60000), ms = ms % 60000;\n }\n seconds = ms / 1000;\n }\n if (hours !== 0 || minutes !== 0)\n return { 0: seconds, 1: ms } = StringPrototypeSplit.@call(NumberPrototypeToFixed.@call(seconds, 3), \".\"), `${hours !== 0 \? `${hours}:${pad(minutes)}` : minutes}:${pad(seconds)}.${ms} (${hours !== 0 \? \"h:m\" : \"\"}m:ss.mmm)`;\n if (seconds !== 0)\n return `${NumberPrototypeToFixed.@call(seconds, 3)}s`;\n return `${Number(NumberPrototypeToFixed.@call(ms, 3))}ms`;\n }\n const keyKey = \"Key\", valuesKey = \"Values\", indexKey = \"(index)\", iterKey = \"(iteration index)\", isArray = (v) => @isJSArray(v) || @isTypedArrayView(v) || isBuffer(v);\n function noop() {\n }\n for (let method of Reflect.ownKeys(consoleMethods))\n Console.prototype[method] = consoleMethods[method];\n return Console.prototype.debug = Console.prototype.log, Console.prototype.info = Console.prototype.log, Console.prototype.dirxml = Console.prototype.log, Console.prototype.error = Console.prototype.warn, Console.prototype.groupCollapsed = Console.prototype.group, Console;\n})\n"; + #define DEFINE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \ JSC::FunctionExecutable* codeName##Generator(JSC::VM& vm) \ {\ diff --git a/src/js/out/WebCoreJSBuiltins.h b/src/js/out/WebCoreJSBuiltins.h index dcfdbd1ef..08945eff1 100644 --- a/src/js/out/WebCoreJSBuiltins.h +++ b/src/js/out/WebCoreJSBuiltins.h @@ -2497,17 +2497,28 @@ extern const JSC::ConstructAbility s_consoleObjectWriteCodeConstructAbility; extern const JSC::ConstructorKind s_consoleObjectWriteCodeConstructorKind; extern const JSC::ImplementationVisibility s_consoleObjectWriteCodeImplementationVisibility; +// createConsoleConstructor +#define WEBCORE_BUILTIN_CONSOLEOBJECT_CREATECONSOLECONSTRUCTOR 1 +extern const char* const s_consoleObjectCreateConsoleConstructorCode; +extern const int s_consoleObjectCreateConsoleConstructorCodeLength; +extern const JSC::ConstructAbility s_consoleObjectCreateConsoleConstructorCodeConstructAbility; +extern const JSC::ConstructorKind s_consoleObjectCreateConsoleConstructorCodeConstructorKind; +extern const JSC::ImplementationVisibility s_consoleObjectCreateConsoleConstructorCodeImplementationVisibility; + #define WEBCORE_FOREACH_CONSOLEOBJECT_BUILTIN_DATA(macro) \ macro(asyncIterator, consoleObjectAsyncIterator, 0) \ macro(write, consoleObjectWrite, 1) \ + macro(createConsoleConstructor, consoleObjectCreateConsoleConstructor, 1) \ #define WEBCORE_FOREACH_CONSOLEOBJECT_BUILTIN_CODE(macro) \ macro(consoleObjectAsyncIteratorCode, asyncIterator, "[Symbol.asyncIterator]"_s, s_consoleObjectAsyncIteratorCodeLength) \ macro(consoleObjectWriteCode, write, ASCIILiteral(), s_consoleObjectWriteCodeLength) \ + macro(consoleObjectCreateConsoleConstructorCode, createConsoleConstructor, ASCIILiteral(), s_consoleObjectCreateConsoleConstructorCodeLength) \ #define WEBCORE_FOREACH_CONSOLEOBJECT_BUILTIN_FUNCTION_NAME(macro) \ macro(asyncIterator) \ macro(write) \ + macro(createConsoleConstructor) \ #define DECLARE_BUILTIN_GENERATOR(codeName, functionName, overriddenName, argumentCount) \ JSC::FunctionExecutable* codeName##Generator(JSC::VM&); diff --git a/test/js/node/console/console-constructor.test.ts b/test/js/node/console/console-constructor.test.ts new file mode 100644 index 000000000..2e2b29832 --- /dev/null +++ b/test/js/node/console/console-constructor.test.ts @@ -0,0 +1,66 @@ +import { test, describe, expect } from "bun:test"; +import { Console } from "node:console"; + +import { Writable } from "node:stream"; + +function writable() { + let intoString = ""; + const { promise, resolve } = Promise.withResolvers(); + const stream = new Writable({ + write(chunk) { + intoString += chunk.toString(); + }, + destroy() { + resolve(intoString); + }, + autoDestroy: true, + }); + + (stream as any).write = (chunk: any) => { + intoString += Buffer.from(chunk).toString("utf-8"); + }; + + return [stream, () => promise] as const; +} + +describe("console.Console", () => { + test("global instanceof Console", () => { + expect(global.console).toBeInstanceOf(Console); + }); + + test("new Console instanceof Console", () => { + const c = new Console({ stdout: process.stdout, stderr: process.stderr }); + expect(c).toBeInstanceOf(Console); + }); + + test("it can write to a stream", async () => { + console.log(); + const [stream, value] = writable(); + const c = new Console({ stdout: stream, stderr: stream, colorMode: false }); + c.log("hello"); + c.log({ foo: "bar" }); + stream.end(); + expect(await value()).toBe("hello\n{ foo: 'bar' }\n"); + }); + + test("can enable colors", async () => { + const [stream, value] = writable(); + const c = new Console({ stdout: stream, stderr: stream, colorMode: true }); + c.log("hello"); + c.log({ foo: "bar" }); + stream.end(); + expect(await value()).toBe("hello\n{ foo: \u001B[32m'bar'\u001B[39m }\n"); + }); + + test("stderr and stdout are separate", async () => { + const [out, outValue] = writable(); + const [err, errValue] = writable(); + const c = new Console({ stdout: out, stderr: err }); + c.log("hello world!"); + c.error("uh oh!"); + out.end(); + err.end(); + expect(await outValue()).toBe("hello world!\n"); + expect(await errValue()).toBe("uh oh!\n"); + }); +}); |