streams: fixes for webstreams
Follow-up on #50126.
- Avoid
PromiseResolve
inensureIsPromise
. Web IDL requires this to always return a newPromise
, whereasPromiseResolve
may return the samePromise
. This leads to a different timing, sincenew Promise()
takes at least one microtask to resolve. See my previous comment. - Fix handling sync errors from source cancel and sink abort. We were not correctly handling synchronously-thrown errors from these, which could leave the stream in an incorrect state.
- Check for promise only when constructing from source/sink/transformer. When constructing an internal stream, these algorithms must always return a promise, and we shouldn't wrap them again with
ensureIsPromise()
. - Fix
TeeReadableStream
. This should construct an internal stream with internal callbacks usingsetupReadableStreamDefaultController
, but it was incorrectly using user-land callbacks withsetupReadableStreamDefaultControllerFromSource
. - Use internal streams for teeing a readable byte stream. This was using the user-land
ReadableStream
constructor, which is incorrect. The new implementation mirrors how we handle teeing "default" readable streams. - Use internal streams for
ReadableStream.from()
. Again, this was incorrectly using the user-landReadableStream
constructor. - Use internal streams for
TransformStream
. Same thing again. - Add a helper to create the internal state of a
ReadableStream
andWritableStream
. This code was duplicated a few times, so it made sense to extract a helper function. - Remove an unused field in the
ReadableStream
internal state. This seemed like a copy-paste mistake: other classes (likeReadableStreamDefaultController
) do have astream
field in their state, butReadableStream
shouldn't. - Fix validating callbacks. Previously, we asserted that the given callbacks were indeed
typeof callback === "function"
by virtue of bluntly trying to callFunctionPrototypeBind
on them. We no longer useFunctionPrototypeBind
for this, so we need to manually callvalidateFunction
for each callback. I've wrapped that in acreatePromiseCallback
helper. - Update expectations for the Streams WPT tests.