Re: [whatwg/streams] can streams be transferred via postMessage()? (#276)

Sorry, I'm pretty behind on the discussion. Please allow me to ask some stupid questions to try and get caught up...

From what I understand we're considering a situation like this:

```js
// in window
const s = new ReadableStream({ start(c) { c.error(); } });
frames[0].postMessage(s, [s]);

// in frames[0]
worker.postMessage(s, [s]);
```

I guess what I'm envisioning is that in `frames[0]`, the transfer steps for `s` would send the `frames[0]` `MessagePort` to `worker`, alongside `s`'s [[state]] and [[storedError]]. Then those values make their way to the transfer-recieving steps, at which point SetUpCrossRealmTransformReadable would go poke around the internals of the newly-created _stream_ and set its [[state]] and [[storedError]] to the values.

(I was initially thinking that the transfer-recieving steps would dispatch a synthetic message event on the MessagePort that was something like `{ type: "reestablish state", value: { state, storedError } }`, but I think that's messier...)

> Then add in the fact that there may be a message in transit from the original realm that's trying to change our state at the same time we're trying to clone it and the whole thing becomes very painful.

I feel like this should all be handled by HTML's (and implementations') existing infrastructure. As long as we reestablish the state that was last seen before any such state-changing messages arrive, everything would be consistent, and HTML gives us the ordering guarantees needed to make that possible.

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/streams/issues/276#issuecomment-656340901

Received on Thursday, 9 July 2020 20:42:11 UTC