Bug 143363 - [Streams API] ReadableStream constructor start function should be able to close the stream
Summary: [Streams API] ReadableStream constructor start function should be able to clo...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: youenn fablet
URL:
Keywords:
Depends on: 141160 143714 143774
Blocks:
  Show dependency treegraph
 
Reported: 2015-04-03 00:19 PDT by youenn fablet
Modified: 2015-04-27 06:33 PDT (History)
4 users (show)

See Also:


Attachments
Patch (14.85 KB, patch)
2015-04-03 04:52 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (16.85 KB, patch)
2015-04-09 03:36 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch for landing (16.21 KB, patch)
2015-04-14 05:58 PDT, youenn fablet
no flags Details | Formatted Diff | Diff
Patch (15.37 KB, patch)
2015-04-23 02:00 PDT, Xabier Rodríguez Calvar
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description youenn fablet 2015-04-03 00:19:52 PDT
Support for the close function passed as parameter to "start" and "pull" source functions should be implemented.
THis should end up putting the stream and reader in closed state and fulfilling the reader closed promise.
Comment 1 youenn fablet 2015-04-03 04:52:58 PDT
Created attachment 250060 [details]
Patch
Comment 2 youenn fablet 2015-04-09 03:36:15 PDT
Created attachment 250434 [details]
Patch
Comment 3 Benjamin Poulain 2015-04-09 21:51:17 PDT
Comment on attachment 250434 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=250434&action=review

Very quick review. Something is fishy. If that's right, please add tests for the controller.

Can you please add the type exception on errored? It is not testable yet, but it may be harder to forget if there is already if branch for it.

> Source/WebCore/Modules/streams/ReadableStream.cpp:61
> +void ReadableStream::changeStateToClosed()

How will you raise the TypeError when closeRequested == true or state == "errored"?

> Source/WebCore/bindings/js/ReadableStreamJSSource.cpp:127
> +    getReadableJSStream(exec).changeStateToClosed();
> +    return JSValue::encode(jsUndefined());

Hum, reading the spec side by side with the code...I don't think that is quite correct.

Say I keep the function close in a variable close. I could do:
    close.call("foobar");
and that would still close the original stream.

The specs says to get the internal slot on the this object. If the this object is not a controller:
    If IsReadableStreamController(this) is false, throw a TypeError exception.

Note that this also let you do close.call(otherController) to close the controller of one object with the close function from an other object.

If I am reading this correctly, you need to have the internal slot on the controller object, and get it out through the this object.
Comment 4 youenn fablet 2015-04-10 03:31:55 PDT
(In reply to comment #3)
> Comment on attachment 250434 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=250434&action=review
> 
> Very quick review. Something is fishy. If that's right, please add tests for
> the controller.
> 
> Can you please add the type exception on errored? It is not testable yet,
> but it may be harder to forget if there is already if branch for it.
> 
> > Source/WebCore/Modules/streams/ReadableStream.cpp:61
> > +void ReadableStream::changeStateToClosed()
> 
> How will you raise the TypeError when closeRequested == true or state ==
> "errored"?
> 
> > Source/WebCore/bindings/js/ReadableStreamJSSource.cpp:127
> > +    getReadableJSStream(exec).changeStateToClosed();
> > +    return JSValue::encode(jsUndefined());
> 
> Hum, reading the spec side by side with the code...I don't think that is
> quite correct.
> 
> Say I keep the function close in a variable close. I could do:
>     close.call("foobar");
> and that would still close the original stream.
> 
> The specs says to get the internal slot on the this object. If the this
> object is not a controller:
>     If IsReadableStreamController(this) is false, throw a TypeError
> exception.
> 
> Note that this also let you do close.call(otherController) to close the
> controller of one object with the close function from an other object.
> 
> If I am reading this correctly, you need to have the internal slot on the
> controller object, and get it out through the this object.

You are reading correctly.
I was expecting to first do that patch and then upgrade the controller implementation so that it matches the spec and ensure close is still working.
But I can do it the other way as well.

For the controller, I am not yet sure whether going the IDL way or making a full custom implementation of it.
Comment 5 Benjamin Poulain 2015-04-12 12:46:33 PDT
(In reply to comment #4)
> > If I am reading this correctly, you need to have the internal slot on the
> > controller object, and get it out through the this object.
> 
> You are reading correctly.
> I was expecting to first do that patch and then upgrade the controller
> implementation so that it matches the spec and ensure close is still working.
> But I can do it the other way as well.
> 
> For the controller, I am not yet sure whether going the IDL way or making a
> full custom implementation of it.

A fix in a follow up is okay with me. I r+ed this one.

Poke me when you have the follow up.
Comment 6 youenn fablet 2015-04-14 05:58:51 PDT
Created attachment 250702 [details]
Patch for landing
Comment 7 WebKit Commit Bot 2015-04-14 06:54:00 PDT
Comment on attachment 250702 [details]
Patch for landing

Clearing flags on attachment: 250702

Committed r182794: <http://trac.webkit.org/changeset/182794>
Comment 8 WebKit Commit Bot 2015-04-14 06:54:05 PDT
All reviewed patches have been landed.  Closing bug.
Comment 9 WebKit Commit Bot 2015-04-14 09:09:19 PDT
Re-opened since this is blocked by bug 143714
Comment 10 Xabier Rodríguez Calvar 2015-04-23 02:00:10 PDT
Created attachment 251421 [details]
Patch

Rebased against trunk.
Comment 11 WebKit Commit Bot 2015-04-27 06:33:13 PDT
Comment on attachment 251421 [details]
Patch

Clearing flags on attachment: 251421

Committed r183395: <http://trac.webkit.org/changeset/183395>
Comment 12 WebKit Commit Bot 2015-04-27 06:33:16 PDT
All reviewed patches have been landed.  Closing bug.