Re: [whatwg/streams] reader.read() inside strategy.size() doesn't work (#794)

Huh. I share your intuition that this should work. And also that it's code that should never be written.

The full fix would be to do any necessary state checks immediately after calling size(). So I guess after step 4.b in [ReadableStreamDefaultControllerEnqueue](https://streams.spec.whatwg.org/commit-snapshots/89d32e228eb9428ae6f82793c875b1123febfc92/#readable-stream-default-controller-enqueue). Those checks would be... basically steps 2 and 3.

(Also interesting: what if someone releases the reader lock? Seems to work OK.)

I guess at a high level I see three choices:

1. Try to ensure size() is well-behaved. E.g. at one extreme we could have a boolean, [[sizeBeingCalled]], and make everything throw/fail if this flag is true.
2. Allow size() to do whatever it wants, and recover gracefully. So, insert the above checks.
3. Say that if size() is not well-behaved, the behavior will be unexpected (but well-specified). It will essentially be whatever is simplest to spec and implement, i.e. no extra checks.

I think we are currently going for (3). Although you could make an argument that handling exceptions thrown by size() at all, like we do now, is partially leaning toward (2).

I think I am OK with that. It'd be improved a bit if I got around to fixing #427.

We could also probably transition to (1) or (2) later if we really wanted, breaking only pathological code.

-- 
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/794#issuecomment-329705908

Received on Friday, 15 September 2017 07:36:33 UTC