Changeset 223279 in webkit


Ignore:
Timestamp:
Oct 13, 2017 2:22:48 AM (7 years ago)
Author:
romain.bellessort@crf.canon.fr
Message:

[Readable Streams API] Align queue with spec for ReadableStreamDefaultController
https://bugs.webkit.org/show_bug.cgi?id=178082

Reviewed by Xabier Rodriguez-Calvar.

LayoutTests/imported/w3c:

Updated test expectations for tests that were previously failing but now pass.

  • web-platform-tests/streams/readable-streams/floating-point-total-queue-size-expected.txt:
  • web-platform-tests/streams/readable-streams/floating-point-total-queue-size.dedicatedworker-expected.txt:

Source/WebCore:

Implemented new queue behavior for dequeueValue (used by ReadableStreamDefaultController),
which fixes rounding errors (as described in https://github.com/whatwg/streams/pull/661).
Also aligned ReadableByteStreamController queue so that both queues are implemented in
the same way.

No new tests (covered by existing tests, especially WPT tests that now pass).

  • Modules/streams/ReadableByteStreamInternals.js:

(privateInitializeReadableByteStreamController): Aligned queue with RSDC.
(readableByteStreamControllerCancel): Aligned queue with RSDC.
(readableByteStreamControllerError): Aligned queue with RSDC.
(readableByteStreamControllerClose): Aligned queue with RSDC.
(readableByteStreamControllerHandleQueueDrain): Aligned queue with RSDC.
(readableByteStreamControllerPull): Aligned queue with RSDC.
(readableByteStreamControllerEnqueue): Aligned queue with RSDC.
(readableByteStreamControllerEnqueueChunk): Aligned queue with RSDC.
(readableByteStreamControllerProcessPullDescriptors): Aligned queue with RSDC.
(readableByteStreamControllerFillDescriptorFromQueue): Aligned queue with RSDC.
(readableByteStreamControllerPullInto): Aligned queue with RSDC.

  • Modules/streams/StreamInternals.js:

(dequeueValue): Updated to match spec.

  • bindings/js/WebCoreBuiltinNames.h: Removed now useless "totalQueuedBytes".
Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r223273 r223279  
     12017-10-13  Romain Bellessort  <romain.bellessort@crf.canon.fr>
     2
     3        [Readable Streams API] Align queue with spec for ReadableStreamDefaultController
     4        https://bugs.webkit.org/show_bug.cgi?id=178082
     5
     6        Reviewed by Xabier Rodriguez-Calvar.
     7
     8        Updated test expectations for tests that were previously failing but now pass.
     9
     10        * web-platform-tests/streams/readable-streams/floating-point-total-queue-size-expected.txt:
     11        * web-platform-tests/streams/readable-streams/floating-point-total-queue-size.dedicatedworker-expected.txt:
     12
    1132017-10-12  Chris Dumez  <cdumez@apple.com>
    214
  • trunk/LayoutTests/imported/w3c/web-platform-tests/streams/readable-streams/floating-point-total-queue-size-expected.txt

    r213882 r223279  
    11
    2 FAIL Floating point arithmetic must manifest near NUMBER.MAX_SAFE_INTEGER (total ends up positive) assert_equals: [[queueTotalSize]] must clamp to 0 if it becomes negative expected 0 but got 1
    3 FAIL Floating point arithmetic must manifest near 0 (total ends up positive, but clamped) assert_equals: [[queueTotalSize]] must clamp to 0 if it becomes negative expected 0 but got 1.1102230246251565e-16
     2PASS Floating point arithmetic must manifest near NUMBER.MAX_SAFE_INTEGER (total ends up positive)
     3PASS Floating point arithmetic must manifest near 0 (total ends up positive, but clamped)
    44PASS Floating point arithmetic must manifest near 0 (total ends up positive, and not clamped)
    55PASS Floating point arithmetic must manifest near 0 (total ends up zero)
  • trunk/LayoutTests/imported/w3c/web-platform-tests/streams/readable-streams/floating-point-total-queue-size.dedicatedworker-expected.txt

    r217225 r223279  
    11
    2 FAIL Floating point arithmetic must manifest near NUMBER.MAX_SAFE_INTEGER (total ends up positive) assert_equals: [[queueTotalSize]] must clamp to 0 if it becomes negative expected 0 but got 1
    3 FAIL Floating point arithmetic must manifest near 0 (total ends up positive, but clamped) assert_equals: [[queueTotalSize]] must clamp to 0 if it becomes negative expected 0 but got 1.1102230246251565e-16
     2PASS Floating point arithmetic must manifest near NUMBER.MAX_SAFE_INTEGER (total ends up positive)
     3PASS Floating point arithmetic must manifest near 0 (total ends up positive, but clamped)
    44PASS Floating point arithmetic must manifest near 0 (total ends up positive, and not clamped)
    55PASS Floating point arithmetic must manifest near 0 (total ends up zero)
  • trunk/Source/WebCore/ChangeLog

    r223278 r223279  
     12017-10-13  Romain Bellessort  <romain.bellessort@crf.canon.fr>
     2
     3        [Readable Streams API] Align queue with spec for ReadableStreamDefaultController
     4        https://bugs.webkit.org/show_bug.cgi?id=178082
     5
     6        Reviewed by Xabier Rodriguez-Calvar.
     7
     8        Implemented new queue behavior for dequeueValue (used by ReadableStreamDefaultController),
     9        which fixes rounding errors (as described in https://github.com/whatwg/streams/pull/661).
     10        Also aligned ReadableByteStreamController queue so that both queues are implemented in
     11        the same way.
     12
     13        No new tests (covered by existing tests, especially WPT tests that now pass).
     14
     15        * Modules/streams/ReadableByteStreamInternals.js:
     16        (privateInitializeReadableByteStreamController): Aligned queue with RSDC.
     17        (readableByteStreamControllerCancel): Aligned queue with RSDC.
     18        (readableByteStreamControllerError): Aligned queue with RSDC.
     19        (readableByteStreamControllerClose): Aligned queue with RSDC.
     20        (readableByteStreamControllerHandleQueueDrain): Aligned queue with RSDC.
     21        (readableByteStreamControllerPull): Aligned queue with RSDC.
     22        (readableByteStreamControllerEnqueue): Aligned queue with RSDC.
     23        (readableByteStreamControllerEnqueueChunk): Aligned queue with RSDC.
     24        (readableByteStreamControllerProcessPullDescriptors): Aligned queue with RSDC.
     25        (readableByteStreamControllerFillDescriptorFromQueue): Aligned queue with RSDC.
     26        (readableByteStreamControllerPullInto): Aligned queue with RSDC.
     27        * Modules/streams/StreamInternals.js:
     28        (dequeueValue): Updated to match spec.
     29        * bindings/js/WebCoreBuiltinNames.h: Removed now useless "totalQueuedBytes".
     30
    1312017-10-13  Wenson Hsieh  <wenson_hsieh@apple.com>
    232
  • trunk/Source/WebCore/Modules/streams/ReadableByteStreamInternals.js

    r220566 r223279  
    6060    this.@pulling = false;
    6161    @readableByteStreamControllerClearPendingPullIntos(this);
    62     this.@queue = [];
    63     this.@totalQueuedBytes = 0;
     62    this.@queue = @newQueue();
    6463    this.@started = false;
    6564    this.@closeRequested = false;
     
    138137    if (controller.@pendingPullIntos.length > 0)
    139138        controller.@pendingPullIntos[0].bytesFilled = 0;
    140     controller.@queue = [];
    141     controller.@totalQueuedBytes = 0;
     139    controller.@queue = @newQueue();
    142140    return @promiseInvokeOrNoop(controller.@underlyingByteSource, "cancel", [reason]);
    143141}
     
    149147    @assert(controller.@controlledReadableStream.@state === @streamReadable);
    150148    @readableByteStreamControllerClearPendingPullIntos(controller);
    151     controller.@queue = [];
     149    controller.@queue = @newQueue();
    152150    @readableStreamError(controller.@controlledReadableStream, e);
    153151}
     
    160158    @assert(controller.@controlledReadableStream.@state === @streamReadable);
    161159
    162     if (controller.@totalQueuedBytes > 0) {
     160    if (controller.@queue.size > 0) {
    163161        controller.@closeRequested = true;
    164162        return;
     
    195193       return 0;
    196194
    197    return controller.@strategyHWM - controller.@totalQueuedBytes;
     195   return controller.@strategyHWM - controller.@queue.size;
    198196}
    199197
     
    217215
    218216    @assert(controller.@controlledReadableStream.@state === @streamReadable);
    219     if (!controller.@totalQueuedBytes && controller.@closeRequested)
     217    if (!controller.@queue.size && controller.@closeRequested)
    220218        @readableStreamClose(controller.@controlledReadableStream);
    221219    else
     
    230228    @assert(@readableStreamHasDefaultReader(stream));
    231229
    232     if (controller.@totalQueuedBytes > 0) {
     230    if (controller.@queue.size > 0) {
    233231        @assert(stream.@reader.@readRequests.length === 0);
    234         const entry = controller.@queue.@shift();
    235         controller.@totalQueuedBytes -= entry.byteLength;
     232        const entry = controller.@queue.content.@shift();
     233        controller.@queue.size -= entry.byteLength;
    236234        @readableByteStreamControllerHandleQueueDrain(controller);
    237235        let view;
     
    342340            @readableByteStreamControllerEnqueueChunk(controller, transferredBuffer, byteOffset, byteLength);
    343341        else {
    344             @assert(!controller.@queue.length);
     342            @assert(!controller.@queue.content.length);
    345343            let transferredView = new @Uint8Array(transferredBuffer, byteOffset, byteLength);
    346344            @readableStreamFulfillReadRequest(stream, transferredView, false);
     
    364362    "use strict";
    365363
    366     controller.@queue.@push({
     364    controller.@queue.content.@push({
    367365        buffer: buffer,
    368366        byteOffset: byteOffset,
    369367        byteLength: byteLength
    370368    });
    371     controller.@totalQueuedBytes += byteLength;
     369    controller.@queue.size += byteLength;
    372370}
    373371
     
    472470    @assert(!controller.@closeRequested);
    473471    while (controller.@pendingPullIntos.length > 0) {
    474         if (controller.@totalQueuedBytes === 0)
     472        if (controller.@queue.size === 0)
    475473            return;
    476474        let pullIntoDescriptor = controller.@pendingPullIntos[0];
     
    488486
    489487    const currentAlignedBytes = pullIntoDescriptor.bytesFilled - (pullIntoDescriptor.bytesFilled % pullIntoDescriptor.elementSize);
    490     const maxBytesToCopy = controller.@totalQueuedBytes < pullIntoDescriptor.byteLength - pullIntoDescriptor.bytesFilled ?
    491                 controller.@totalQueuedBytes : pullIntoDescriptor.byteLength - pullIntoDescriptor.bytesFilled;
     488    const maxBytesToCopy = controller.@queue.size < pullIntoDescriptor.byteLength - pullIntoDescriptor.bytesFilled ?
     489                controller.@queue.size : pullIntoDescriptor.byteLength - pullIntoDescriptor.bytesFilled;
    492490    const maxBytesFilled = pullIntoDescriptor.bytesFilled + maxBytesToCopy;
    493491    const maxAlignedBytes = maxBytesFilled - (maxBytesFilled % pullIntoDescriptor.elementSize);
     
    501499
    502500    while (totalBytesToCopyRemaining > 0) {
    503         let headOfQueue = controller.@queue[0];
     501        let headOfQueue = controller.@queue.content[0];
    504502        const bytesToCopy = totalBytesToCopyRemaining < headOfQueue.byteLength ? totalBytesToCopyRemaining : headOfQueue.byteLength;
    505503        // Copy appropriate part of pullIntoDescriptor.buffer to headOfQueue.buffer.
     
    517515
    518516        if (headOfQueue.byteLength === bytesToCopy)
    519             controller.@queue.@shift();
     517            controller.@queue.content.@shift();
    520518        else {
    521519            headOfQueue.byteOffset += bytesToCopy;
     
    523521        }
    524522
    525         controller.@totalQueuedBytes -= bytesToCopy;
     523        controller.@queue.size -= bytesToCopy;
    526524        @assert(controller.@pendingPullIntos.length === 0 || controller.@pendingPullIntos[0] === pullIntoDescriptor);
    527525        @readableByteStreamControllerInvalidateBYOBRequest(controller);
     
    531529
    532530    if (!ready) {
    533         @assert(controller.@totalQueuedBytes === 0);
     531        @assert(controller.@queue.size === 0);
    534532        @assert(pullIntoDescriptor.bytesFilled > 0);
    535533        @assert(pullIntoDescriptor.bytesFilled < pullIntoDescriptor.elementSize);
     
    660658    }
    661659
    662     if (controller.@totalQueuedBytes > 0) {
     660    if (controller.@queue.size > 0) {
    663661        if (@readableByteStreamControllerFillDescriptorFromQueue(controller, pullIntoDescriptor)) {
    664662            const filledView = @readableByteStreamControllerConvertDescriptor(pullIntoDescriptor);
  • trunk/Source/WebCore/Modules/streams/StreamInternals.js

    r220566 r223279  
    106106    const record = queue.content.@shift();
    107107    queue.size -= record.size;
     108    // As described by spec, below case may occur due to rounding errors.
     109    if (queue.size < 0)
     110        queue.size = 0;
    108111    return record.value;
    109112}
  • trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h

    r221966 r223279  
    267267    macro(structuredCloneArrayBufferView) \
    268268    macro(top) \
    269     macro(totalQueuedBytes) \
    270269    macro(underlyingByteSource) \
    271270    macro(underlyingSink) \
Note: See TracChangeset for help on using the changeset viewer.