Last active
January 20, 2018 01:59
-
-
Save jayphelps/cfc66b39cdd45187df936fec545df447 to your computer and use it in GitHub Desktop.
WebAssembly structured clone node.js v8 serialize deserialize "Unable to deserialize cloned data"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const v8 = require('v8'); | |
const fs = require('fs'); | |
function writeDemo() { | |
const module = new WebAssembly.Module(new Uint8Array([ | |
0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00 | |
])); | |
const buffer = v8.serialize(module); | |
fs.writeFileSync('cached-wasm-module.buffer', buffer); | |
} | |
function readDemo() { | |
const buffer = fs.readFileSync('cached-wasm-module.buffer'); | |
const module = new WebAssembly.Module(v8.deserialize(buffer)); | |
const instance = new WebAssembly.Instance(module); | |
} | |
writeDemo(); | |
readDemo(); | |
/* | |
// Currently trying to deserialize the buffer fails... | |
const buffer = v8.serialize(module); | |
v8.deserialize(buffer); | |
// "Error: Unable to deserialize cloned data." | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment