I didn't have time to start reviewing this until late in the day, but I thought I'd send out a quick note: I suspect many of your return values are wrong.  In this case, when the function must return a struct, Emscripten transforms the function by adding an extra argument that points to where the return value should be stored.


See: https://github.com/google/pepper.js/blob/master/wrappers/base.js#L130

vs.

https://developer.chrome.com/native-client/pepper_stable/c/struct_p_p_b___var__1__2#a5c7ce303ae72998f54ba5da3357f7641


Any time you're returning a PP_Var by value, you will need to set the type and value fields of the result pointer.  (undefined or null PP_Var only need the type set, however.)  asm.js also doesn't have a string type, so the next return statement is also wrong - you'd need to return a PP_Var of type string containing an empty string value.  This will be a simplified version of the function I linked to, specialized for a specific value, and you probably want to put that in its own helper function.

Yes... all this poking at pointers is a pain in the butt.  :/  Ask if you have questions.