sdk
sdk copied to clipboard
Using postMessage to pass SharedArrayBuffer throws UnimplementedError: structured clone of other type
Using postMessage on a Worker or MessagePort throws UnimplementedError: structured clone of other type . when passing a SharedArrayBuffer. This is when using dart2js to compile workers to javascript. I believe adding it here would fix the issue, but I don't know if there is more to do than just that of course.
https://github.com/dart-lang/sdk/blob/e995cb5f7cd67d39c1ee4bdbe95c8241db36725f/sdk/lib/html/html_common/conversions_dart2js.dart#L116-L117
I did work around it by manually editing the emitted js and adding the following line to the emitted code from dart2js.
// Opt out of structured cloning!
if(e instanceof SharedArrayBuffer) {
return e;
}
// This is the emitted js from cloneNotRequired
if (type$.NativeByteBuffer._is(e) || type$.NativeTypedData._is(e) || type$.MessagePort._is(e))
return e;
This is using Dart SDK version: 2.19.0-61.0.dev
Just to note: Javascript needs the original, not cloned, SharedArrayBuffer passed in the message, it also requires that it not be transferred via the transfer list in order to work properly.