-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
support passing ArrayBuffer to wasm module #1961
Comments
Thanks for the report! This is indeed not supported today, but seems plausible to me to support for |
I don't think we should be using Because if (e.data instanceof ArrayBuffer) {
const res = wasm.process_array_buffer(new Uint8Array(e.data));
console.log('worker: res', res);
} It's important to note that using |
that's right "only pay for what you use" philosophy works great inside c++/rust where we have strong type system. but here in js it just receives so currently passing besides, there's type checking for numeric arguments already function _assertNum(n) {
if (typeof(n) !== 'number') throw new Error('expected a number argument');
} maybe not implicit conversion, but type assertion should exist at least in debug build |
I completely agree, we should have runtime assertions in debug mode (not release mode). Silent errors are quite bad. |
Ran across this silent error today. |
I consider this a bug, happy to review a PR. |
i'm passing
ArrayBuffer
from browser window to worker thread, and then to wasm module function compiled with rust andwasm-pack
, but rust always receives buffer of zero length.rust function:
generated glue js:
worker.js:
so glue js expects typed array
Uint8Array
, but i'm passingArrayBuffer
, which doesn't have.length
prop but.byteLength
, etc.i'm working with
ArrayBuffer
because it's Transferable, andUint8Array
is not.as a workaround i can receive
ArrayBuffer
in worker, wrap it intoUint8Array
there and pass to wasm.but i believe glue js can check type of argument with
instanceof ArrayBuffer
, and pass it to wasm memory correctly.The text was updated successfully, but these errors were encountered: