[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>
Mon, 27 Apr 2015 13:31:59 +0000 (13:31 +0000)
committeryouenn.fablet@crf.canon.fr <youenn.fablet@crf.canon.fr@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 27 Apr 2015 13:31:59 +0000 (13:31 +0000)
commit957b8c7d64bde240dac4289e05a2710e5f0fda6c
tree4e3d584d0fe16e878bcbc7cd77fbcf7f87c437f2
parent4a81fecc32afbd3b0f379d6abdf264b5cf08cc7a
[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 releases 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 in
the future as well, though of course it is not restricted to Streams.

Covered by reference tests that are now passing.

* Modules/streams/ReadableStream.h:
* Modules/streams/ReadableStream.cpp:
(WebCore::ReadableStream::changeStateToClosed): Called by the JS function 'close'.
* Modules/streams/ReadableStreamReader.cpp:
(WebCore::ReadableStreamReader::ReadableStreamReader): Initialized stream.
(WebCore::ReadableStreamReader::initialize): Added to handle state change at constructor time
in particular closed/errored state.
(WebCore::ReadableStreamReader::releaseStream): Releases the stream.
(WebCore::ReadableStreamReader::closed): Stores the promise callbacks and invokes success
immediately if the stream is already closed.
(WebCore::ReadableStreamReader::changeStateToClosed): Changes the internal state to closed,
resolves the promise and releases the stream.
* Modules/streams/ReadableStreamReader.h:
(WebCore::ReadableStreamReader::State): Added.
* bindings/js/JSDOMPromise.h:
(WebCore::DeferredWrapper::resolve<JSC::JSValue>): Adds the ability to resolve a promise with
a custom JS value.
* bindings/js/JSReadableStreamControllerCustom.cpp:
(WebCore::JSReadableStreamController::close): Not "notImplemented" anymore. Now it closes the
stream.
* bindings/js/JSReadableStreamReaderCustom.cpp:
(WebCore::JSReadableStreamReader::closed): Resolves the promise with undefined.

LayoutTests:

Updated expectations with new passes.

* streams/reference-implementation/bad-underlying-sources-expected.txt:
* 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@183395 268f45cc-cd09-0410-ab3c-d52691b4dbfc
12 files changed:
LayoutTests/ChangeLog
LayoutTests/streams/reference-implementation/bad-underlying-sources-expected.txt
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/JSReadableStreamControllerCustom.cpp
Source/WebCore/bindings/js/JSReadableStreamReaderCustom.cpp