I am facing a problem with decode() on SharedArrayBuffer.
Code:
var sharedArrayBuffer = new SharedArrayBuffer(2);
var uint8Array = new Uint8Array(sharedArrayBuffer);
uint8Array[0] = 20;
var decoder = new TextDecoder();
decoder.decode(uint8Array);
Error:
Failed to execute 'decode' on 'TextDecoder': The provided ArrayBufferView value must not be shared.
There is a specification here that warns developers about race-condition on this type of memory. Can I somehow force decoding? I am sure data will not be changed during decoding. Or is there a workaround for this?
Reasons: I want to create a single copy of Uint8Array and pass it without copying via postmessage (which copies by default if transferrable is not specified) to several(>3) IFrames(with sandbox tag). Maybe there are other possible solutions?
Looks like using ArrayBuffer works fine.