shim.js 722 B

12345678910111213141516171819202122
  1. 'use strict';
  2. var define = require('define-properties');
  3. var getPolyfill = require('./polyfill');
  4. module.exports = function shimGlobal() {
  5. var polyfill = getPolyfill();
  6. if (define.supportsDescriptors) {
  7. var descriptor = Object.getOwnPropertyDescriptor(polyfill, 'globalThis');
  8. if (!descriptor || (descriptor.configurable && (descriptor.enumerable || !descriptor.writable || globalThis !== polyfill))) { // eslint-disable-line max-len
  9. Object.defineProperty(polyfill, 'globalThis', {
  10. configurable: true,
  11. enumerable: false,
  12. value: polyfill,
  13. writable: true
  14. });
  15. }
  16. } else if (typeof globalThis !== 'object' || globalThis !== polyfill) {
  17. polyfill.globalThis = polyfill;
  18. }
  19. return polyfill;
  20. };