Skip to content

Instantly share code, notes, and snippets.

@jayphelps
Last active January 20, 2018 01:59
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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"
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