Fix introspected (u)int64 types to use BigInt
One long-standing problem with GJS is that 64-bit integers can be exposed by gobject-introspection, but JS Numbers only support integers up to 53 bits (the largest integers that can be stored losslessly in a double). Since some time ago we have logged a warning whenever an integer larger than
Number.MAX_SAFE_INTEGER is received from C. For example:
gjs> imports.gi.GLib.MAXINT64 (gjs:1408): Gjs-WARNING **: 14:40:01.550: Value 9223372036854775807 cannot be safely stored in a JS Number and may be rounded 9223372036854776000
In SpiderMonkey 68 we are getting BigInt, which could be used to solve this problem. We will have to figure out how to expose this to GJS code in a backwards-compatible way, though.
For input arguments it's simple: accept both Numbers and BigInts for a 64-bit int parameter. For output arguments, though, you have to choose which one to return. All options have drawbacks:
- Always return Numbers (current behaviour): retains the current problems.
- Always return BigInts: it will be backwards incompatible, as
2n + 2will throw an exception.
- Return Number if the value is safe, and BigInt if it isn't: it is arguably backwards compatible, if we consider the case where you get the wrong value to be broken, sometimes returning one type and sometimes another type seems like a nightmare for API consumers.