Bug 147978

Summary: [Streams API] Update implementation with the latest spec
Product: WebKit Reporter: Xabier Rodríguez Calvar <calvaris>
Component: New BugsAssignee: Xabier Rodríguez Calvar <calvaris>
Status: RESOLVED FIXED    
Severity: Normal CC: benjamin, commit-queue, darin, ggaren, youennf
Priority: P2    
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 148075, 148078    
Attachments:
Description Flags
Patch
none
Patch
none
Patch none

Description Xabier Rodríguez Calvar 2015-08-13 09:08:48 PDT
ç[Streams API] Update implementation and tests with the latest spec
Comment 1 Xabier Rodríguez Calvar 2015-08-13 09:38:10 PDT
Created attachment 258892 [details]
Patch

Brought changes in the tests done at the reference. I left some of the custom ones cause I think they are not explicitely covered but I do think they are implicitly. Youenn, any opinion about leaving or removing them? I also fixed the implementation according to the latest changes in the spec.
Comment 2 youenn fablet 2015-08-13 11:20:15 PDT
(In reply to comment #1)
> Created attachment 258892 [details]
> Patch
> 
> Brought changes in the tests done at the reference. I left some of the
> custom ones cause I think they are not explicitely covered but I do think
> they are implicitly. Youenn, any opinion about leaving or removing them? I
> also fixed the implementation according to the latest changes in the spec.

It is a bit difficult to precisely check all the changes.
Could you split the patch in two:
1. Inverting the order of read/closed promise resolution (with updated related tests)
2. Updating other tests

It might not be necessary to move the read promises from ReadableStream to ReadableStreamReader.
The current design is to make controller and reader just dummy objects whose sole purpose is to expose specific parts of ReadableStream.
Comment 3 Xabier Rodríguez Calvar 2015-08-13 13:10:29 PDT
(In reply to comment #2)
> (In reply to comment #1)
> > Created attachment 258892 [details]
> > Patch
> > 
> > Brought changes in the tests done at the reference. I left some of the
> > custom ones cause I think they are not explicitely covered but I do think
> > they are implicitly. Youenn, any opinion about leaving or removing them? I
> > also fixed the implementation according to the latest changes in the spec.
> 
> It is a bit difficult to precisely check all the changes.
> Could you split the patch in two:
> 1. Inverting the order of read/closed promise resolution (with updated
> related tests)
> 2. Updating other tests

I can try that.

> It might not be necessary to move the read promises from ReadableStream to
> ReadableStreamReader.
> The current design is to make controller and reader just dummy objects whose
> sole purpose is to expose specific parts of ReadableStream.

The new spec says that you have to be able to resolve the promises belonging to a specific reader, so you have to track which promises belong to which reader.
Comment 4 youenn fablet 2015-08-14 00:46:22 PDT
A stream may have only one reader at a time. This allows storing pending requests in the stream itself.
A minor point is that the reader class (several instances per stream potentially) is made smaller.
Comment 5 Xabier Rodríguez Calvar 2015-08-14 05:59:16 PDT
Created attachment 258998 [details]
Patch

As Youenn suggested, I am splitting the patch in two. In the end it is true that we don't need to move the read pending requests to the reader. Basically I renamed the releaseReader into closeReader according to the spec and did the necessary changes in promise resolution order and object release.
Comment 6 youenn fablet 2015-08-14 12:26:59 PDT
(In reply to comment #5)
> Created attachment 258998 [details]
> Patch
> 
> As Youenn suggested, I am splitting the patch in two. In the end it is true
> that we don't need to move the read pending requests to the reader.
> Basically I renamed the releaseReader into closeReader according to the spec
> and did the necessary changes in promise resolution order and object release.

That looks mostly good to me.
I would make the following "fine-tuning" tweaks to changeStateToErrored:
1. m_state could be set earlier than what the patch is doing (no behavior impact but closer to spec).
2. after setting m_state to Errored, we could exit early if m_reader is null.

I would leave releaseReader renaming to another patch, as it might be good to rename  at the same time ReadableStream::close into finishClosing.
At the same time of renaming these methods, I would inline clearCallbacks. This would get us closer to the spec.
Comment 7 Xabier Rodríguez Calvar 2015-08-17 02:09:09 PDT
Created attachment 259140 [details]
Patch

Set m_state to Errored earlier, bailout if no m_reader and keep releaseReader as method name as suggested by Youenn.
Comment 8 Xabier Rodríguez Calvar 2015-08-17 02:54:38 PDT
(In reply to comment #6)
> 1. m_state could be set earlier than what the patch is doing (no behavior
> impact but closer to spec).

True, I mixed the reader and stream state. That's why I was setting it later.

I changed everything you requested and if reviewers agree, I think we are ready for a r+.
Comment 9 youenn fablet 2015-08-17 07:47:47 PDT
Sounds good to me.
Maybe rename the bug and update change logs accordingly, at cq time or updated patch if additional changes are required.
Comment 10 Xabier Rodríguez Calvar 2015-08-17 08:39:35 PDT
(In reply to comment #9)
> Sounds good to me.
> Maybe rename the bug and update change logs accordingly, at cq time or
> updated patch if additional changes are required.

I can do it, but I don't think it's even needed, as it is an update according to the spec, the only point is that we don't follow the same naming conventions, which is accessory.
Comment 11 WebKit Commit Bot 2015-08-18 01:25:29 PDT
Comment on attachment 259140 [details]
Patch

Clearing flags on attachment: 259140

Committed r188580: <http://trac.webkit.org/changeset/188580>
Comment 12 WebKit Commit Bot 2015-08-18 01:25:33 PDT
All reviewed patches have been landed.  Closing bug.
Comment 13 youenn fablet 2015-08-18 10:45:43 PDT
(In reply to comment #10)
> (In reply to comment #9)
> > Sounds good to me.
> > Maybe rename the bug and update change logs accordingly, at cq time or
> > updated patch if additional changes are required.
> 
> I can do it, but I don't think it's even needed, as it is an update
> according to the spec, the only point is that we don't follow the same
> naming conventions, which is accessory.

Bug title is a minor point but still useful.
It seems to me the title should help future developers grasp quickly the scope of the patch.

The current bug title seems to convey what you are trying to do (sync the impl with the spec), not what the patch is.
Something like "[Streams API] ReadableStreamReader read promises should be resolved before closed promise" might have been clearer.
Also, at some point, we may need again to "update implementation with the latest spec".

The same applies a bit to bug 148075 as well. How about something along the lines of "[Streams API] ReadableStream close methods should better match specification naming"?