es.regexp.sticky.js 831 B

123456789101112131415161718192021
  1. var DESCRIPTORS = require('../internals/descriptors');
  2. var UNSUPPORTED_Y = require('../internals/regexp-sticky-helpers').UNSUPPORTED_Y;
  3. var defineProperty = require('../internals/object-define-property').f;
  4. var getInternalState = require('../internals/internal-state').get;
  5. var RegExpPrototype = RegExp.prototype;
  6. // `RegExp.prototype.sticky` getter
  7. if (DESCRIPTORS && UNSUPPORTED_Y) {
  8. defineProperty(RegExp.prototype, 'sticky', {
  9. configurable: true,
  10. get: function () {
  11. if (this === RegExpPrototype) return undefined;
  12. // We can't use InternalStateModule.getterFor because
  13. // we don't add metadata for regexps created by a literal.
  14. if (this instanceof RegExp) {
  15. return !!getInternalState(this).sticky;
  16. }
  17. throw TypeError('Incompatible receiver, RegExp required');
  18. }
  19. });
  20. }