2017-03-17 71 views
1

我试图在node.js中运行webassembly模块,并且得到Wasm decoding failedResult。我认为我的问题是将节点Buffer转换为ArrayBuffer。这里是我的应用代码:当我使用emcc hello_world.c -s WASM=1 -o hello.html我可以加载的模块,并在浏览器中运行它编译hello world到wasm并在节点中运行

(relevant details) 

Wasm decoding failedResult = expected version 0c 00 00 00, found 01 00 00 00 @+4 

fs.readFileAsync(WASM_PATH) 
    .then(buf => buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength)) 
    .then(arrayBuffer => Wasm.instantiateModule(arrayBuffer)) 
    .then(results => console.log(results.instance)) 
    .catch(err => console.error(err)); 

我得到这个错误。所以,我很确定这是我的一个问题,或者可能是一些兼容性问题。提前致谢。

回答

2

您的节点版本使用版本为0xC的版本较早的V8版本的V8。您的工具链发出now-stable MVP version 0x1

节点roughly follows Chrome releasesChrome 57增加了对MVP WebAssembly的支持。该页面说,Chrome 57的V8版本是5.7.492.65。

因此对MVP的支持迫在眉睫。

或者,您可以使用旧的Emscripten工具链。这将是非常古老的:0xd是MVP之前的版本(并且0xd实际上与MVP相同,以该版本为模)。