Skip to content

Commit 3eb4159

Browse files
committed
fix some possible String#split polyfill problems in V8 5.1
1 parent 7a7c66b commit 3eb4159

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## Changelog
22
##### Unreleased
33
- Fixed some cases of `Function#toString` with multiple `core-js` instances
4+
- Fixed some possible `String#split` polyfill problems in V8 5.1
45

56
##### 3.12.0 - 2021.05.06
67
- Added well-known symbol `Symbol.metadata` for [decorators stage 2 proposal](https://github.com/tc39/proposal-decorators)

packages/core-js/internals/fix-regexp-well-known-symbol-logic.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
// TODO: Remove from `core-js@4` since it's moved to entry points
33
require('../modules/es.regexp.exec');
44
var redefine = require('../internals/redefine');
5+
var regexpExec = require('../internals/regexp-exec');
56
var fails = require('../internals/fails');
67
var wellKnownSymbol = require('../internals/well-known-symbol');
78
var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');
89

910
var SPECIES = wellKnownSymbol('species');
11+
var RegExpPrototype = RegExp.prototype;
1012

1113
var REPLACE_SUPPORTS_NAMED_GROUPS = !fails(function () {
1214
// #replace needs built-in support for named groups.
@@ -94,7 +96,8 @@ module.exports = function (KEY, length, exec, sham) {
9496
) {
9597
var nativeRegExpMethod = /./[SYMBOL];
9698
var methods = exec(SYMBOL, ''[KEY], function (nativeMethod, regexp, str, arg2, forceStringMethod) {
97-
if (regexp.exec === RegExp.prototype.exec) {
99+
var $exec = regexp.exec;
100+
if ($exec === regexpExec || $exec === RegExpPrototype.exec) {
98101
if (DELEGATES_TO_SYMBOL && !forceStringMethod) {
99102
// The native String method already delegates to @@method (this
100103
// polyfilled function), leasing to infinite recursion.
@@ -112,7 +115,7 @@ module.exports = function (KEY, length, exec, sham) {
112115
var regexMethod = methods[1];
113116

114117
redefine(String.prototype, KEY, stringMethod);
115-
redefine(RegExp.prototype, SYMBOL, length == 2
118+
redefine(RegExpPrototype, SYMBOL, length == 2
116119
// 21.2.5.8 RegExp.prototype[@@replace](string, replaceValue)
117120
// 21.2.5.11 RegExp.prototype[@@split](string, limit)
118121
? function (string, arg) { return regexMethod.call(string, this, arg); }
@@ -122,5 +125,5 @@ module.exports = function (KEY, length, exec, sham) {
122125
);
123126
}
124127

125-
if (sham) createNonEnumerableProperty(RegExp.prototype[SYMBOL], 'sham', true);
128+
if (sham) createNonEnumerableProperty(RegExpPrototype[SYMBOL], 'sham', true);
126129
};

0 commit comments

Comments
 (0)