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

-- 
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/119c38c9-afdf-4e94-9a6b-bf956e12ddcd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to