embind and webldl not work on v8

17 views
Skip to first unread message

Wenqian Tian

unread,
May 13, 2019, 5:17:10 AM5/13/19
to emscripten-discuss
Hi,

I'm currently trying exploring expose C++ objects and classes to V8 Javascript engine using embind or webidl.

I use

emcc glue_wrapper.cc -s WASM=1 -s EXPORTED_FUNCTIONS="['_malloc']" --post-js glue.js --post-js post-script.js -o webidl.js

to create target js file and wasm. In order to run webidl.js file and load wasm file in v8, I modify the webidl.js a little, modify

function instantiateArrayBuffer(receiver) {
getBinaryPromise().then(function(binary) {
return WebAssembly.instantiate(binary, info);
}).then(receiver, function(reason) {
err('failed to asynchronously prepare wasm: ' + reason);
abort(reason);
});
}

to

function instantiateArrayBuffer(receiver) {
let module = new WebAssembly.Module(Module['wasmBinary']);
let instance = new WebAssembly.Instance(module, info);
receiveInstance(instance);
}

and Module['wasmBinary'] has already contained the binary data of target wasm file before load the webidl.js file.

I have load the target js file and wasm file successfully . But when I run the exported c++ class/method in js file, like this


var _t = new WebIDL(10, "YHSPY");
console.log(_t.getValueX());
console.log(_t.getValueStr());
Module.destroy(_t);

it reports

 Uncaught TypeError: Cannot read property 'apply' of undefined, location: webidl.js:0:0
    STACK:
    [0]asm._malloc   webidl.js:2242
    [1]Module._malloc webidl.js:2351
    [2]prepare webidl.js:2792
    [3]WebIDL webidl.js:2883
    [4]anonymous main.js:32

I have tried embind, but has similar problem. I use

emcc glue_wrapper.cc -s WASM=1 -s EXPORTED_FUNCTIONS="['_malloc']" --post-js glue.js --post-js post-script.js -o webidl.html

to create target html file and test it in brower. It works well.

can anyone give some help ?


Thanks,
wqtian
Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
0 new messages