-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fix RegExp methods in old browsers #453
Merged
zloirock
merged 9 commits into
zloirock:master
from
nicolo-ribaudo:fix-regexs-on-old-browsers
Nov 17, 2018
Merged
Changes from 2 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
aeacd0d
Fix RegExp methods on Chrome 50 & 51
nicolo-ribaudo 02a4e07
Reduce repetition
nicolo-ribaudo 37c85d5
Rename internals/regexp-exec -> internals/regexp-exec-abstract
nicolo-ribaudo 62ade11
Add RegExp#exec tests (they are failing in IE8)
nicolo-ribaudo 5bd11fc
Fix #lastIndex in IE8 and move NPCG check from #split to #exec
nicolo-ribaudo b8f73b1
Fix String#split and another RegExp#lastIndex case in IE8
nicolo-ribaudo 823756a
Fix String#replace bug with custon exec in IE8
nicolo-ribaudo d2aac81
Fix bug in IE7 (only tested using IE8 in compatibility mode)
nicolo-ribaudo d3fa95e
Fix bug in Safari 9
nicolo-ribaudo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,40 +4,44 @@ var anObject = require('../internals/an-object'); | |
var toLength = require('../internals/to-length'); | ||
var advanceStringIndex = require('../internals/advance-string-index'); | ||
var regExpExec = require('../internals/regexp-exec'); | ||
var nativeExec = RegExp.prototype.exec; | ||
|
||
// @@match logic | ||
require('../internals/fix-regexp-well-known-symbol-logic')('match', 1, function (defined, MATCH, nativeMatch) { | ||
return [ | ||
// `String.prototype.match` method | ||
// https://tc39.github.io/ecma262/#sec-string.prototype.match | ||
function match(regexp) { | ||
var O = defined(this); | ||
var matcher = regexp == undefined ? undefined : regexp[MATCH]; | ||
return matcher !== undefined ? matcher.call(regexp, O) : new RegExp(regexp)[MATCH](String(O)); | ||
}, | ||
// `RegExp.prototype[@@match]` method | ||
// https://tc39.github.io/ecma262/#sec-regexp.prototype-@@match | ||
function (regexp) { | ||
if (regexp.exec === nativeExec) return nativeMatch.call(this, regexp); | ||
require('../internals/fix-regexp-well-known-symbol-logic')( | ||
'match', | ||
1, | ||
function (defined, MATCH, nativeMatch, maybeCallNative) { | ||
return [ | ||
// `String.prototype.match` method | ||
// https://tc39.github.io/ecma262/#sec-string.prototype.match | ||
function match(regexp) { | ||
var O = defined(this); | ||
var matcher = regexp == undefined ? undefined : regexp[MATCH]; | ||
return matcher !== undefined ? matcher.call(regexp, O) : new RegExp(regexp)[MATCH](String(O)); | ||
}, | ||
// `RegExp.prototype[@@match]` method | ||
// https://tc39.github.io/ecma262/#sec-regexp.prototype-@@match | ||
function (regexp) { | ||
var res = maybeCallNative(nativeMatch, regexp, this); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All those "maybeCallNative" calls are to fix the infinite recursion in Chrome 50 |
||
if (res.done) return res.value; | ||
|
||
var rx = anObject(regexp); | ||
var S = String(this); | ||
var rx = anObject(regexp); | ||
var S = String(this); | ||
|
||
if (!rx.global) return regExpExec(rx, S); | ||
if (!rx.global) return regExpExec(rx, S); | ||
|
||
var fullUnicode = rx.unicode; | ||
rx.lastIndex = 0; | ||
var A = []; | ||
var n = 0; | ||
var result; | ||
while ((result = regExpExec(rx, S)) !== null) { | ||
var matchStr = String(result[0]); | ||
A[n] = matchStr; | ||
if (matchStr === '') rx.lastIndex = advanceStringIndex(S, toLength(rx.lastIndex), fullUnicode); | ||
n++; | ||
var fullUnicode = rx.unicode; | ||
rx.lastIndex = 0; | ||
var A = []; | ||
var n = 0; | ||
var result; | ||
while ((result = regExpExec(rx, S)) !== null) { | ||
var matchStr = String(result[0]); | ||
A[n] = matchStr; | ||
if (matchStr === '') rx.lastIndex = advanceStringIndex(S, toLength(rx.lastIndex), fullUnicode); | ||
n++; | ||
} | ||
return n === 0 ? null : A; | ||
} | ||
return n === 0 ? null : A; | ||
} | ||
]; | ||
}); | ||
]; | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the fix for Chrome 51.