Skip to content

Commit

Permalink
[Robustness] use a cached and shimmed String#trim
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jan 6, 2016
1 parent 41b5bfb commit 12eb504
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion es5-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -1897,6 +1897,7 @@ defineProperties(StringPrototype, {
return $String(this).replace(trimBeginRegexp, '').replace(trimEndRegexp, '');
}
}, hasTrimWhitespaceBug);
var trim = call.bind(String.prototype.trim);

var hasLastIndexBug = StringPrototype.lastIndexOf && 'abcあい'.lastIndexOf('あい', 2) !== -1;
defineProperties(StringPrototype, {
Expand Down Expand Up @@ -1937,7 +1938,7 @@ if (parseInt(ws + '08') !== 8 || parseInt(ws + '0x16') !== 22) {
parseInt = (function (origParseInt) {
var hexRegex = /^[\-+]?0[xX]/;
return function parseInt(str, radix) {
var string = $String(str).trim();
var string = trim(str);
var defaultedRadix = $Number(radix) || (hexRegex.test(string) ? 16 : 10);
return origParseInt(string, defaultedRadix);
};
Expand Down

0 comments on commit 12eb504

Please sign in to comment.