I haven't actually confirmed this, but from looking at the code, it seems we only care about whether a number has a fractional part in our int decoder. We don't make any attempt to do bounds checking.
I think this means that a JS date that has been encoded as a JSON number will succeed at decoding as an int, but the int will overflow and the actual value won't match the original JSON.
My gut says that we could convert a number -> int -> float and compare with the original, and that should work? e.g.
let isValidInt = num =>
float(int_of_float(num)) == num;
This compiles to:
function isValidInt(num) {
return (num | 0) === num;
}
And as far as I can tell, this returns the correct result for out-of-bounds numbers, and numbers both with and without fractional parts.
I haven't actually confirmed this, but from looking at the code, it seems we only care about whether a number has a fractional part in our
int
decoder. We don't make any attempt to do bounds checking.I think this means that a JS date that has been encoded as a JSON number will succeed at decoding as an int, but the int will overflow and the actual value won't match the original JSON.
My gut says that we could convert a number -> int -> float and compare with the original, and that should work? e.g.
This compiles to:
And as far as I can tell, this returns the correct result for out-of-bounds numbers, and numbers both with and without fractional parts.