Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a workaround for a UC Browser specific version bug with unobservable RegExp#sticky flag #1015

Merged
merged 2 commits into from Nov 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
@@ -1,5 +1,6 @@
## Changelog
##### Unreleased
- Added a workaround for a UC Browser specific version bug with unobservable `RegExp#sticky` flag, [#1008](https://github.com/zloirock/core-js/issues/1008), [#1015](https://github.com/zloirock/core-js/issues/1015)
- Added handling of comments and specific spaces to `Function#name` polyfill, [#1010](https://github.com/zloirock/core-js/issues/1010), thanks [@ildar-shaimordanov](https://github.com/ildar-shaimordanov)
- Updated Deno compat data mapping
- Added iOS Safari 15.2 compat data mapping
Expand Down
2 changes: 1 addition & 1 deletion packages/core-js/internals/regexp-exec.js
Expand Up @@ -28,7 +28,7 @@ var UPDATES_LAST_INDEX_WRONG = (function () {
return re1.lastIndex !== 0 || re2.lastIndex !== 0;
})();

var UNSUPPORTED_Y = stickyHelpers.UNSUPPORTED_Y || stickyHelpers.BROKEN_CARET;
var UNSUPPORTED_Y = stickyHelpers.BROKEN_CARET;

// nonparticipating capturing group, copied from es5-shim's String#split patch.
var NPCG_INCLUDED = /()??/.exec('')[1] !== undefined;
Expand Down
16 changes: 14 additions & 2 deletions packages/core-js/internals/regexp-sticky-helpers.js
Expand Up @@ -4,15 +4,27 @@ var global = require('../internals/global');
// babel-minify and Closure Compiler transpiles RegExp('a', 'y') -> /a/y and it causes SyntaxError
var $RegExp = global.RegExp;

exports.UNSUPPORTED_Y = fails(function () {
var UNSUPPORTED_Y = fails(function () {
var re = $RegExp('a', 'y');
re.lastIndex = 2;
return re.exec('abcd') != null;
});

exports.BROKEN_CARET = fails(function () {
// UC Browser bug
// https://github.com/zloirock/core-js/issues/1008
var MISSED_STICKY = UNSUPPORTED_Y || fails(function () {
return !$RegExp('a', 'y').sticky;
});

var BROKEN_CARET = UNSUPPORTED_Y || fails(function () {
// https://bugzilla.mozilla.org/show_bug.cgi?id=773687
var re = $RegExp('^r', 'gy');
re.lastIndex = 2;
return re.exec('str') != null;
});

module.exports = {
BROKEN_CARET: BROKEN_CARET,
MISSED_STICKY: MISSED_STICKY,
UNSUPPORTED_Y: UNSUPPORTED_Y
};
7 changes: 4 additions & 3 deletions packages/core-js/modules/es.regexp.constructor.js
Expand Up @@ -38,10 +38,11 @@ var re2 = /a/g;
// "new" should create a new object, old webkit bug
var CORRECT_NEW = new NativeRegExp(re1) !== re1;

var MISSED_STICKY = stickyHelpers.MISSED_STICKY;
var UNSUPPORTED_Y = stickyHelpers.UNSUPPORTED_Y;

var BASE_FORCED = DESCRIPTORS &&
(!CORRECT_NEW || UNSUPPORTED_Y || UNSUPPORTED_DOT_ALL || UNSUPPORTED_NCG || fails(function () {
(!CORRECT_NEW || MISSED_STICKY || UNSUPPORTED_DOT_ALL || UNSUPPORTED_NCG || fails(function () {
re2[MATCH] = false;
// RegExp constructor can alter flags and IsRegExp works correct with @@match
return NativeRegExp(re1) != re1 || NativeRegExp(re2) == re2 || NativeRegExp(re1, 'i') != '/a/i';
Expand Down Expand Up @@ -146,9 +147,9 @@ if (isForced('RegExp', BASE_FORCED)) {

rawFlags = flags;

if (UNSUPPORTED_Y && 'sticky' in re1) {
if (MISSED_STICKY && 'sticky' in re1) {
sticky = !!flags && stringIndexOf(flags, 'y') > -1;
if (sticky) flags = replace(flags, /y/g, '');
if (sticky && UNSUPPORTED_Y) flags = replace(flags, /y/g, '');
}

if (UNSUPPORTED_NCG) {
Expand Down
4 changes: 2 additions & 2 deletions packages/core-js/modules/es.regexp.sticky.js
@@ -1,6 +1,6 @@
var global = require('../internals/global');
var DESCRIPTORS = require('../internals/descriptors');
var UNSUPPORTED_Y = require('../internals/regexp-sticky-helpers').UNSUPPORTED_Y;
var MISSED_STICKY = require('../internals/regexp-sticky-helpers').MISSED_STICKY;
var classof = require('../internals/classof-raw');
var defineProperty = require('../internals/object-define-property').f;
var getInternalState = require('../internals/internal-state').get;
Expand All @@ -10,7 +10,7 @@ var TypeError = global.TypeError;

// `RegExp.prototype.sticky` getter
// https://tc39.es/ecma262/#sec-get-regexp.prototype.sticky
if (DESCRIPTORS && UNSUPPORTED_Y) {
if (DESCRIPTORS && MISSED_STICKY) {
defineProperty(RegExpPrototype, 'sticky', {
configurable: true,
get: function () {
Expand Down