[Streams API] ReadableStream constructor start function should be able to close the...
authoryouenn.fablet@crf.canon.fr <youenn.fablet@crf.canon.fr@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Apr 2015 13:52:59 +0000 (13:52 +0000)
committeryouenn.fablet@crf.canon.fr <youenn.fablet@crf.canon.fr@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 14 Apr 2015 13:52:59 +0000 (13:52 +0000)
commitf4d2791bc600c6e8ff30a7564a2095b6b453a545
tree6f6d9ecdf91588f1c792c5097b07e5b0b4df6f58
parentf14e20aee6d0fea1c3fccca4e0c1d9e510149462
[Streams API] ReadableStream constructor start function should be able to close the stream
https://bugs.webkit.org/show_bug.cgi?id=143363

Reviewed by Benjamin Poulain.

Source/WebCore:

Implements https://streams.spec.whatwg.org/#close-readable-stream.
When the "close" JS function is called, the stream is getting closed.
The stream state is changed to close and if it has a reader, the reader gets closed as well:
The reader resolves the closed promise and release the stream.

Enabled the possibility to resolve a promise with any JS value.
This is used to resolve closed promise with jsUndefined and will be used for read promises.

Covered by reference tests that are now passing.

* Modules/streams/ReadableStream.cpp:
(WebCore::ReadableStream::changeStateToClosed): Called by the JS function 'close'.
* Modules/streams/ReadableStream.h:
* Modules/streams/ReadableStreamReader.cpp:
(WebCore::ReadableStreamReader::ReadableStreamReader):
(WebCore::ReadableStreamReader::initialize): Added to handle state change at constructor time (in particular closed/errored state).
(WebCore::ReadableStreamReader::releaseStream):
(WebCore::ReadableStreamReader::closed): Storing the closed promise callbacks.
(WebCore::ReadableStreamReader::changeStateToClosed): Resolution of closed promise.
* Modules/streams/ReadableStreamReader.h:
* bindings/js/JSDOMPromise.h:
(WebCore::DeferredWrapper::resolve<JSC::JSValue>):
* bindings/js/JSReadableStreamReaderCustom.cpp:
(WebCore::JSReadableStreamReader::closed):
* bindings/js/ReadableStreamJSSource.cpp:
(WebCore::readableStreamSlotName):
(WebCore::getReadableJSStream): Helper function to retrieve the stream from the exec state.
(WebCore::closeReadableStreamFunction):
(WebCore::createReadableStreamCloseFunction):
(WebCore::createReadableStreamController):
(WebCore::ReadableStreamJSSource::start):
(WebCore::ReadableJSStreamReader::ReadableJSStreamReader): Deleted.

LayoutTests:

Rebased tests as some are now passing.

* streams/reference-implementation/readable-stream-reader-expected.txt:
* streams/reference-implementation/readable-stream-templated-expected.txt:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@182794 268f45cc-cd09-0410-ab3c-d52691b4dbfc
LayoutTests/ChangeLog
LayoutTests/streams/reference-implementation/readable-stream-reader-expected.txt
LayoutTests/streams/reference-implementation/readable-stream-templated-expected.txt
Source/WebCore/ChangeLog
Source/WebCore/Modules/streams/ReadableStream.cpp
Source/WebCore/Modules/streams/ReadableStream.h
Source/WebCore/Modules/streams/ReadableStreamReader.cpp
Source/WebCore/Modules/streams/ReadableStreamReader.h
Source/WebCore/bindings/js/JSDOMPromise.h
Source/WebCore/bindings/js/JSReadableStreamReaderCustom.cpp
Source/WebCore/bindings/js/ReadableStreamJSSource.cpp