polyfill.js 864 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. 'use strict';
  2. var implementation = require('./implementation');
  3. var supportsDescriptors = require('define-properties').supportsDescriptors;
  4. var $gOPD = Object.getOwnPropertyDescriptor;
  5. module.exports = function getPolyfill() {
  6. if (supportsDescriptors && (/a/mig).flags === 'gim') {
  7. var descriptor = $gOPD(RegExp.prototype, 'flags');
  8. if (
  9. descriptor
  10. && typeof descriptor.get === 'function'
  11. && 'dotAll' in RegExp.prototype
  12. && 'hasIndices' in RegExp.prototype
  13. ) {
  14. /* eslint getter-return: 0 */
  15. var calls = '';
  16. var o = {};
  17. Object.defineProperty(o, 'hasIndices', {
  18. get: function () {
  19. calls += 'd';
  20. }
  21. });
  22. Object.defineProperty(o, 'sticky', {
  23. get: function () {
  24. calls += 'y';
  25. }
  26. });
  27. descriptor.get.call(o);
  28. if (calls === 'dy') {
  29. return descriptor.get;
  30. }
  31. }
  32. }
  33. return implementation;
  34. };