"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_smol_detect = require('../smol/detect.js');

//#region src/primordials/uncurry.ts
/**
* @file `uncurryThis` and the cluster of helpers built atop it. Mirrors
*   Node.js's internal/per_context/primordials.js. Every other primordials leaf
*   depends on `uncurryThis` to expose prototype-method primordials, so this
*   file must be import-safe before any of them. Smol fast paths
*   (`node:smol-util`) replace the JS forms when running on socket-btm's smol
*   Node binary; stock Node and other runtimes fall back to the standard
*   `bind.bind(call)` shape. **IMPORTANT**: do not destructure on `globalThis`
*   or `Reflect` here. tsgo has a bug that mis-transpiles destructured exports.
*   See: https://github.com/SocketDev/socket-packageurl-js/issues/3.
*/
const _smolUtil = /* @__PURE__ */ require_smol_detect.getSmolUtil();
const { apply, bind, call } = Function.prototype;
const uncurryThis = _smolUtil?.uncurryThis ?? bind.bind(call);
const applyBind = _smolUtil?.applyBind ?? bind.bind(apply);
const _applyBoundForSafe = applyBind;
const applySafe = _smolUtil?.applySafe ?? ((fn) => {
	const apply2 = _applyBoundForSafe(fn);
	return (self, args) => {
		try {
			return apply2(self, args);
		} catch {
			return;
		}
	};
});
const _bindCallFallback = ((fn, thisArg, ...presetArgs) => Function.prototype.bind.apply(fn, [thisArg, ...presetArgs]));
const bindCall = _smolUtil?.bindCall ?? _bindCallFallback;
const weakRefSafe = _smolUtil?.weakRefSafe ?? ((target) => {
	try {
		return new WeakRef(target);
	} catch {
		return;
	}
});

//#endregion
exports.applyBind = applyBind;
exports.applySafe = applySafe;
exports.bindCall = bindCall;
exports.uncurryThis = uncurryThis;
exports.weakRefSafe = weakRefSafe;