FWIW - when I wrote the FFI for GPSEE (SpiderMonkey embedding), I supported
JS numbers -> int32 by checking for overflow at the coercion point
...something like this, if I recall correctly:
{
jsval v = getItFromJS();
jsdouble d = convertFromJSVAL(v);
int32_t i = d;
if (d != i)
return gpsee_throw('overflow');
doTheFFIThingWithTheInt32(&i);
}
This worked fine in practice on GCC. My dev platforms at the time were
ARM, x86, and SPARC. Maybe x86_64 too. It was a while ago.
On Wed, Jan 22, 2020 at 4:20 AM Fabrice Bellard <fabrice@xxxxxxxxxxx> wrote:
JS_IsInteger() was removed for a good reason : there is no integer type
in Javscript (except for the recently added BigInt type). So your code
should use either JS_IsNumber() (and use JS_ToInt64() or JS_ToFloat64()
depending if you need an int64 or a float64) or JS_IsBigInt() (and use
JS_ToBigInt64() to get the corresponding int64).
Best regards,
Fabrice.
On 1/21/20 10:42 PM, Fred Weigel wrote:
Updated documentation -- much more complete.
JS_IsInteger() is missing in QuickJS 2020-01-19. Function copied in
from QuickJS 2020-01-05.
Fixed ffidefine() to always return boolean.
Fred Weigel