You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. var define = require('define-properties');
  3. var gOPD = require('gopd');
  4. var getPolyfill = require('./polyfill');
  5. module.exports = function shimGlobal() {
  6. var polyfill = getPolyfill();
  7. if (define.supportsDescriptors) {
  8. var descriptor = gOPD(polyfill, 'globalThis');
  9. if (
  10. !descriptor
  11. || (
  12. descriptor.configurable
  13. && (descriptor.enumerable || !descriptor.writable || globalThis !== polyfill)
  14. )
  15. ) {
  16. Object.defineProperty(polyfill, 'globalThis', {
  17. configurable: true,
  18. enumerable: false,
  19. value: polyfill,
  20. writable: true
  21. });
  22. }
  23. } else if (typeof globalThis !== 'object' || globalThis !== polyfill) {
  24. polyfill.globalThis = polyfill;
  25. }
  26. return polyfill;
  27. };