es.regexp.sticky.js 891 B

12345678910111213141516171819202122
  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. // https://tc39.es/ecma262/#sec-get-regexp.prototype.sticky
  8. if (DESCRIPTORS && UNSUPPORTED_Y) {
  9. defineProperty(RegExp.prototype, 'sticky', {
  10. configurable: true,
  11. get: function () {
  12. if (this === RegExpPrototype) return undefined;
  13. // We can't use InternalStateModule.getterFor because
  14. // we don't add metadata for regexps created by a literal.
  15. if (this instanceof RegExp) {
  16. return !!getInternalState(this).sticky;
  17. }
  18. throw TypeError('Incompatible receiver, RegExp required');
  19. }
  20. });
  21. }