Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.Sign up
misc/wasm: js.TypedArrayOf is impossible to use correctly #31980
However, quoting from syscall/js:
CL 174304 works around one instance of this problem and replaced the typed array with a copy. Converting our bufferData call above in a similar way gives:
However, the above still results in rare crashes, leading me to suspect that there is no way to use TypedArrayOf correctly. I failed to produce a minimal test program, but I believe a modified version of Gio is enough to demonstrate the issue.
The relevant code is
The runtime.GC call is required to reproduce the crash every run, but in my case the crash happens even in the browser and without the runtime.GC call.
If I'm right, CL 174304 merely narrows the window for a crash, and #31812 is difficult to fix.
In order of preference, I propose one of:
Yes, I agree that this is currently a bad situation.
The most safe approach right now would probably be to remove
Have you considering my second proposal above? Namely: expand syscall/js.Value.Call (and Invoke) to accept Go slices, which are atomically wrapped in a TypedArray before being passed to the native side. I believe that's a strictly better option than explicit copy to/from JS:
where the Call atomically transfers the slice
The problem with the second approach is that it will still cause issues if the function that you are calling is using the typed array asynchronously. For example it would not have prevented #31702. I currently believe that there are quite some APIs like this. Your example with