Skip to content
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

Merged
merged 4 commits into from
Aug 10, 2018

Conversation

jyasskin
Copy link
Member

@jyasskin jyasskin commented Aug 1, 2018

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 modifying Object's prototype should affect things.

@domenic


Preview | Diff

@ricea
Copy link
Collaborator

ricea commented Aug 2, 2018

Yes, I need to change this to use CreateReadableStream() but I haven't done it yet. Sorry.

@jyasskin jyasskin force-pushed the ReadableStream-construction branch from 46e1be1 to 3f3479e Compare August 3, 2018 21:57
@jyasskin jyasskin force-pushed the ReadableStream-construction branch from 3f3479e to a3e0245 Compare August 3, 2018 21:57
@jyasskin
Copy link
Member Author

jyasskin commented Aug 3, 2018

@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>.
Copy link
Collaborator

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.

Copy link
Member Author

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>
Copy link
Collaborator

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.

Copy link
Member Author

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.

Copy link
Member Author

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>().
Copy link
Collaborator

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.

Copy link
Member Author

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()?

Copy link
Member

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).

Copy link
Collaborator

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.

@ricea
Copy link
Collaborator

ricea commented Aug 6, 2018

This is not so terrible. It seems pretty close to usable to me.

Some more bad news: the difference is actually observable if Object.prototype.start or Object.prototype.type is set. This is one motivation for moving to CreateReadableStream(). Someone needs to write a web platform test for this. I can do it if there are no other volunteers.

Copy link
Member Author

@jyasskin jyasskin left a 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>.
Copy link
Member Author

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>().
Copy link
Member Author

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>
Copy link
Member Author

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.

@ricea
Copy link
Collaborator

ricea commented Aug 7, 2018

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.

jyasskin added a commit to jyasskin/ServiceWorker that referenced this pull request Aug 7, 2018
ricea added a commit to ricea/web-platform-tests that referenced this pull request Aug 8, 2018
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.
@ricea
Copy link
Collaborator

ricea commented Aug 8, 2018

PR for the web platform test: web-platform-tests/wpt#12350

@jyasskin jyasskin changed the title Be clearer about the underlying source of a constructed ReadableStream. Be clearer about Fetch creates ReadableStreams. Aug 8, 2018
@jyasskin jyasskin changed the title Be clearer about Fetch creates ReadableStreams. Be clearer about how Fetch creates ReadableStreams. Aug 8, 2018
@annevk
Copy link
Member

annevk commented Aug 9, 2018

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?

@ricea
Copy link
Collaborator

ricea commented Aug 9, 2018

PR to update the ServiceWorker standard to match: w3c/ServiceWorker#1338.

@domenic
Copy link
Member

domenic commented Aug 9, 2018

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:

  • Omits startAlgorithm
  • Uses named arguments so that pullAlgorithm, and cancelAlgorithm become optional
  • Allows pullAlgorithm and cancelAlgorithm to return non-promises

@annevk
Copy link
Member

annevk commented Aug 9, 2018

Thanks @ricea, that looks good (modulo Oxford comma). Thoughts on my nit commit?

I guess I'm okay with merging this given @domenic's feedback.

@jakearchibald
Copy link
Collaborator

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.

@ricea
Copy link
Collaborator

ricea commented Aug 10, 2018

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.

@annevk annevk merged commit 6b31c45 into whatwg:master Aug 10, 2018
jyasskin added a commit to jyasskin/ServiceWorker that referenced this pull request Aug 13, 2018
@jyasskin jyasskin deleted the ReadableStream-construction branch August 13, 2018 02:52
jungkees pushed a commit to w3c/ServiceWorker that referenced this pull request Aug 13, 2018
Update the strategy argument to 'construct a ReadableStream' according to whatwg/fetch#781.
annevk pushed a commit to web-platform-tests/wpt that referenced this pull request Sep 20, 2018
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.
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Sep 24, 2018
…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
xeonchen pushed a commit to xeonchen/gecko-cinnabar that referenced this pull request Sep 25, 2018
…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
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Sep 25, 2018
…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
julienw pushed a commit to julienw/mozilla-central that referenced this pull request Sep 26, 2018
…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
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Oct 3, 2019
…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
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Oct 3, 2019
…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
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Oct 3, 2019
…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
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Oct 3, 2019
…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
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Oct 3, 2019
…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
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Oct 3, 2019
…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

6 participants