Thanks! Yes, that is necessary too, adding.

(Sadly it's very hard to test closure issues like this, so I couldn't
verify myself...)

On Wed, Nov 20, 2019 at 1:22 AM Sampo Syrjänen <[email protected]>
wrote:

> Hi Alon, thanks for help! I tested the patch and got this from the test
>
> node test.js
> C:\work\closure\lib.js:28
>     throw b;
>     ^
>
> TypeError: WebAssembly.Table.set(): Argument 1 must be null or a
> WebAssembly function
>     at Object.a.addFunction (C:\work\closure\lib.js:630:7)
>     at Timeout._onTimeout (C:\work\closure\test.js:6:29)
>     at listOnTimeout (internal/timers.js:531:17)
>     at processTimers (internal/timers.js:475:7)
> gmake: *** [Makefile:9: test] Error 7
>
> I added one more change to the patch and then the test worked:
>
>   var module = new WebAssembly.Module(bytes);
>   var instance = new WebAssembly.Instance(module, {
>     'e': {
>       'f': func
>     }
>   });
>   var wrappedFunc = instance.exports['f'];
>   return wrappedFunc;
>
> So I changed instance.exports.f -> instance.exports['f'] and now it seems
> to work. In my tests, I applied the patch directly to 1.39.2, if that
> matters.
>
> On Tuesday, November 12, 2019 at 4:11:45 PM UTC+2, Sampo Syrjänen wrote:
>>
>> Hello! I have trouble getting addFunction to work with closure compiler
>> enabled. There's a minimal project here to reproduce the issue:
>>
>> // lib.c
>> typedef int (*callback_t)(int a);
>>
>> int func(callback_t callback, int a)
>> {
>>     return callback(a);
>> }
>>
>> // test.js
>> const lib = require("./lib.js");
>> setTimeout(() => {
>>     const callback = (a) => {
>>         return 40 + a;
>>     };
>>     const callbackPtr = lib.addFunction(callback, "ii");
>>     console.log(lib._func(callbackPtr, 2));
>> }, 100);
>>
>> # Makefile
>> lib.js: lib.c
>> emcc -s EXPORTED_FUNCTIONS="['_func']" -s
>> EXTRA_EXPORTED_RUNTIME_METHODS="['addFunction']" -s
>> RESERVED_FUNCTION_POINTERS=1 --closure 1 -o $@ $^
>>
>> .PHONY: clean
>> clean:
>> $(RM) lib.js lib.wasm
>>
>> test: lib.js
>> node test.js
>>
>>
>> With make test I get this:
>>
>> node test.js
>> C:\work\closure\lib.js:28
>>     throw b;
>>     ^
>>
>> LinkError: WebAssembly.Instance(): Import #0 module="e" function="f"
>> error: function import requires a callable
>>     at Object.a.addFunction (C:\work\closure\lib.js:629:10)
>>     at Timeout._onTimeout (C:\work\closure\test.js:6:29)
>> [90m    at listOnTimeout (internal/timers.js:531:17) [39m
>> [90m    at processTimers (internal/timers.js:475:7) [39m
>> gmake: *** [Makefile:9: test] Error 7
>>
>> What am I missing? How should I compile to make addFunction work?
>>
> --
> You received this message because you are subscribed to the Google Groups
> "emscripten-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/emscripten-discuss/e9b05fa7-8ab8-4593-9b6f-4bc212b2d0fd%40googlegroups.com
> <https://groups.google.com/d/msgid/emscripten-discuss/e9b05fa7-8ab8-4593-9b6f-4bc212b2d0fd%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/emscripten-discuss/CAEX4NpQPFavRcKSTu2BVb9gGzBwrh%2BFe2rcWO-7VBczm3cj10Q%40mail.gmail.com.

Reply via email to