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

Hmm, okay, this might be a bit trickier than I thought. 😅 

If we're going to transfer the port that we were using for the cross-realm transform readable/writable, we have to be absolutely sure that it no longer needs it inside the current realm. I can see this being a problem with [the current _writeAlgorithm_ for `SetUpCrossRealmTransformWritable`](https://github.com/whatwg/streams/blob/a08c1bcccbc56d60ed0b0cd7044b461f45587fc4/index.bs#L5969-L5977): it receives a chunk, *waits for backpressure to be relieved* and only then sends the chunk over the message port. If we neuter the port while it's waiting on the backpressure promise, then we will **lose the chunk**.

Also, the mere fact that we were waiting for backpressure is actually part of the stream's state, so we need to somehow transfer _that_ as well. We could keep a boolean flag to indicate whether there is backpressure or not, send that flag when transferring the stream, and use that when we transfer-receive the stream to initialize _backpressurePromise_ to either a pending or a resolved promise.

In other words: we need to carefully re-construct the cross-real transform readable/writable in **exactly the same state** as it was inside the realm from which we transferred.

-- 
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-656392681

Received on Thursday, 9 July 2020 23:05:46 UTC