UNPKG

@sentry/core

Version:
62 lines (53 loc) 2.52 kB
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); const version = require('./utils-hoist/version.js'); const worldwide = require('./utils-hoist/worldwide.js'); /** * An object that contains globally accessible properties and maintains a scope stack. * @hidden */ /** * 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() { // This ensures a Sentry carrier exists getSentryCarrier(worldwide.GLOBAL_OBJ); return worldwide.GLOBAL_OBJ; } /** Will either get the existing sentry carrier, or create a new one. */ function getSentryCarrier(carrier) { const __SENTRY__ = (carrier.__SENTRY__ = carrier.__SENTRY__ || {}); // For now: First SDK that sets the .version property wins __SENTRY__.version = __SENTRY__.version || version.SDK_VERSION; // Intentionally populating and returning the version of "this" SDK instance // rather than what's set in .version so that "this" SDK always gets its carrier return (__SENTRY__[version.SDK_VERSION] = __SENTRY__[version.SDK_VERSION] || {}); } /** * 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 = worldwide.GLOBAL_OBJ, ) { const __SENTRY__ = (obj.__SENTRY__ = obj.__SENTRY__ || {}); const carrier = (__SENTRY__[version.SDK_VERSION] = __SENTRY__[version.SDK_VERSION] || {}); // Note: We do not want to set `carrier.version` here, as this may be called before any `init` is called, e.g. for the default scopes return carrier[name] || (carrier[name] = creator()); } exports.getGlobalSingleton = getGlobalSingleton; exports.getMainCarrier = getMainCarrier; exports.getSentryCarrier = getSentryCarrier; //# sourceMappingURL=carrier.js.map