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

Normative: Make JSON.stringify(-0) preserve the sign #1466

Closed
wants to merge 1 commit into from

Commits on Mar 5, 2019

  1. Normative: Make JSON.stringify(-0) preserve the sign

    Although JSON supports -0 per ECMA-404 and JSON.parse('-0') returns -0, JSON.stringify(-0) currently loses the sign, outputting just '0'.
    
    This patch makes JSON.stringify(-0) return '-0' instead, so that the following holds:
    
        Object.is(JSON.parse('-0'), -0);
        // → true (this is already the case, even without this patch)
        JSON.stringify(-0);
        // → '-0'
        Object.is(JSON.parse(JSON.stringify(-0)), -0);
        // → true
    
    Results in current JavaScript engines:
    
        $ eshost -se 'Object.is(JSON.parse("-0"), -0)'
        #### Chakra, JavaScriptCore, SpiderMonkey, V8
        true
    
        #### XS
        false
    
        $ eshost -se 'JSON.stringify(-0)'
        #### Chakra, JavaScriptCore, SpiderMonkey, V8, XS
        0
    
        $ eshost -se 'Object.is(JSON.parse(JSON.stringify(-0)), -0)'
        #### Chakra
        true
    
        #### JavaScriptCore, SpiderMonkey, V8, XS
        false
    mathiasbynens committed Mar 5, 2019
    Copy the full SHA
    69be071 View commit details
    Browse the repository at this point in the history