Changeset 186044 in webkit


Ignore:
Timestamp:
Jun 28, 2015 5:39:48 AM (9 years ago)
Author:
youenn.fablet@crf.canon.fr
Message:

[Streams API] Add support for chunks with customized sizes
https://bugs.webkit.org/show_bug.cgi?id=146312

Reviewed by Darin Adler.

Source/WebCore:

Covered by rebased tests.

  • bindings/js/ReadableJSStream.cpp:

(WebCore::ReadableJSStream::read): Decrement totalQueueSize with the chunk specific size.
(WebCore::ReadableJSStream::enqueue): Calls retrieveSize, enqueue chunk with its size and increment totalQueueSize.
(WebCore::ReadableJSStream::retrieveChunkSize): Calls size JS callback and convert it to double.

  • bindings/js/ReadableJSStream.h:

LayoutTests:

  • streams/reference-implementation/bad-strategies-expected.txt:
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r186040 r186044  
     12015-06-28  Xabier Rodriguez Calvar  <calvaris@igalia.com> and Youenn Fablet  <youenn.fablet@crf.canon.fr>
     2
     3        [Streams API] Add support for chunks with customized sizes
     4        https://bugs.webkit.org/show_bug.cgi?id=146312
     5
     6        Reviewed by Darin Adler.
     7
     8        * streams/reference-implementation/bad-strategies-expected.txt:
     9
    1102015-06-27  David Kilzer  <ddkilzer@apple.com>
    211
  • trunk/LayoutTests/streams/reference-implementation/bad-strategies-expected.txt

    r185953 r186044  
    11
    22PASS Readable stream: throwing strategy.size getter
    3 FAIL Readable stream: throwing strategy.size method assert_throws: enqueue should throw the error function "function () { c.enqueue('a'); }" did not throw
     3PASS Readable stream: throwing strategy.size method
    44PASS Readable stream: throwing strategy.highWaterMark getter
    55PASS Readable stream: invalid strategy.highWaterMark
    66PASS Readable stream: negative strategy.highWaterMark
    7 FAIL Readable stream: strategy.size returning NaN assert_equals: enqueue should throw a RangeError expected function "function RangeError() {
    8     [native code]
    9 }" but got function "function AssertionError(message)
    10     {
    11         this.messa..."
    12 FAIL Readable stream: strategy.size returning -Infinity assert_equals: enqueue should throw a RangeError expected function "function RangeError() {
    13     [native code]
    14 }" but got function "function AssertionError(message)
    15     {
    16         this.messa..."
    17 FAIL Readable stream: strategy.size returning +Infinity assert_equals: enqueue should throw a RangeError expected function "function RangeError() {
    18     [native code]
    19 }" but got function "function AssertionError(message)
    20     {
    21         this.messa..."
     7PASS Readable stream: strategy.size returning NaN
     8PASS Readable stream: strategy.size returning -Infinity
     9PASS Readable stream: strategy.size returning +Infinity
    2210
  • trunk/Source/WebCore/ChangeLog

    r186043 r186044  
     12015-06-28  Xabier Rodriguez Calvar  <calvaris@igalia.com> and Youenn Fablet  <youenn.fablet@crf.canon.fr>
     2
     3        [Streams API] Add support for chunks with customized sizes
     4        https://bugs.webkit.org/show_bug.cgi?id=146312
     5
     6        Reviewed by Darin Adler.
     7
     8        Covered by rebased tests.
     9
     10        * bindings/js/ReadableJSStream.cpp:
     11        (WebCore::ReadableJSStream::read): Decrement totalQueueSize with the chunk specific size.
     12        (WebCore::ReadableJSStream::enqueue): Calls retrieveSize, enqueue chunk with its size and increment totalQueueSize.
     13        (WebCore::ReadableJSStream::retrieveChunkSize): Calls size JS callback and convert it to double.
     14        * bindings/js/ReadableJSStream.h:
     15
    1162015-06-28  Youenn Fablet  <youenn.fablet@crf.canon.fr>
    217
  • trunk/Source/WebCore/bindings/js/ReadableJSStream.cpp

    r186043 r186044  
    324324    ASSERT(hasValue());
    325325
    326     return m_chunkQueue.takeFirst().get();
    327 }
    328 
    329 void ReadableJSStream::enqueue(ExecState& exec)
     326    Chunk chunk = m_chunkQueue.takeFirst();
     327    m_totalQueueSize -= chunk.size;
     328
     329    return chunk.value.get();
     330}
     331
     332void ReadableJSStream::enqueue(ExecState& state)
    330333{
    331334    ASSERT(!isCloseRequested());
     
    334337        return;
    335338
    336     JSValue chunk = exec.argumentCount() ? exec.argument(0) : jsUndefined();
     339    JSValue chunk = state.argument(0);
    337340    if (resolveReadCallback(chunk)) {
    338341        pull();
     
    340343    }
    341344
    342     m_chunkQueue.append(JSC::Strong<JSC::Unknown>(exec.vm(), chunk));
    343     // FIXME: Compute chunk size.
     345    double size = retrieveChunkSize(state, chunk);
     346    if (state.hadException()) {
     347        storeError(state, state.exception()->value());
     348        return;
     349    }
     350
     351    m_chunkQueue.append({ JSC::Strong<JSC::Unknown>(state.vm(), chunk), size });
     352    m_totalQueueSize += size;
     353
    344354    pull();
    345355}
    346356
     357double ReadableJSStream::retrieveChunkSize(ExecState& state, JSValue chunk)
     358{
     359    if (!m_sizeFunction)
     360        return 1;
     361
     362    MarkedArgumentBuffer arguments;
     363    arguments.append(chunk);
     364
     365    JSValue sizeValue = callFunction(state, m_sizeFunction.get(), jsUndefined(), arguments);
     366    if (state.hadException())
     367        return 0;
     368
     369    double size = sizeValue.toNumber(&state);
     370    if (state.hadException())
     371        return 0;
     372
     373    if (!std::isfinite(size)) {
     374        throwVMError(&state, createRangeError(&state, ASCIILiteral("Incorrect double value")));
     375        return 0;
     376    }
     377
     378    return size;
     379}
     380
    347381} // namespace WebCore
    348382
  • trunk/Source/WebCore/bindings/js/ReadableJSStream.h

    r186043 r186044  
    6565    void enqueue(JSC::ExecState&);
    6666
    67     double desiredSize() const { return m_highWaterMark - m_chunkQueue.size(); }
     67    double desiredSize() const { return m_highWaterMark - m_totalQueueSize; }
    6868
    6969private:
     
    8383    JSDOMGlobalObject* globalObject();
    8484
     85    double retrieveChunkSize(JSC::ExecState&, JSC::JSValue);
     86
    8587    std::unique_ptr<ReadableStreamController> m_controller;
    8688    // FIXME: we should consider not using JSC::Strong, see https://bugs.webkit.org/show_bug.cgi?id=146278
     
    8890    JSC::Strong<JSC::JSFunction> m_errorFunction;
    8991    JSC::Strong<JSC::JSObject> m_source;
    90     Deque<JSC::Strong<JSC::Unknown>> m_chunkQueue;
     92
     93    struct Chunk {
     94        JSC::Strong<JSC::Unknown> value;
     95        double size;
     96    };
     97    Deque<Chunk> m_chunkQueue;
     98
     99    double m_totalQueueSize { 0 };
    91100    double m_highWaterMark;
    92101    JSC::Strong<JSC::JSFunction> m_sizeFunction;
Note: See TracChangeset for help on using the changeset viewer.