[79a0317] | 1 | 'use strict';
|
---|
| 2 | var globalThis = require('../internals/global-this');
|
---|
| 3 | var DESCRIPTORS = require('../internals/descriptors');
|
---|
| 4 | var defineBuiltInAccessor = require('../internals/define-built-in-accessor');
|
---|
| 5 | var regExpFlags = require('../internals/regexp-flags');
|
---|
| 6 | var fails = require('../internals/fails');
|
---|
| 7 |
|
---|
| 8 | // babel-minify and Closure Compiler transpiles RegExp('.', 'd') -> /./d and it causes SyntaxError
|
---|
| 9 | var RegExp = globalThis.RegExp;
|
---|
| 10 | var RegExpPrototype = RegExp.prototype;
|
---|
| 11 |
|
---|
| 12 | var FORCED = DESCRIPTORS && fails(function () {
|
---|
| 13 | var INDICES_SUPPORT = true;
|
---|
| 14 | try {
|
---|
| 15 | RegExp('.', 'd');
|
---|
| 16 | } catch (error) {
|
---|
| 17 | INDICES_SUPPORT = false;
|
---|
| 18 | }
|
---|
| 19 |
|
---|
| 20 | var O = {};
|
---|
| 21 | // modern V8 bug
|
---|
| 22 | var calls = '';
|
---|
| 23 | var expected = INDICES_SUPPORT ? 'dgimsy' : 'gimsy';
|
---|
| 24 |
|
---|
| 25 | var addGetter = function (key, chr) {
|
---|
| 26 | // eslint-disable-next-line es/no-object-defineproperty -- safe
|
---|
| 27 | Object.defineProperty(O, key, { get: function () {
|
---|
| 28 | calls += chr;
|
---|
| 29 | return true;
|
---|
| 30 | } });
|
---|
| 31 | };
|
---|
| 32 |
|
---|
| 33 | var pairs = {
|
---|
| 34 | dotAll: 's',
|
---|
| 35 | global: 'g',
|
---|
| 36 | ignoreCase: 'i',
|
---|
| 37 | multiline: 'm',
|
---|
| 38 | sticky: 'y'
|
---|
| 39 | };
|
---|
| 40 |
|
---|
| 41 | if (INDICES_SUPPORT) pairs.hasIndices = 'd';
|
---|
| 42 |
|
---|
| 43 | for (var key in pairs) addGetter(key, pairs[key]);
|
---|
| 44 |
|
---|
| 45 | // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
|
---|
| 46 | var result = Object.getOwnPropertyDescriptor(RegExpPrototype, 'flags').get.call(O);
|
---|
| 47 |
|
---|
| 48 | return result !== expected || calls !== expected;
|
---|
| 49 | });
|
---|
| 50 |
|
---|
| 51 | // `RegExp.prototype.flags` getter
|
---|
| 52 | // https://tc39.es/ecma262/#sec-get-regexp.prototype.flags
|
---|
| 53 | if (FORCED) defineBuiltInAccessor(RegExpPrototype, 'flags', {
|
---|
| 54 | configurable: true,
|
---|
| 55 | get: regExpFlags
|
---|
| 56 | });
|
---|