es.regexp.sticky.js 1.0 KB

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