Changeset 205117 in webkit


Ignore:
Timestamp:
Aug 29, 2016 3:52:42 AM (8 years ago)
Author:
commit-queue@webkit.org
Message:

[Fetch API] Response cloning should structureClone when teeing Response stream
https://bugs.webkit.org/show_bug.cgi?id=161147

Patch by Youenn Fablet <youenn@apple.com> on 2016-08-29
Reviewed by Darin Adler.

LayoutTests/imported/w3c:

  • web-platform-tests/fetch/api/response/response-clone-expected.txt:
  • web-platform-tests/fetch/api/response/response-clone.html:

Source/JavaScriptCore:

  • builtins/BuiltinNames.h: Adding ArrayBuffer and isView identifiers.
  • runtime/JSArrayBufferConstructor.cpp:

(JSC::JSArrayBufferConstructor::finishCreation): Adding @isView as private method.

  • runtime/JSDataView.h: Exporting create method.

Source/WebCore:

Covered by updated test.

Implementing structure cloning for ArrayBuffer and ArrayBufferView objects.
Using this structure cloning in ReadableStream to support structureClone in the case of Fetch API.

  • CMakeLists.txt: Adding StructureClone.cpp
  • Modules/fetch/FetchResponse.js:

(clone): Setting structureClone to true

  • Modules/streams/ReadableStreamInternals.js:

(doStructuredClone): Added to clone ArrayBuffer/ArrayBufferView chunks. Throwing exception otherwise.
(teeReadableStreamPullFunction): Using @doStructuredClone

  • WebCore.xcodeproj/project.pbxproj: Adding StructureClone.cpp/.h
  • bindings/js/JSDOMGlobalObject.cpp:

(WebCore::JSDOMGlobalObject::addBuiltinGlobals): Adding @ArrayBuffer and structuredCloneArrayBuffer and structuredCloneArrayBufferView private properties.

  • bindings/js/StructuredClone.cpp: Added.

(WebCore::structuredCloneArrayBuffer): Cloning of ArrayBuffer as per
http://w3c.github.io/html/infrastructure.html#section-structuredclone step 11.

(WebCore::structuredCloneArrayBufferView): Cloning of ArrayBufferView as
perhttp://w3c.github.io/html/infrastructure.html#section-structuredclone, step 12.

  • bindings/js/StructuredClone.h: Added.
  • bindings/js/WebCoreBuiltinNames.h:
Location:
trunk
Files:
2 added
14 edited

Legend:

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

    r205115 r205117  
     12016-08-29  Youenn Fablet  <youenn@apple.com>
     2
     3        [Fetch API] Response cloning should structureClone when teeing Response stream
     4        https://bugs.webkit.org/show_bug.cgi?id=161147
     5
     6        Reviewed by Darin Adler.
     7
     8        * web-platform-tests/fetch/api/response/response-clone-expected.txt:
     9        * web-platform-tests/fetch/api/response/response-clone.html:
     10
    1112016-08-29  Youenn Fablet  <youenn@apple.com>
    212
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-clone-expected.txt

    r205110 r205117  
    77PASS Cloned responses should provide the same data
    88PASS Cancelling stream should not affect cloned one
     9PASS Check response clone use structureClone for teed ReadableStreams (Int8Arraychunk)
     10PASS Check response clone use structureClone for teed ReadableStreams (Int16Arraychunk)
     11PASS Check response clone use structureClone for teed ReadableStreams (Int32Arraychunk)
     12PASS Check response clone use structureClone for teed ReadableStreams (ArrayBufferchunk)
     13PASS Check response clone use structureClone for teed ReadableStreams (Uint8Arraychunk)
     14PASS Check response clone use structureClone for teed ReadableStreams (Uint8ClampedArraychunk)
     15PASS Check response clone use structureClone for teed ReadableStreams (Uint16Arraychunk)
     16PASS Check response clone use structureClone for teed ReadableStreams (Uint32Arraychunk)
     17PASS Check response clone use structureClone for teed ReadableStreams (Float32Arraychunk)
     18PASS Check response clone use structureClone for teed ReadableStreams (Float64Arraychunk)
     19PASS Check response clone use structureClone for teed ReadableStreams (DataViewchunk)
    920
  • trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-clone.html

    r205110 r205117  
    9494    }, 'Cancelling stream should not affect cloned one');
    9595
     96function testReadableStreamClone(initialBuffer, bufferType)
     97{
     98    promise_test(function(test) {
     99        var response = new Response(new ReadableStream({start : function(controller) {
     100            controller.enqueue(initialBuffer);
     101            controller.close();
     102        }}));
     103
     104        var clone = response.clone();
     105        var stream1 = response.body;
     106        var stream2 = clone.body;
     107
     108        var buffer;
     109        return stream1.getReader().read().then(function(data) {
     110            assert_false(data.done);
     111            assert_array_equals(data.value, initialBuffer, "Cloned buffer chunks have the same content");
     112            assert_equals(Object.getPrototypeOf(data.value), Object.getPrototypeOf(initialBuffer), "Cloned buffers have the same type");
     113            assert_true(data.value !== initialBuffer, "Cloned buffers are different objects");
     114            return stream2.getReader().read();
     115        }).then(function(data) {
     116            assert_false(data.done);
     117            assert_array_equals(data.value, initialBuffer, "Cloned buffer chunks have the same content");
     118            assert_equals(Object.getPrototypeOf(data.value), Object.getPrototypeOf(initialBuffer), "Cloned buffers have the same type");
     119            assert_true(data.value !== initialBuffer, "Cloned buffers are different objects");
     120        });
     121    }, "Check response clone use structureClone for teed ReadableStreams (" + bufferType  + "chunk)");
     122}
     123
     124var arrayBuffer = new ArrayBuffer(16);
     125testReadableStreamClone(new Int8Array(arrayBuffer, 1), "Int8Array");
     126testReadableStreamClone(new Int16Array(arrayBuffer, 2, 2), "Int16Array");
     127testReadableStreamClone(new Int32Array(arrayBuffer), "Int32Array");
     128testReadableStreamClone(arrayBuffer, "ArrayBuffer");
     129testReadableStreamClone(new Uint8Array(arrayBuffer), "Uint8Array");
     130testReadableStreamClone(new Uint8ClampedArray(arrayBuffer), "Uint8ClampedArray");
     131testReadableStreamClone(new Uint16Array(arrayBuffer, 2), "Uint16Array");
     132testReadableStreamClone(new Uint32Array(arrayBuffer), "Uint32Array");
     133testReadableStreamClone(new Float32Array(arrayBuffer), "Float32Array");
     134testReadableStreamClone(new Float64Array(arrayBuffer), "Float64Array");
     135testReadableStreamClone(new DataView(arrayBuffer, 2, 8), "DataView");
    96136    </script>
    97137  </body>
  • trunk/Source/JavaScriptCore/ChangeLog

    r205112 r205117  
     12016-08-29  Youenn Fablet  <youenn@apple.com>
     2
     3        [Fetch API] Response cloning should structureClone when teeing Response stream
     4        https://bugs.webkit.org/show_bug.cgi?id=161147
     5
     6        Reviewed by Darin Adler.
     7
     8        * builtins/BuiltinNames.h: Adding ArrayBuffer and isView identifiers.
     9        * runtime/JSArrayBufferConstructor.cpp:
     10        (JSC::JSArrayBufferConstructor::finishCreation): Adding @isView as private method.
     11        * runtime/JSDataView.h: Exporting create method.
     12
    1132016-08-29  Benjamin Poulain  <bpoulain@apple.com>
    214
  • trunk/Source/JavaScriptCore/builtins/BuiltinNames.h

    r204058 r205117  
    3737    JSC_COMMON_BYTECODE_INTRINSIC_FUNCTIONS_EACH_NAME(macro) \
    3838    JSC_COMMON_BYTECODE_INTRINSIC_CONSTANTS_EACH_NAME(macro) \
    39     macro(iteratedObject) \
    4039    macro(arrayIteratorNextIndex) \
    4140    macro(arrayIterationKind) \
     
    4443    macro(arrayIteratorKind) \
    4544    macro(charCodeAt) \
     45    macro(isView) \
     46    macro(iteratedObject) \
    4647    macro(iteratedString) \
    4748    macro(stringIteratorNextIndex) \
     
    5657    macro(Number) \
    5758    macro(Array) \
     59    macro(ArrayBuffer) \
    5860    macro(String) \
    5961    macro(RegExp) \
  • trunk/Source/JavaScriptCore/runtime/JSArrayBufferConstructor.cpp

    r203320 r205117  
    2727#include "JSArrayBufferConstructor.h"
    2828
     29#include "BuiltinNames.h"
    2930#include "Error.h"
    3031#include "ExceptionHelpers.h"
     
    5859    JSGlobalObject* globalObject = this->globalObject();
    5960    JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->isView, arrayBufferFuncIsView, DontEnum, 1);
     61    JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().isViewPrivateName(), arrayBufferFuncIsView, DontEnum, 1);
    6062}
    6163
  • trunk/Source/JavaScriptCore/runtime/JSDataView.h

    r198023 r205117  
    4141   
    4242public:
    43     static JSDataView* create(
     43    JS_EXPORT_PRIVATE static JSDataView* create(
    4444        ExecState*, Structure*, PassRefPtr<ArrayBuffer>, unsigned byteOffset,
    4545        unsigned byteLength);
  • trunk/Source/WebCore/CMakeLists.txt

    r205103 r205117  
    12581258    bindings/js/ScriptGlobalObject.cpp
    12591259    bindings/js/ScriptState.cpp
     1260    bindings/js/StructuredClone.cpp
    12601261    bindings/js/SerializedScriptValue.cpp
    12611262    bindings/js/WebCoreTypedArrayController.cpp
  • trunk/Source/WebCore/ChangeLog

    r205116 r205117  
     12016-08-29  Youenn Fablet  <youenn@apple.com>
     2
     3        [Fetch API] Response cloning should structureClone when teeing Response stream
     4        https://bugs.webkit.org/show_bug.cgi?id=161147
     5
     6        Reviewed by Darin Adler.
     7
     8        Covered by updated test.
     9
     10        Implementing structure cloning for ArrayBuffer and ArrayBufferView objects.
     11        Using this structure cloning in ReadableStream to support structureClone in the case of Fetch API.
     12
     13        * CMakeLists.txt: Adding StructureClone.cpp
     14        * Modules/fetch/FetchResponse.js:
     15        (clone): Setting structureClone to true
     16        * Modules/streams/ReadableStreamInternals.js:
     17        (doStructuredClone): Added to clone ArrayBuffer/ArrayBufferView chunks. Throwing exception otherwise.
     18        (teeReadableStreamPullFunction): Using @doStructuredClone
     19        * WebCore.xcodeproj/project.pbxproj: Adding StructureClone.cpp/.h
     20        * bindings/js/JSDOMGlobalObject.cpp:
     21        (WebCore::JSDOMGlobalObject::addBuiltinGlobals): Adding @ArrayBuffer and structuredCloneArrayBuffer and structuredCloneArrayBufferView private properties.
     22        * bindings/js/StructuredClone.cpp: Added.
     23        (WebCore::structuredCloneArrayBuffer): Cloning of ArrayBuffer as per
     24        http://w3c.github.io/html/infrastructure.html#section-structuredclone step 11.
     25       (WebCore::structuredCloneArrayBufferView): Cloning of ArrayBufferView as
     26       perhttp://w3c.github.io/html/infrastructure.html#section-structuredclone, step 12.
     27        * bindings/js/StructuredClone.h: Added.
     28        * bindings/js/WebCoreBuiltinNames.h:
     29
    1302016-08-16  Carlos Garcia Campos  <cgarcia@igalia.com>
    231
  • trunk/Source/WebCore/Modules/fetch/FetchResponse.js

    r205110 r205117  
    9797
    9898    if (this.@body) {
    99         var teedReadableStreams = @teeReadableStream(this.@body, false);
     99        var teedReadableStreams = @teeReadableStream(this.@body, true);
    100100        this.@body = teedReadableStreams[0];
    101101        cloned.@body = teedReadableStreams[1];
  • trunk/Source/WebCore/Modules/streams/ReadableStreamInternals.js

    r205110 r205117  
    112112}
    113113
     114function doStructuredClone(object)
     115{
     116    // FIXME: We should implement http://w3c.github.io/html/infrastructure.html#ref-for-structured-clone-4
     117    // Implementation is currently limited to ArrayBuffer/ArrayBufferView to meet Fetch API needs.
     118
     119    if (object instanceof @ArrayBuffer)
     120        return @structuredCloneArrayBuffer(object);
     121
     122    if (@ArrayBuffer.@isView(object))
     123        return @structuredCloneArrayBufferView(object);
     124
     125    throw new @TypeError("structuredClone not implemented for: " + object);
     126}
     127
    114128function teeReadableStreamPullFunction(teeState, reader, shouldClone)
    115129{
     
    127141            if (teeState.closedOrErrored)
    128142                return;
    129             if (!teeState.canceled1) {
    130                 // FIXME: Implement cloning if shouldClone is true
    131                 @enqueueInReadableStream(teeState.branch1, result.value);
    132             }
    133             if (!teeState.canceled2) {
    134                 // FIXME: Implement cloning if shouldClone is true
    135                 @enqueueInReadableStream(teeState.branch2, result.value);
    136             }
     143            if (!teeState.canceled1)
     144                @enqueueInReadableStream(teeState.branch1, shouldClone ? @doStructuredClone(result.value) : result.value);
     145            if (!teeState.canceled2)
     146                @enqueueInReadableStream(teeState.branch2, shouldClone ? @doStructuredClone(result.value) : result.value);
    137147        });
    138148    }
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r205103 r205117  
    15141514                4147E2B71C89912C00A7E715 /* FetchLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4147E2B41C89912600A7E715 /* FetchLoader.cpp */; };
    15151515                4147E2B81C89912F00A7E715 /* FetchBodyOwner.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4147E2B31C89912600A7E715 /* FetchBodyOwner.cpp */; };
     1516                414B82041D6DF0DF0077EBE3 /* StructuredClone.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 414B82021D6DF0D90077EBE3 /* StructuredClone.cpp */; };
     1517                414B82051D6DF0E50077EBE3 /* StructuredClone.h in Headers */ = {isa = PBXBuildFile; fileRef = 414B82031D6DF0D90077EBE3 /* StructuredClone.h */; };
    15161518                415071571685067300C3C7B3 /* SelectorFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 415071551685067300C3C7B3 /* SelectorFilter.cpp */; };
    15171519                415071581685067300C3C7B3 /* SelectorFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 415071561685067300C3C7B3 /* SelectorFilter.h */; };
     
    84058407                4147E2B51C89912600A7E715 /* FetchLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FetchLoader.h; sourceTree = "<group>"; };
    84068408                4147E2B61C89912600A7E715 /* FetchLoaderClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FetchLoaderClient.h; sourceTree = "<group>"; };
     8409                414B82021D6DF0D90077EBE3 /* StructuredClone.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StructuredClone.cpp; sourceTree = "<group>"; };
     8410                414B82031D6DF0D90077EBE3 /* StructuredClone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StructuredClone.h; sourceTree = "<group>"; };
    84078411                415071551685067300C3C7B3 /* SelectorFilter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SelectorFilter.cpp; sourceTree = "<group>"; };
    84088412                415071561685067300C3C7B3 /* SelectorFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SelectorFilter.h; sourceTree = "<group>"; };
     
    2097120975                                A75E497510752ACB00C9B896 /* SerializedScriptValue.cpp */,
    2097220976                                A75E497410752ACB00C9B896 /* SerializedScriptValue.h */,
     20977                                414B82021D6DF0D90077EBE3 /* StructuredClone.cpp */,
     20978                                414B82031D6DF0D90077EBE3 /* StructuredClone.h */,
    2097320979                                419BE7521BC7F3DB00E1C85B /* WebCoreBuiltinNames.h */,
    2097420980                                BC53D910114310CC000D817E /* WebCoreJSClientData.h */,
     
    2692826934                                494BD7950F55C8EE00747828 /* WebKitPoint.h in Headers */,
    2692926935                                5709E8CF1D413D9A003244AC /* WebKitSubtleCrypto.h in Headers */,
     26936                                414B82051D6DF0E50077EBE3 /* StructuredClone.h in Headers */,
    2693026937                                31C0FF250E4CEB6E007D6FE5 /* WebKitTransitionEvent.h in Headers */,
    2693126938                                0FCF332F0F2B9A25004B6795 /* WebLayer.h in Headers */,
     
    2866928676                                511EF2C517F0FD3500E4FA16 /* JSIDBIndex.cpp in Sources */,
    2867028677                                5141299B1C6C16740059E714 /* JSIDBIndexCustom.cpp in Sources */,
     28678                                414B82041D6DF0DF0077EBE3 /* StructuredClone.cpp in Sources */,
    2867128679                                511EF2C617F0FD3500E4FA16 /* JSIDBKeyRange.cpp in Sources */,
    2867228680                                511EF2C717F0FD3500E4FA16 /* JSIDBObjectStore.cpp in Sources */,
  • trunk/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp

    r203818 r205117  
    3939#include "JSWorkerGlobalScope.h"
    4040#include "RuntimeEnabledFeatures.h"
     41#include "StructuredClone.h"
    4142#include "WebCoreJSClientData.h"
    4243#include "WorkerGlobalScope.h"
     44#include <builtins/BuiltinNames.h>
    4345
    4446using namespace JSC;
     
    106108    JSDOMGlobalObject::GlobalPropertyInfo staticGlobals[] = {
    107109        JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().makeThisTypeErrorPrivateName(),
    108                 JSFunction::create(vm, this, 2, String(), makeThisTypeErrorForBuiltins), DontDelete | ReadOnly),
     110            JSFunction::create(vm, this, 2, String(), makeThisTypeErrorForBuiltins), DontDelete | ReadOnly),
    109111        JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().makeGetterTypeErrorPrivateName(),
    110                 JSFunction::create(vm, this, 2, String(), makeGetterTypeErrorForBuiltins), DontDelete | ReadOnly),
     112            JSFunction::create(vm, this, 2, String(), makeGetterTypeErrorForBuiltins), DontDelete | ReadOnly),
     113        JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().structuredCloneArrayBufferPrivateName(),
     114            JSFunction::create(vm, this, 1, String(), structuredCloneArrayBuffer), DontDelete | ReadOnly),
     115        JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().structuredCloneArrayBufferViewPrivateName(),
     116            JSFunction::create(vm, this, 1, String(), structuredCloneArrayBufferView), DontDelete | ReadOnly),
     117        JSDOMGlobalObject::GlobalPropertyInfo(vm.propertyNames->builtinNames().ArrayBufferPrivateName(), getDirect(vm, vm.propertyNames->ArrayBuffer), DontDelete | ReadOnly),
    111118#if ENABLE(STREAMS_API)
    112119        JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().streamClosedPrivateName(), jsNumber(1), DontDelete | ReadOnly),
  • trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h

    r205110 r205117  
    9191    macro(streamWaiting) \
    9292    macro(streamWritable) \
     93    macro(structuredCloneArrayBuffer) \
     94    macro(structuredCloneArrayBufferView) \
    9395    macro(underlyingSink) \
    9496    macro(underlyingSource) \
Note: See TracChangeset for help on using the changeset viewer.