Skip to content

Commit

Permalink
fix some possible String#split polyfill problems in V8 5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed May 8, 2021
1 parent 7a7c66b commit 3eb4159
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Changelog
##### Unreleased
- Fixed some cases of `Function#toString` with multiple `core-js` instances
- Fixed some possible `String#split` polyfill problems in V8 5.1

##### 3.12.0 - 2021.05.06
- Added well-known symbol `Symbol.metadata` for [decorators stage 2 proposal](https://github.com/tc39/proposal-decorators)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
// TODO: Remove from `core-js@4` since it's moved to entry points
require('../modules/es.regexp.exec');
var redefine = require('../internals/redefine');
var regexpExec = require('../internals/regexp-exec');
var fails = require('../internals/fails');
var wellKnownSymbol = require('../internals/well-known-symbol');
var createNonEnumerableProperty = require('../internals/create-non-enumerable-property');

var SPECIES = wellKnownSymbol('species');
var RegExpPrototype = RegExp.prototype;

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

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

if (sham) createNonEnumerableProperty(RegExp.prototype[SYMBOL], 'sham', true);
if (sham) createNonEnumerableProperty(RegExpPrototype[SYMBOL], 'sham', true);
};

0 comments on commit 3eb4159

Please sign in to comment.