-
Notifications
You must be signed in to change notification settings - Fork 332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Be clearer about how Fetch creates ReadableStreams. #781
Conversation
Yes, I need to change this to use CreateReadableStream() but I haven't done it yet. Sorry. |
46e1be1
to
3f3479e
Compare
3f3479e
to
a3e0245
Compare
@ricea Here's a terrible attempt at calling CreateReadableStream(). With some more work, it's probably possible to simplify that wording. |
fetch.bs
Outdated
@@ -1876,18 +1876,45 @@ with given <var>strategy</var>, <var>pull</var> action and <var>cancel</var> act | |||
are optional, run these steps: | |||
|
|||
<ol> | |||
<li><p>Let <var>init</var> be a new object. | |||
<li><p>Let <var>startAlg</var> be an algorithm that returns <code>undefined</code>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I find it clearer just to write out "startAlgorithm" in full.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
fetch.bs
Outdated
<li><p>Let <var>stream</var> be the result of calling the initial value of {{ReadableStream}} as | ||
constructor with <var>init</var> and <var>strategy</var> if given. | ||
<li><p>Let <var>highWaterMark</var> be: | ||
<dl class=switch> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The need to unpack the strategy argument is unfortunate. If the reference in HTTP-Network-Fetch is the only usage, I would prefer to change that from the (scary) phrasing:
Let strategy be an object. The user agent may choose any object.
to something like
Let highWaterMark be a be a non-negative, non-NaN number, chosen by the user agent.
Let sizeAlgorithm be an algorithm that accepts chunk objects and returns a number, chosen by the user agent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. I didn't do that because I'm nervous about other callers outside Fetch, but I could leave a note here about the previous state and expect them to update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done this and added the note.
fetch.bs
Outdated
<var>cancel</var> is given. | ||
<dl class=switch> | ||
<dt>If <var>pull</var> is given | ||
<dd>the result of [=promise-calling=] <var>pull</var>(). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@annevk usually objects to using the promises guide. However, I don't see much alternative except for copying the phrasing that the promises guide uses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's also https://streams.spec.whatwg.org/#promise-call, but it requires a non-undefined
object parameter. @domenic, it looks like the underlying https://tc39.github.io/ecma262/#sec-call can take undefined there; would it make sense to allow that in PromiseCall()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very out-of-context question: What is the reasoning for objection to using the promises guide? Haven't read all of it, just curious (sorry this is not the best place).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@domfarolino Possibly w3ctag/promises-guide#52.
I know of one trap in there: because aggregating promises uses Promise.all()
it calls the current (not original) value of Promise.reject()
which may have been replaced. This makes it unsafe to use in algorithms that are not re-entrant or are otherwise vulnerable to unexpected JS execution.There may be other traps I don't know about.
Having said that, we use it in the streams standard and I think it is fine if you use it with care.
This is not so terrible. It seems pretty close to usable to me. Some more bad news: the difference is actually observable if |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ricea I'd appreciate if you'd write the web platform test. I'd probably need to do it in November after coming back from leave.
fetch.bs
Outdated
@@ -1876,18 +1876,45 @@ with given <var>strategy</var>, <var>pull</var> action and <var>cancel</var> act | |||
are optional, run these steps: | |||
|
|||
<ol> | |||
<li><p>Let <var>init</var> be a new object. | |||
<li><p>Let <var>startAlg</var> be an algorithm that returns <code>undefined</code>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
fetch.bs
Outdated
<var>cancel</var> is given. | ||
<dl class=switch> | ||
<dt>If <var>pull</var> is given | ||
<dd>the result of [=promise-calling=] <var>pull</var>(). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's also https://streams.spec.whatwg.org/#promise-call, but it requires a non-undefined
object parameter. @domenic, it looks like the underlying https://tc39.github.io/ecma262/#sec-call can take undefined there; would it make sense to allow that in PromiseCall()
?
fetch.bs
Outdated
<li><p>Let <var>stream</var> be the result of calling the initial value of {{ReadableStream}} as | ||
constructor with <var>init</var> and <var>strategy</var> if given. | ||
<li><p>Let <var>highWaterMark</var> be: | ||
<dl class=switch> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done this and added the note.
Okay, I will write the web platform test tomorrow. This structurally looks good to me. I'm not sure whether we can leave a note in there. Last time I checked, the only spec relying on this was the service worker one. Maybe we can just file an issue there to update? I think the markup will need some nitpicking, which I will leave to @annevk. |
Test that setting Object.prototype.start to a function that throws doesn't interfere with fetch operations that create a stream. Similarly, verify that setting throwing accessors for 'type', 'size', and 'highWaterMark' doesn't cause problems. See whatwg/fetch#781 for background.
PR for the web platform test: web-platform-tests/wpt#12350 |
So https://w3c.github.io/ServiceWorker/ invokes this algorithm with strategy. I guess now it'd have to omit that argument, but still supply pull and cancel? It seems rather muddy that this ends up using named arguments therefore. I think I'd rather we make them non-optional and require passing null. @domenic what do you think? |
PR to update the ServiceWorker standard to match: w3c/ServiceWorker#1338. |
Hmm yeah I didn't quite get the named arguments thing before. I dunno, this is OK-ish for now... Definitely a big improvement over the previous situation. I think the whole area of how streams interfaces with other specs needs a re-think, but I've been putting that off forever. Also worth noting that, it seems like the idea of this wrapper, versus just using CreateReadableStream directly, is:
|
I'm making use of streams in background fetch, eg step 7 of https://wicg.github.io/background-fetch/#create-settled-fetches-algorithm, which is streaming an item from storage that may still be writing from another algorithm. It felt like I wanted to kind of spec-level stream concept, but I haven't thought too much about it. Anyway, the changes here don't disrupt background-fetch. The change is pretty easy. |
The named arguments don't bother me. I think this is a clear improvement on the status quo. As @domenic said, longer term we have to figure out a better way for other standards to talk about streams. I think this will tide us over in the meantime. |
Update the strategy argument to 'construct a ReadableStream' according to whatwg/fetch#781.
Test that setting Object.prototype.start to a function that throws doesn't interfere with fetch operations that create a stream. Similarly, verify that setting throwing accessors for 'type', 'size', and 'highWaterMark' doesn't cause problems. See whatwg/fetch#781 for background.
…fere with fetch streams, a=testonly Automatic update from web-platform-testsFetch: Object.prototype shouldn't interfere with fetch streams Test that setting Object.prototype.start to a function that throws doesn't interfere with fetch operations that create a stream. Similarly, verify that setting throwing accessors for 'type', 'size', and 'highWaterMark' doesn't cause problems. See whatwg/fetch#781 for background. -- wpt-commits: ba582388f4506ea2c8341dac4d8ce6e5eb39871b wpt-pr: 12350
…fere with fetch streams, a=testonly Automatic update from web-platform-testsFetch: Object.prototype shouldn't interfere with fetch streams Test that setting Object.prototype.start to a function that throws doesn't interfere with fetch operations that create a stream. Similarly, verify that setting throwing accessors for 'type', 'size', and 'highWaterMark' doesn't cause problems. See whatwg/fetch#781 for background. -- wpt-commits: ba582388f4506ea2c8341dac4d8ce6e5eb39871b wpt-pr: 12350
…fere with fetch streams, a=testonly Automatic update from web-platform-testsFetch: Object.prototype shouldn't interfere with fetch streams Test that setting Object.prototype.start to a function that throws doesn't interfere with fetch operations that create a stream. Similarly, verify that setting throwing accessors for 'type', 'size', and 'highWaterMark' doesn't cause problems. See whatwg/fetch#781 for background. -- wpt-commits: ba582388f4506ea2c8341dac4d8ce6e5eb39871b wpt-pr: 12350
…fere with fetch streams, a=testonly Automatic update from web-platform-testsFetch: Object.prototype shouldn't interfere with fetch streams Test that setting Object.prototype.start to a function that throws doesn't interfere with fetch operations that create a stream. Similarly, verify that setting throwing accessors for 'type', 'size', and 'highWaterMark' doesn't cause problems. See whatwg/fetch#781 for background. -- wpt-commits: ba582388f4506ea2c8341dac4d8ce6e5eb39871b wpt-pr: 12350
…fere with fetch streams, a=testonly Automatic update from web-platform-testsFetch: Object.prototype shouldn't interfere with fetch streams Test that setting Object.prototype.start to a function that throws doesn't interfere with fetch operations that create a stream. Similarly, verify that setting throwing accessors for 'type', 'size', and 'highWaterMark' doesn't cause problems. See whatwg/fetch#781 for background. -- wpt-commits: ba582388f4506ea2c8341dac4d8ce6e5eb39871b wpt-pr: 12350 UltraBlame original commit: a2a4a8d57735d173482c452d09ae4eb57ecfe1fe
…fere with fetch streams, a=testonly Automatic update from web-platform-testsFetch: Object.prototype shouldn't interfere with fetch streams Test that setting Object.prototype.start to a function that throws doesn't interfere with fetch operations that create a stream. Similarly, verify that setting throwing accessors for 'type', 'size', and 'highWaterMark' doesn't cause problems. See whatwg/fetch#781 for background. -- wpt-commits: ba582388f4506ea2c8341dac4d8ce6e5eb39871b wpt-pr: 12350 UltraBlame original commit: d03965cb9d48c88a94030dc00aa15d01b50f63a8
…fere with fetch streams, a=testonly Automatic update from web-platform-testsFetch: Object.prototype shouldn't interfere with fetch streams Test that setting Object.prototype.start to a function that throws doesn't interfere with fetch operations that create a stream. Similarly, verify that setting throwing accessors for 'type', 'size', and 'highWaterMark' doesn't cause problems. See whatwg/fetch#781 for background. -- wpt-commits: ba582388f4506ea2c8341dac4d8ce6e5eb39871b wpt-pr: 12350 UltraBlame original commit: a2a4a8d57735d173482c452d09ae4eb57ecfe1fe
…fere with fetch streams, a=testonly Automatic update from web-platform-testsFetch: Object.prototype shouldn't interfere with fetch streams Test that setting Object.prototype.start to a function that throws doesn't interfere with fetch operations that create a stream. Similarly, verify that setting throwing accessors for 'type', 'size', and 'highWaterMark' doesn't cause problems. See whatwg/fetch#781 for background. -- wpt-commits: ba582388f4506ea2c8341dac4d8ce6e5eb39871b wpt-pr: 12350 UltraBlame original commit: d03965cb9d48c88a94030dc00aa15d01b50f63a8
…fere with fetch streams, a=testonly Automatic update from web-platform-testsFetch: Object.prototype shouldn't interfere with fetch streams Test that setting Object.prototype.start to a function that throws doesn't interfere with fetch operations that create a stream. Similarly, verify that setting throwing accessors for 'type', 'size', and 'highWaterMark' doesn't cause problems. See whatwg/fetch#781 for background. -- wpt-commits: ba582388f4506ea2c8341dac4d8ce6e5eb39871b wpt-pr: 12350 UltraBlame original commit: a2a4a8d57735d173482c452d09ae4eb57ecfe1fe
…fere with fetch streams, a=testonly Automatic update from web-platform-testsFetch: Object.prototype shouldn't interfere with fetch streams Test that setting Object.prototype.start to a function that throws doesn't interfere with fetch operations that create a stream. Similarly, verify that setting throwing accessors for 'type', 'size', and 'highWaterMark' doesn't cause problems. See whatwg/fetch#781 for background. -- wpt-commits: ba582388f4506ea2c8341dac4d8ce6e5eb39871b wpt-pr: 12350 UltraBlame original commit: d03965cb9d48c88a94030dc00aa15d01b50f63a8
It could be that this should call https://streams.spec.whatwg.org/#create-readable-stream or https://streams.spec.whatwg.org/#create-readable-byte-stream (#267?) instead of trying to go through the
ReadableStream()
constructor, with all the ambiguity about how modifyingObject
's prototype should affect things.@domenic
Preview | Diff