4 ms·
FFI calls are just like normal calls: they need a coercion on them. i = ffiFunc() | 0; // returns an int d = +ffiFunc(); // returns a double This i
by azakai 12y ago
FFI calls are just like normal calls: they need a coercion on them.
i = ffiFunc() | 0; // returns an int
d = +ffiFunc(); // returns a double
This is identical for FFI and non-FFI calls. A difference though is that asm functions have specific types (an asm function returns either nothing, an int, or a double). But an FFI is just any old JS function. So you could not write the above 2 lines together with an asm function, only an FFI can get an int one time and a double another time from the same function.
- jvilk 12y agoUnderstood. If `ffiFunc()` returns an empty array at a double call site, does ASM.js just accept it as `0`? (`+[]` is `0`). Or are there runtime checks that verify that the return value is a numeric type? btw, I hope these questions make it clearer why I grumped a bit about the specification, and result in a more robust spec!