worldwide.js 3.0 KB

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