es.regexp.sticky.js 995 B

12345678910111213141516171819202122232425
  1. var DESCRIPTORS = require('../internals/descriptors');
  2. var MISSED_STICKY = require('../internals/regexp-sticky-helpers').MISSED_STICKY;
  3. var classof = require('../internals/classof-raw');
  4. var defineBuiltInAccessor = require('../internals/define-built-in-accessor');
  5. var getInternalState = require('../internals/internal-state').get;
  6. var RegExpPrototype = RegExp.prototype;
  7. var $TypeError = TypeError;
  8. // `RegExp.prototype.sticky` getter
  9. // https://tc39.es/ecma262/#sec-get-regexp.prototype.sticky
  10. if (DESCRIPTORS && MISSED_STICKY) {
  11. defineBuiltInAccessor(RegExpPrototype, 'sticky', {
  12. configurable: true,
  13. get: function sticky() {
  14. if (this === RegExpPrototype) return undefined;
  15. // We can't use InternalStateModule.getterFor because
  16. // we don't add metadata for regexps created by a literal.
  17. if (classof(this) === 'RegExp') {
  18. return !!getInternalState(this).sticky;
  19. }
  20. throw $TypeError('Incompatible receiver, RegExp required');
  21. }
  22. });
  23. }