2017-03-17 72 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相同,以該版本爲模)。