polyfill.js 650 B

1234567891011121314151617181920
  1. 'use strict';
  2. var implementation = require('./implementation');
  3. var supportsDescriptors = require('define-properties').supportsDescriptors;
  4. var $gOPD = Object.getOwnPropertyDescriptor;
  5. var $TypeError = TypeError;
  6. module.exports = function getPolyfill() {
  7. if (!supportsDescriptors) {
  8. throw new $TypeError('RegExp.prototype.flags requires a true ES5 environment that supports property descriptors');
  9. }
  10. if ((/a/mig).flags === 'gim') {
  11. var descriptor = $gOPD(RegExp.prototype, 'flags');
  12. if (descriptor && typeof descriptor.get === 'function' && typeof (/a/).dotAll === 'boolean') {
  13. return descriptor.get;
  14. }
  15. }
  16. return implementation;
  17. };