getGlobalThis.js 702 B

123456789101112131415161718192021222324252627282930
  1. "use strict";
  2. // eslint-disable-next-line func-names
  3. module.exports = function () {
  4. if (typeof globalThis === "object") {
  5. return globalThis;
  6. }
  7. var g;
  8. try {
  9. // This works if eval is allowed (see CSP)
  10. // eslint-disable-next-line no-new-func
  11. g = this || new Function("return this")();
  12. } catch (e) {
  13. // This works if the window reference is available
  14. if (typeof window === "object") {
  15. return window;
  16. }
  17. // This works if the self reference is available
  18. if (typeof self === "object") {
  19. return self;
  20. }
  21. // This works if the global reference is available
  22. if (typeof global !== "undefined") {
  23. return global;
  24. }
  25. }
  26. return g;
  27. }();