UNPKG

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