(function() {
const defineProperty = Object.defineProperty;
const callSiteDefaults = {
getThis() {},
getTypeName() {
return null;
},
getFunction() {},
getMethodName() {
return null;
},
getEvalOrigin() {},
isToplevel() {
return true;
},
isEval() {
return false;
},
isNative() {
return false;
},
isConstructor() {
return false;
},
isAsync() {
return false;
},
isPromiseAll() {
return false;
},
getPromiseIndex() {
return null;
},
getScriptNameOrSourceURL() {
return this.getFileName();
},
toString() {
let location = this.getFileName() ?? "<anonymous>";
const line = this.getLineNumber();
if (line !== null) location += `:${line}:${this.getColumnNumber()}`;
const name = this.getFunctionName();
return name === null ? location : `${name} (${location})`;
}
};
function completeCallSite(prototype) {
for (const [name, method] of Object.entries(callSiteDefaults)) if (!Object.hasOwn(prototype, name)) defineProperty(prototype, name, {
value: method,
writable: true,
configurable: true
});
}
var FrameCallSite = class {
#frame;
constructor(frame) {
this.#frame = frame;
}
getFunctionName() {
return this.#frame[0];
}
getFileName() {
return this.#frame[1] ?? void 0;
}
getLineNumber() {
return this.#frame[2];
}
getColumnNumber() {
return this.#frame[3];
}
isEval() {
return this.#frame[4];
}
};
completeCallSite(FrameCallSite.prototype);
function header(target) {
const { name, message } = target;
const named = name === void 0 ? "Error" : String(name);
const described = message === void 0 ? "" : String(message);
if (named === "") return described;
return described === "" ? named : `${named}: ${described}`;
}
function stackTraceLimit() {
const limit = Error.stackTraceLimit;
return typeof limit === "number" && limit > 0 ? Math.min(limit, 2 ** 32 - 1) : 0;
}
function installCaptureStackTrace(frames) {
let preparing = false;
defineProperty(Error, "captureStackTrace", {
value: function captureStackTrace(target, constructorOpt) {
if (typeof target !== "object" && typeof target !== "function" || target === null) throw new TypeError("Error.captureStackTrace requires an object");
const sites = frames(constructorOpt, stackTraceLimit()).map((frame) => new FrameCallSite(frame));
const prepare = Error.prepareStackTrace;
let stack;
if (typeof prepare === "function" && !preparing) {
preparing = true;
try {
stack = prepare(target, sites);
} finally {
preparing = false;
}
} else stack = [header(target), ...sites.map((site) => ` at ${site.toString()}`)].join("\n");
defineProperty(target, "stack", {
value: stack,
writable: true,
configurable: true
});
},
writable: true,
configurable: true
});
if (!Object.hasOwn(Error, "stackTraceLimit")) defineProperty(Error, "stackTraceLimit", {
value: 10,
writable: true,
enumerable: true,
configurable: true
});
}
function nativeCallSitePrototype() {
const hadPrepare = Object.hasOwn(Error, "prepareStackTrace");
const previous = Error.prepareStackTrace;
let site;
Error.prepareStackTrace = (_error, sites) => {
site = sites[0];
return "";
};
try {
const target = {};
Error.captureStackTrace?.(target);
target.stack;
} finally {
if (hadPrepare) Error.prepareStackTrace = previous;
else delete Error.prepareStackTrace;
}
return site === void 0 ? void 0 : Object.getPrototypeOf(site);
}
const frames = globalThis.__fetchletStackFrames;
delete globalThis.__fetchletStackFrames;
if (typeof Error.captureStackTrace !== "function") {
if (frames !== void 0) installCaptureStackTrace(frames);
} else {
const prototype = nativeCallSitePrototype();
if (prototype !== void 0) completeCallSite(prototype);
}
})();