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

unable to postMessage with webassembly module #11823

Closed
treethought opened this issue Aug 23, 2021 · 0 comments · Fixed by #12140
Closed

unable to postMessage with webassembly module #11823

treethought opened this issue Aug 23, 2021 · 0 comments · Fixed by #12140
Assignees
Labels
bug Something isn't working correctly deno_core Changes in "deno_core" crate are needed web related to Web APIs
Milestone

Comments

@treethought
Copy link

related to #9140, which was closed as structured cloning had not yet been implemented.

Now that #3557 has been implemented, I would expect the following to work given the following documentation:

  • A WebAssembly.Module object representing the compiled WebAssembly module.
    * This Module can be instantiated again, or shared via postMessage().

deno versions: 1.12.2 and 1.13.1

main.ts

const worker = new Worker(
  new URL("./worker.ts", import.meta.url).href,
  {
    name: "wasmWorker",
    type: "module",
  },
);

const wasmBuf = Deno.readFileSync("./test.wasm",);

const valid = WebAssembly.validate(wasmBuf);
console.log("valid", valid); // => true

WebAssembly.compile(wasmBuf).then((mod) => {
  console.log("sending module to worker");
  worker.postMessage({ "module": mod });
}).catch((err) => {
  console.log(err);
});

worker.ts

onmessage = function (e) {
  console.log("module received from main thread");
  console.log(e.data);
};

Result

➜ deno run -A test.ts
valid true
sending module to worker
DOMException: Failed to serialize response

Note that in the context this minimal example is based on, the message is DataCloneError: Failed to serialize response

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 deno_core Changes in "deno_core" crate are needed web related to Web APIs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants