v8.deserialize on WebAssembly module fails with "Unable to deserialize cloned data" · Issue #18265 · nodejs/node (original) (raw)
- Version: v9.4.0
- Platform: 16.6.0 Darwin Kernel Version 16.6.0; root:xnu-3789.60.24~6/RELEASE_X86_64 x86_64
- Subsystem: Serialization API (experimental)
Online REPL Reproduction
Using the experimental Serialization API calling v8.serialize(module)
on a WebAssembly module works, however trying to then deserialize it v8.deserialize(buffer)
fails with Error: Unable to deserialize cloned data.
.
From what I gather, node is using a newly exposed API from v8, so it's possible that exposed API is to blame. Although, v8 itself supports it within its internal APIs and the --wasm_disable_structured_cloning flag is exposed in node v9.4.0 with the expected value of false
(don't disable aka is enabled)
node --v8-options
...
--wasm_disable_structured_cloning (disable wasm structured cloning)
type: bool default: false
# false means structured cloning aka serialization is NOT disabled AFAIK -jayphelps
const v8 = require('v8');
// only putting a simple wasm binary inline so it's easy to reproduce const theModule = new WebAssembly.Module(new Uint8Array([ 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00 ]));
const buffer = v8.serialize(theModule); v8.deserialize(buffer); // "Error: Unable to deserialize cloned data."
A bit more real world example, for those curious:
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();
This is supported in browsers via postMessage
or saving them into IndexedDB
No urgency on my part, just logging mostly curious if someone can point me in the right direction codewise and I'll take a peek. I went down the rabbit hole on my own and didn't immediately see anything that would have prohibited support.
Cc/ @kwonoj