asm-js / validator

A reference validator for asm.js.
Apache License 2.0
1.78k stars 154 forks source link

Allow lookup of asm.js function by function table name and function pointer #83

Open chadaustin opened 10 years ago

chadaustin commented 10 years ago

Hi,

I spent the weekend porting embind to work with emscripten's fastcomp/asm.js compiler ( https://github.com/kripken/emscripten/pull/2287 ) and ran into an asm.js limitation that adds an unnecessary layer of overhead.

embind's fundamental use case is to look up a function object, given a function table name and a function pointer value (that is, index into a function table).

It needs this to wrap and expose said function to JavaScript.

Ideally, the function tables themselves could be exported by the asm.js module. But function tables are immutable, so this would likely defeat browser optimizations.

Instead, @juj proposed allowing export of read-only slices of function tables. That is:

return {
    ...
    'FUNCTION_TABLE_viii': FUNCTION_TABLE_viii.slice()
}

Are there any disadvantages to modifying the spec to allow this?

juj commented 10 years ago

Btw, with either FUNCTION_TABLE_viii or FUNCTION_TABLE_viii.slice(), do/did you currently get an asm.js validation error in practice in Firefox? (just curious about how it's working out in concrete manner atm) I wonder if there's a easy way/shortcut that could be used to benchmark what the difference to a dynCall approach is in practice?

chadaustin commented 10 years ago

I don't have my test VM with me, but I did see a validation error. Something about a type mismatch: I don't remember the error message being particularly clear.

The asm.js spec says only a single function or an object with function values can be exported, so that makes sense.