-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow disable of RegExp cache/restore
The implementation of cache/restore of RegExp properties has the potential to cause a number of issues. A perfect solution is not possible because it's not possible to determine the regex that was used to turn the cached input into the cached match and group matches. The current solution simply takes the lastMatch and escapes it, wrapping any match groups in parens. One problem with this approach is that when the match is very long, it will overrun the maximum length of a RegEx in JavaScript. In this commit, we add the capability to disable restore of RegExp properties entirely, via `IntlPolyfill.__disableRegExpRestore`.
- Loading branch information
Mike Lewis
committed
Jul 7, 2016
1 parent
f8c5616
commit b5d5bf7
Showing
5 changed files
with
59 additions
and
1 deletion.
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
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
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 |
---|---|---|
@@ -0,0 +1,40 @@ | ||
var IntlPolyfill = require('../'); | ||
|
||
function assertEqual(value, expected, message) { | ||
console.log(message); | ||
if (value !== expected) { | ||
console.error(' > ERROR: expected value ' + expected + ' but the actual value is ' + value); | ||
process.exit(1); | ||
} else { | ||
console.log(' > PASSED'); | ||
} | ||
} | ||
|
||
function assertNotEqual(value, expected, message) { | ||
console.log(message); | ||
if (value === expected) { | ||
console.error(' > ERROR: expected value ' + expected + ' but the actual value is ' + value); | ||
process.exit(1); | ||
} else { | ||
console.log(' > PASSED'); | ||
} | ||
} | ||
|
||
/foo/.exec('a foo test'); | ||
new IntlPolyfill.NumberFormat('en-US', { | ||
style: 'currency', | ||
currency: 'GBP', | ||
minimumFractionDigits: 2, | ||
}); | ||
assertEqual(RegExp.input, 'a foo test', 'Normally, RegExp.input should be cached and restored'); | ||
assertEqual(RegExp.lastMatch, 'foo', 'Normally, RegExp.lastMatch should be cached and restored'); | ||
|
||
IntlPolyfill.__disableRegExpRestore(); | ||
/foo/.exec('a foo test'); | ||
new IntlPolyfill.NumberFormat('en-US', { | ||
style: 'currency', | ||
currency: 'GBP', | ||
minimumFractionDigits: 2, | ||
}); | ||
assertNotEqual(RegExp.input, 'a foo test', 'After invoking __disableRegExpRestore, RegExp.input should not be cached and restored'); | ||
assertNotEqual(RegExp.lastMatch, 'foo', 'After invoking __disableRegExpRestore, RegExp.lastMatch should not be cached and restored'); |