Skip to content

Commit 69be071

Browse files
committed
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
1 parent a09fc23 commit 69be071

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

spec.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36323,6 +36323,7 @@ <h1>Runtime Semantics: SerializeJSONProperty ( _key_, _holder_ )</h1>
3632336323
1. If _value_ is *false*, return `"false"`.
3632436324
1. If Type(_value_) is String, return QuoteJSONString(_value_).
3632536325
1. If Type(_value_) is Number, then
36326+
1. If _value_ is *-0*, return `"-0"`.
3632636327
1. If _value_ is finite, return ! ToString(_value_).
3632736328
1. Return `"null"`.
3632836329
1. If Type(_value_) is Object and IsCallable(_value_) is *false*, then

0 commit comments

Comments
 (0)