3 ms·
Follow-up question. How does it deduce the return type of a foreign function? Can foreign functions return values? Normally, ASM.js functions require an annot
by jvilk 12y ago
Follow-up question.
How does it deduce the return type of a foreign function? Can foreign functions return values?
Normally, ASM.js functions require an annotation on the return statement [0].
[0] http://asmjs.org/spec/latest/#return-type-annotations http://asmjs.org/spec/latest/#return-type-annotations
- azakai 12y agoFFI 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!