"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_primordials_string = require('../primordials/string.js');
const require_objects_predicates = require('../objects/predicates.js');

//#region src/debug/caller-info.ts
/**
* @file `getCallerInfo` — extract the caller's function name from the V8 stack
*   trace at a given offset. Used by every output function to prefix the debug
*   line with the calling site. Strips V8-injected prefixes (`async`, `bound`,
*   `Object.`, etc.) so the printed name matches what the developer typed.
*/
/**
* Extract caller information from the stack trace.
*
* @private
*/
/*@__NO_SIDE_EFFECTS__*/
function getCallerInfo(stackOffset = 3) {
	let name = "";
	const captureStackTrace = Error.captureStackTrace;
	/* c8 ignore start */
	if (typeof captureStackTrace === "function") {
		const obj = {};
		captureStackTrace(obj, getCallerInfo);
		const stack = obj.stack;
		if (typeof stack === "string") {
			let lineCount = 0;
			let lineStart = 0;
			for (let i = 0, { length } = stack; i < length; i += 1) if (stack[i] === "\n") {
				lineCount += 1;
				if (lineCount < stackOffset) lineStart = i + 1;
				else {
					const line = stack.slice(lineStart, i).trimStart();
					const match = /(?<=^at\s+).*?(?=\s+\(|$)/.exec(line)?.[0];
					/* c8 ignore next - Defensive guard; real V8 stack frames
					always start with 'at '. */
					if (match) {
						name = match.replace(/^(?:async|bound|get|new|set)\s+/, "");
						if (require_primordials_string.StringPrototypeStartsWith(name, "Object.")) {
							const afterDot = require_primordials_string.StringPrototypeSlice(name, 7);
							if (!/* @__PURE__ */ require_objects_predicates.hasOwn(Object, afterDot)) name = afterDot;
						}
					}
					break;
				}
			}
		}
	}
	/* c8 ignore stop */
	return name;
}

//#endregion
exports.getCallerInfo = getCallerInfo;