worldwide.js 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. Object.defineProperty(exports, '__esModule', { value: true });
  2. /** Internal global with common properties and Sentry extensions */
  3. // The code below for 'isGlobalObj' and 'GLOBAL_OBJ' was copied from core-js before modification
  4. // https://github.com/zloirock/core-js/blob/1b944df55282cdc99c90db5f49eb0b6eda2cc0a3/packages/core-js/internals/global.js
  5. // core-js has the following licence:
  6. //
  7. // Copyright (c) 2014-2022 Denis Pushkarev
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining a copy
  10. // of this software and associated documentation files (the "Software"), to deal
  11. // in the Software without restriction, including without limitation the rights
  12. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. // copies of the Software, and to permit persons to whom the Software is
  14. // furnished to do so, subject to the following conditions:
  15. //
  16. // The above copyright notice and this permission notice shall be included in
  17. // all copies or substantial portions of the Software.
  18. //
  19. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. // THE SOFTWARE.
  26. /** Returns 'obj' if it's the global object, otherwise returns undefined */
  27. function isGlobalObj(obj) {
  28. return obj && obj.Math == Math ? obj : undefined;
  29. }
  30. /** Get's the global object for the current JavaScript runtime */
  31. const GLOBAL_OBJ =
  32. (typeof globalThis == 'object' && isGlobalObj(globalThis)) ||
  33. // eslint-disable-next-line no-restricted-globals
  34. (typeof window == 'object' && isGlobalObj(window)) ||
  35. (typeof self == 'object' && isGlobalObj(self)) ||
  36. (typeof global == 'object' && isGlobalObj(global)) ||
  37. (function () {
  38. return this;
  39. })() ||
  40. {};
  41. /**
  42. * @deprecated Use GLOBAL_OBJ instead or WINDOW from @sentry/browser. This will be removed in v8
  43. */
  44. function getGlobalObject() {
  45. return GLOBAL_OBJ ;
  46. }
  47. /**
  48. * Returns a global singleton contained in the global `__SENTRY__` object.
  49. *
  50. * If the singleton doesn't already exist in `__SENTRY__`, it will be created using the given factory
  51. * function and added to the `__SENTRY__` object.
  52. *
  53. * @param name name of the global singleton on __SENTRY__
  54. * @param creator creator Factory function to create the singleton if it doesn't already exist on `__SENTRY__`
  55. * @param obj (Optional) The global object on which to look for `__SENTRY__`, if not `GLOBAL_OBJ`'s return value
  56. * @returns the singleton
  57. */
  58. function getGlobalSingleton(name, creator, obj) {
  59. const gbl = (obj || GLOBAL_OBJ) ;
  60. const __SENTRY__ = (gbl.__SENTRY__ = gbl.__SENTRY__ || {});
  61. const singleton = __SENTRY__[name] || (__SENTRY__[name] = creator());
  62. return singleton;
  63. }
  64. exports.GLOBAL_OBJ = GLOBAL_OBJ;
  65. exports.getGlobalObject = getGlobalObject;
  66. exports.getGlobalSingleton = getGlobalSingleton;
  67. //# sourceMappingURL=worldwide.js.map