2 // TODO: Remove from `core-js@4` since it's moved to entry points
3 require('../modules/es.regexp.exec');
4 var uncurryThis = require('../internals/function-uncurry-this');
5 var redefine = require('../internals/redefine');
6 var regexpExec = require('../internals/regexp-exec');
7 var fails = require('../internals/fails');
8 var wellKnownSymbol = require('../internals/well-known-symbol');
9 var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
11 var SPECIES = wellKnownSymbol('species');
12 var RegExpPrototype = RegExp.prototype;
14 module.exports = function (KEY, exec, FORCED, SHAM) {
15 var SYMBOL = wellKnownSymbol(KEY);
17 var DELEGATES_TO_SYMBOL = !fails(function () {
18 // String methods call symbol-named RegEp methods
20 O[SYMBOL] = function () { return 7; };
21 return ''[KEY](O) != 7;
24 var DELEGATES_TO_EXEC = DELEGATES_TO_SYMBOL && !fails(function () {
25 // Symbol-named RegExp methods call .exec
26 var execCalled = false;
29 if (KEY === 'split') {
30 // We can't use real regex here since it causes deoptimization
31 // and serious performance degradation in V8
32 // https://github.com/zloirock/core-js/issues/306
34 // RegExp[@@split] doesn't call the regex's exec method, but first creates
35 // a new one. We need to return the patched regex when creating the new one.
37 re.constructor[SPECIES] = function () { return re; };
39 re[SYMBOL] = /./[SYMBOL];
42 re.exec = function () { execCalled = true; return null; };
49 !DELEGATES_TO_SYMBOL ||
53 var uncurriedNativeRegExpMethod = uncurryThis(/./[SYMBOL]);
54 var methods = exec(SYMBOL, ''[KEY], function (nativeMethod, regexp, str, arg2, forceStringMethod) {
55 var uncurriedNativeMethod = uncurryThis(nativeMethod);
56 var $exec = regexp.exec;
57 if ($exec === regexpExec || $exec === RegExpPrototype.exec) {
58 if (DELEGATES_TO_SYMBOL && !forceStringMethod) {
59 // The native String method already delegates to @@method (this
60 // polyfilled function), leasing to infinite recursion.
61 // We avoid it by directly calling the native @@method method.
62 return { done: true, value: uncurriedNativeRegExpMethod(regexp, str, arg2) };
64 return { done: true, value: uncurriedNativeMethod(str, regexp, arg2) };
66 return { done: false };
69 redefine(String.prototype, KEY, methods[0]);
70 redefine(RegExpPrototype, SYMBOL, methods[1]);
73 if (SHAM) createNonEnumerableProperty(RegExpPrototype[SYMBOL], 'sham', true);