On Mon, Mar 19, 2018 at 10:09 AM, Anders Rundgren < anders.rundgren....@gmail.com> wrote:
> On 2018-03-19 14:43, Mike Samuel wrote: > >> Maybe have a parser function that receive the text of the number? If no >> callout is specified, it could throw an appropriate error. >> >> JSON.safeParse(json, optionalReviver, optionalParseUnrepresentable) >> >> That would allow it to tie into future proposals like decimal, and in >> conjunction with a reviver could treat an array of numbers known to be >> large as an Int64Array view over an ArrayBuffer. >> > > I may be off here, but don't you also need something like rawToJSON for > JSON.stringify()? > That is, rawToJSON would return a string which is used "as is". > Quite right, you would need some adjustment to stringify too. We could change the contract of toJSON so that if it returns a value with a certain runtime type, then JSON.stringify asserts that it is a syntactically valid ES404 value and then uses it inline. For example, ({[Symbol('rawJSON')]: "1" + "0".repeat(1000) }). That would round-trip and compose reasonably well and wouldn't add another special method that needs to be tested for at stringify time. > Anders > > >> >> On Sun, Mar 18, 2018 at 9:33 PM, Michał Wadas <michalwa...@gmail.com >> <mailto:michalwa...@gmail.com>> wrote: >> >> Fact: JSON allows arbitrary precision numbers. >> Problem: JavaScript is unable to express these numbers. >> >> Proposed solution: introduce JSON.safeParse. This method will work as >> JSON.parse, but throwing on values that can't be accurately represented by >> IEEE 754 64-bit float. >> >> Alternative: allow user to specify number class - eg. by adding >> options object with optional method "parseNumber", overwriting default >> behaviour of using builtin number type. >> >> Any thoughts on this? >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss@mozilla.org <mailto:es-discuss@mozilla.org> >> https://mail.mozilla.org/listinfo/es-discuss < >> https://mail.mozilla.org/listinfo/es-discuss> >> >> >> >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss@mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss >> >> >
_______________________________________________ es-discuss mailing list es-discuss@mozilla.org https://mail.mozilla.org/listinfo/es-discuss