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

parseInt() throws exception instead of returning NaN #32

Open
tjosseau opened this issue Mar 16, 2017 · 3 comments
Open

parseInt() throws exception instead of returning NaN #32

tjosseau opened this issue Mar 16, 2017 · 3 comments

Comments

@tjosseau
Copy link

The new version of Firefox (52) broke the parseInt() behavior on the test if (parseInt(ws + '08') !== 8 || parseInt(ws + '0x16') !== 22) (line 1956) because of wrong whitespace characters ; returning NaN for both instead of 8 and 22.

Thus parseInt() is redefined by your shim. However, the case parseInt() (empty parameter, or undefined, or null) throws an exception while using trim(string) (line 1962) instead of returning NaN (as default behavior) - trim() should never be called with undefined or null as parameter.

This fixes the issue : if (str === undefined || str === null) str = ""; (to add before line 1962) ; Do not attempt to return NaN directly instead as it has bad side effects on some libraries (such as PerfectScrollbar) - I don't know why but it does.

Full example:

// ES-5 15.1.2.2
/* eslint-disable radix */
if (parseInt(ws + '08') !== 8 || parseInt(ws + '0x16') !== 22) {
/* eslint-enable radix */
    /* global parseInt: true */
    parseInt = (function (origParseInt) {
        var hexRegex = /^[\-+]?0[xX]/;
        return function parseInt(str, radix) {
            if (str === undefined || str === null) str = "" ; // Fix here
            var string = trim(str);
            var defaultedRadix = $Number(radix) || (hexRegex.test(string) ? 16 : 10);
            return origParseInt(string, defaultedRadix);
        };
    }(parseInt));
}

The redefined function parseFloat() should have the same fix too (before line 1974).

@tjosseau
Copy link
Author

I've reported the parseInt() issue to Bugzilla, and here is the answer : https://bugzilla.mozilla.org/show_bug.cgi?id=1347869

To sum up, \u180E is no longer supported in Unicode 9 as a whitespace. This particular test should be removed in the ws variable (line 1903).

@michaelficarra
Copy link

@tjosseau You've got the wrong issue tracker, buddy. I think you're looking for this repo: https://github.com/es-shims/es5-shim

@tjosseau
Copy link
Author

Oops, sorry for this. I've added this issue to the correct repo this time. ;)
You can close or even remove this issue now ; thanks !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants