3 ms·
> Please note that this specification assumes that JSON numbers may cover the full integer range of -2^63 … 2^64-1 without loss of precision (i.e. INT64_MIN … U
by Valodim 1y ago
> Please note that this specification assumes that JSON numbers may cover the full integer range of -2^63 … 2^64-1 without loss of precision (i.e. INT64_MIN … UINT64_MAX). Please read, write and process user records as defined by this specification only with JSON implementations that provide this number range.
Wait, so.. not javascript?
- chao- 1y agoInteresting catch. Don't many desktop Linux utilities from the GNOME project use JavaScript?
- mpyne 1y agoAnd from KDE as well, through Qt's Qt Declarative libraries that use QML. Judging by the Qt source, if the internal JS runtime JSON parser is used then it will not support full range of 64-bit integers, since the double floating point type is used for any integers x where abs(x) > 1^^25.
- stonogo 1y agoMost (all?) systems running systemd are going to have a javascript interpreter as a polkit dependency anyway.
- deathanatos 1y agoIt's not the default, but JS is capable of this. (JavaScript has a big integer type nowadays, and the JSON.parse function's "reviver" parameter I think should be capable of parsing to bigints, but you'd need to specify such a reviver.) Something like this, I think: JSON.parse( /* just a test input JSON */ `{"a": 1.1, "b": 22222222222222222222222222222222, "c": {"d": 999999999999999999999999}}`, /* a reviver that returns BigInts, if it's an integer. */ (key, value, context) => { if(typeof value === "number" && /^[0-9]+$/.test(context.source)) { return BigInt(context.source); } else { return value; } } );