threads icon indicating copy to clipboard operation
threads copied to clipboard

Why is buffer frozen?

Open domenic opened this issue 7 years ago • 2 comments

Let status be SetIntegrityLevel(buffer, "frozen").

What does this accomplish?

Note that freezing an ArrayBuffer does not prevent mutating its data:

const ab = new ArrayBuffer(20);
Object.freeze(ab);
const ta = new Uint8Array(ab);
ta[0] = 5; // works fine

So I'm not sure why you'd want to freeze the buffer. A note in the spec would be helpful explaining the purpose.

domenic avatar Aug 16 '18 18:08 domenic

Here's the discussion: https://github.com/WebAssembly/threads/pull/32#issuecomment-310238458

Another interesting point is that, because grow_memory can happen in other agents, it's quite racy which SAB you'll get on any given invocation of the .buffer getter. It seems like any use of expandos would be hazardous and I was thinking maybe the SAB returned by .buffer should be frozen. Identity is still observable (via ===) and expandos are still possible (via WeakMap), so this would just be a deterrent.

A note in the spec would be helpful explaining the purpose.

Sounds good.

binji avatar Aug 17 '18 17:08 binji

(whoops, meant to make a PR, clicked the wrong button)

binji avatar Aug 17 '18 18:08 binji