Changeset 182344 in webkit


Ignore:
Timestamp:
Apr 4, 2015 10:16:21 AM (9 years ago)
Author:
youenn.fablet@crf.canon.fr
Message:

[Streams API] Collecting a ReadableStreamReader should not unlock its stream
https://bugs.webkit.org/show_bug.cgi?id=143333

Reviewed by Benjamin Poulain.

Source/WebCore:

This patch stores as a boolean whether the stream is locked to a reader.
In case the reader forget to unlock the stream, the reader can be collected and destructor called.
In that case, the link between reader and stream will be reset but the stream will remain in locked state.

Covered by new test in streams/readablestreamreader-constructor.html.

  • Modules/streams/ReadableStream.h:

(WebCore::ReadableStream::isLocked):
(WebCore::ReadableStream::lock):
(WebCore::ReadableStream::release):
(WebCore::ReadableStream::releaseButKeepLocked): Introduced to cut the link between reader and stream but stil keeping the stream locked.

  • Modules/streams/ReadableStreamReader.cpp:

(WebCore::ReadableStreamReader::~ReadableStreamReader):

  • bindings/js/JSReadableStreamCustom.cpp:

(WebCore::JSReadableStream::getReader):

  • bindings/js/JSReadableStreamReaderCustom.cpp:

(WebCore::constructJSReadableStreamReader):

LayoutTests:

  • streams/readablestreamreader-constructor-expected.txt:
  • streams/readablestreamreader-constructor.html:
Location:
trunk
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r182343 r182344  
     12015-04-04  Xabier Rodriguez Calvar <calvaris@igalia.com> and Youenn Fablet  <youenn.fablet@crf.canon.fr>
     2
     3        [Streams API] Collecting a ReadableStreamReader should not unlock its stream
     4        https://bugs.webkit.org/show_bug.cgi?id=143333
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        * streams/readablestreamreader-constructor-expected.txt:
     9        * streams/readablestreamreader-constructor.html:
     10
    1112015-04-04  Yusuke Suzuki  <utatane.tea@gmail.com>
    212
  • trunk/LayoutTests/streams/readablestreamreader-constructor-expected.txt

    r182180 r182344  
    44PASS ReadableStreamReader closed should always return the same promise object
    55PASS ReadableStream getReader should throw if ReadableStream is locked
     6PASS Collecting a ReadableStreamReader should not unlock its stream.
    67
  • trunk/LayoutTests/streams/readablestreamreader-constructor.html

    r182180 r182344  
    22<script src='../resources/testharness.js'></script>
    33<script src='../resources/testharnessreport.js'></script>
     4<script src='../resources/gc.js'></script>
    45<script>
    56 
     
    8384}, 'ReadableStream getReader should throw if ReadableStream is locked');
    8485
     86test(function() {
     87    rs = new ReadableStream({});
     88    rs.getReader();
     89    window.gc();
     90    assert_throws(new TypeError(), function() { rs.getReader(); });
     91}, 'Collecting a ReadableStreamReader should not unlock its stream.');
     92
    8593</script>
  • trunk/Source/WebCore/ChangeLog

    r182342 r182344  
     12015-04-04  Xabier Rodriguez Calvar <calvaris@igalia.com> and Youenn Fablet  <youenn.fablet@crf.canon.fr>
     2
     3        [Streams API] Collecting a ReadableStreamReader should not unlock its stream
     4        https://bugs.webkit.org/show_bug.cgi?id=143333
     5
     6        Reviewed by Benjamin Poulain.
     7
     8        This patch stores as a boolean whether the stream is locked to a reader.
     9        In case the reader forget to unlock the stream, the reader can be collected and destructor called.
     10        In that case, the link between reader and stream will be reset but the stream will remain in locked state.
     11
     12        Covered by new test in streams/readablestreamreader-constructor.html.
     13
     14        * Modules/streams/ReadableStream.h:
     15        (WebCore::ReadableStream::isLocked):
     16        (WebCore::ReadableStream::lock):
     17        (WebCore::ReadableStream::release):
     18        (WebCore::ReadableStream::releaseButKeepLocked): Introduced to cut the link between reader and stream but stil keeping the stream locked.
     19        * Modules/streams/ReadableStreamReader.cpp:
     20        (WebCore::ReadableStreamReader::~ReadableStreamReader):
     21        * bindings/js/JSReadableStreamCustom.cpp:
     22        (WebCore::JSReadableStream::getReader):
     23        * bindings/js/JSReadableStreamReaderCustom.cpp:
     24        (WebCore::constructJSReadableStreamReader):
     25
    1262015-04-03  Zan Dobersek  <zdobersek@igalia.com>
    227
  • trunk/Source/WebCore/Modules/streams/ReadableStream.h

    r182309 r182344  
    5959
    6060    ReadableStreamReader* reader() { return m_reader; }
    61     void lock(ReadableStreamReader& reader) { m_reader = &reader; }
    62     void release() { m_reader = nullptr; }
    6361    virtual Ref<ReadableStreamReader> createReader() = 0;
     62
     63    bool isLocked() const { return m_isLocked; }
     64    void lock(ReadableStreamReader&);
     65    void release();
     66    void releaseButKeepLocked();
    6467
    6568    State internalState() { return m_state; }
     
    7679    Ref<ReadableStreamSource> m_source;
    7780    ReadableStreamReader* m_reader { nullptr };
     81    bool m_isLocked { false };
    7882};
     83
     84inline void ReadableStream::lock(ReadableStreamReader& reader)
     85{
     86    m_reader = &reader;
     87    m_isLocked = true;
     88}
     89
     90inline void ReadableStream::release()
     91{
     92    m_reader = nullptr;
     93    m_isLocked = false;
     94}
     95
     96inline void ReadableStream::releaseButKeepLocked()
     97{
     98    m_reader = nullptr;
     99    m_isLocked = true;
     100}
     101
     102
    79103
    80104}
  • trunk/Source/WebCore/Modules/streams/ReadableStreamReader.cpp

    r182309 r182344  
    5858#endif
    5959    if (m_stream) {
    60         m_stream->release();
     60        m_stream->releaseButKeepLocked();
    6161        m_stream = nullptr;
    6262    }
  • trunk/Source/WebCore/bindings/js/JSReadableStreamCustom.cpp

    r182309 r182344  
    5555JSValue JSReadableStream::getReader(ExecState* exec)
    5656{
    57     if (impl().reader())
     57    if (impl().isLocked())
    5858        return exec->vm().throwException(exec, createTypeError(exec, ASCIILiteral("ReadableStream is locked")));
    5959    return toJS(exec, globalObject(), impl().createReader());
  • trunk/Source/WebCore/bindings/js/JSReadableStreamReaderCustom.cpp

    r182180 r182344  
    107107        return throwVMError(exec, createTypeError(exec, ASCIILiteral("ReadableStreamReader constructor parameter is not a ReadableStream")));
    108108
    109     if (stream->impl().reader())
     109    if (stream->impl().isLocked())
    110110        return throwVMError(exec, createTypeError(exec, ASCIILiteral("ReadableStreamReader constructor parameter is a locked ReadableStream")));
    111111
Note: See TracChangeset for help on using the changeset viewer.