source: trip-planner-front/node_modules/core-js/internals/fix-regexp-well-known-symbol-logic.js@ 1ad8e64

Last change on this file since 1ad8e64 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.5 KB
Line 
1'use strict';
2// TODO: Remove from `core-js@4` since it's moved to entry points
3require('../modules/es.regexp.exec');
4var redefine = require('../internals/redefine');
5var regexpExec = require('../internals/regexp-exec');
6var fails = require('../internals/fails');
7var wellKnownSymbol = require('../internals/well-known-symbol');
8var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
9
10var SPECIES = wellKnownSymbol('species');
11var RegExpPrototype = RegExp.prototype;
12
13module.exports = function (KEY, exec, FORCED, SHAM) {
14 var SYMBOL = wellKnownSymbol(KEY);
15
16 var DELEGATES_TO_SYMBOL = !fails(function () {
17 // String methods call symbol-named RegEp methods
18 var O = {};
19 O[SYMBOL] = function () { return 7; };
20 return ''[KEY](O) != 7;
21 });
22
23 var DELEGATES_TO_EXEC = DELEGATES_TO_SYMBOL && !fails(function () {
24 // Symbol-named RegExp methods call .exec
25 var execCalled = false;
26 var re = /a/;
27
28 if (KEY === 'split') {
29 // We can't use real regex here since it causes deoptimization
30 // and serious performance degradation in V8
31 // https://github.com/zloirock/core-js/issues/306
32 re = {};
33 // RegExp[@@split] doesn't call the regex's exec method, but first creates
34 // a new one. We need to return the patched regex when creating the new one.
35 re.constructor = {};
36 re.constructor[SPECIES] = function () { return re; };
37 re.flags = '';
38 re[SYMBOL] = /./[SYMBOL];
39 }
40
41 re.exec = function () { execCalled = true; return null; };
42
43 re[SYMBOL]('');
44 return !execCalled;
45 });
46
47 if (
48 !DELEGATES_TO_SYMBOL ||
49 !DELEGATES_TO_EXEC ||
50 FORCED
51 ) {
52 var nativeRegExpMethod = /./[SYMBOL];
53 var methods = exec(SYMBOL, ''[KEY], function (nativeMethod, regexp, str, arg2, forceStringMethod) {
54 var $exec = regexp.exec;
55 if ($exec === regexpExec || $exec === RegExpPrototype.exec) {
56 if (DELEGATES_TO_SYMBOL && !forceStringMethod) {
57 // The native String method already delegates to @@method (this
58 // polyfilled function), leasing to infinite recursion.
59 // We avoid it by directly calling the native @@method method.
60 return { done: true, value: nativeRegExpMethod.call(regexp, str, arg2) };
61 }
62 return { done: true, value: nativeMethod.call(str, regexp, arg2) };
63 }
64 return { done: false };
65 });
66
67 redefine(String.prototype, KEY, methods[0]);
68 redefine(RegExpPrototype, SYMBOL, methods[1]);
69 }
70
71 if (SHAM) createNonEnumerableProperty(RegExpPrototype[SYMBOL], 'sham', true);
72};
Note: See TracBrowser for help on using the repository browser.