Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WebAssembly.Module is [Serializable] except *forStorage* #18908

Closed
petamoriken opened this issue Apr 29, 2023 · 0 comments · Fixed by #18914
Closed

WebAssembly.Module is [Serializable] except *forStorage* #18908

petamoriken opened this issue Apr 29, 2023 · 0 comments · Fixed by #18914
Labels
bug Something isn't working correctly

Comments

@petamoriken
Copy link
Contributor

Deno KV can store [Serializable] values. WebAssembly.Module is [Serializable], but it is only supposed to be used for postMessage and is not allowed to be stored in storage.

The serialization steps, given value, serialized, and forStorage, are:

  1. If forStorage is true, throw a "DataCloneError" DOMException.
  2. Set serialized.[[Bytes]] to the sub-serialization of value.[[Bytes]].
  3. Set serialized.[[AgentCluster]] to the current Realm's corresponding agent cluster.

https://webassembly.github.io/spec/web-api/index.html#serialization


So the following code should throw a DataCloneError.

const importObject = {
  imports: { imported_func: (arg) => console.log(arg) },
};
const { module } = await WebAssembly.instantiateStreaming(
  fetch("https://mdn.github.io/webassembly-examples/js-api-examples/simple.wasm"),
  importObject,
);

const kv = await Deno.openKv();
await kv.set(["module"], module);
// => { ok: true, versionstamp: "00000000000000020000" }

And apparently, when I try to restart Deno and retrieve the value, I get a RangeError.

const kv = await Deno.openKv();
await kv.get(["module"]);
// Uncaught RangeError: could not deserialize value
//     at Object.deserialize (ext:core/01_core.js:490:43)
//     at deserializeValue (ext:deno_kv/01_db.ts:251:29)
//     at Kv.get (ext:deno_kv/01_db.ts:37:16)
//     at async <anonymous>:2:1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working correctly
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants