UNPKG

@sentry/core

Version:
39 lines (38 loc) • 1.76 kB
import { SDK_VERSION } from "./utils/version.js"; import { GLOBAL_OBJ } from "./utils/worldwide.js"; // src/carrier.ts /** * Returns the global shim registry. * * FIXME: This function is problematic, because despite always returning a valid Carrier, * it has an optional `__SENTRY__` property, which then in turn requires us to always perform an unnecessary check * at the call-site. We always access the carrier through this function, so we can guarantee that `__SENTRY__` is there. **/ function getMainCarrier() { getSentryCarrier(GLOBAL_OBJ); return GLOBAL_OBJ; } /** Will either get the existing sentry carrier, or create a new one. */ function getSentryCarrier(carrier) { const __SENTRY__ = carrier.__SENTRY__ = carrier.__SENTRY__ || {}; __SENTRY__.version = __SENTRY__.version || "11.16.0"; return __SENTRY__[SDK_VERSION] = __SENTRY__["11.16.0"] || {}; } /** * Returns a global singleton contained in the global `__SENTRY__[]` object. * * If the singleton doesn't already exist in `__SENTRY__`, it will be created using the given factory * function and added to the `__SENTRY__` object. * * @param name name of the global singleton on __SENTRY__ * @param creator creator Factory function to create the singleton if it doesn't already exist on `__SENTRY__` * @param obj (Optional) The global object on which to look for `__SENTRY__`, if not `GLOBAL_OBJ`'s return value * @returns the singleton */ function getGlobalSingleton(name, creator, obj = GLOBAL_OBJ) { const __SENTRY__ = obj.__SENTRY__ = obj.__SENTRY__ || {}; const carrier = __SENTRY__[SDK_VERSION] = __SENTRY__["11.16.0"] || {}; return carrier[name] || (carrier[name] = creator()); } export { getGlobalSingleton, getMainCarrier, getSentryCarrier }; //# sourceMappingURL=carrier.js.map