Title: [205117] trunk
Revision
205117
Author
commit-qu...@webkit.org
Date
2016-08-29 03:52:42 -0700 (Mon, 29 Aug 2016)

Log Message

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

Patch by Youenn Fablet <you...@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/_javascript_Core:

* 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:

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (205116 => 205117)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2016-08-29 09:33:40 UTC (rev 205116)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2016-08-29 10:52:42 UTC (rev 205117)
@@ -1,5 +1,15 @@
 2016-08-29  Youenn Fablet  <you...@apple.com>
 
+        [Fetch API] Response cloning should structureClone when teeing Response stream
+        https://bugs.webkit.org/show_bug.cgi?id=161147
+
+        Reviewed by Darin Adler.
+
+        * web-platform-tests/fetch/api/response/response-clone-expected.txt:
+        * web-platform-tests/fetch/api/response/response-clone.html:
+
+2016-08-29  Youenn Fablet  <you...@apple.com>
+
         [Fetch API] Add support for BufferSource bodies
         https://bugs.webkit.org/show_bug.cgi?id=161087
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-clone-expected.txt (205116 => 205117)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-clone-expected.txt	2016-08-29 09:33:40 UTC (rev 205116)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-clone-expected.txt	2016-08-29 10:52:42 UTC (rev 205117)
@@ -6,4 +6,15 @@
 PASS Cannot clone a disturbed response 
 PASS Cloned responses should provide the same data 
 PASS Cancelling stream should not affect cloned one 
+PASS Check response clone use structureClone for teed ReadableStreams (Int8Arraychunk) 
+PASS Check response clone use structureClone for teed ReadableStreams (Int16Arraychunk) 
+PASS Check response clone use structureClone for teed ReadableStreams (Int32Arraychunk) 
+PASS Check response clone use structureClone for teed ReadableStreams (ArrayBufferchunk) 
+PASS Check response clone use structureClone for teed ReadableStreams (Uint8Arraychunk) 
+PASS Check response clone use structureClone for teed ReadableStreams (Uint8ClampedArraychunk) 
+PASS Check response clone use structureClone for teed ReadableStreams (Uint16Arraychunk) 
+PASS Check response clone use structureClone for teed ReadableStreams (Uint32Arraychunk) 
+PASS Check response clone use structureClone for teed ReadableStreams (Float32Arraychunk) 
+PASS Check response clone use structureClone for teed ReadableStreams (Float64Arraychunk) 
+PASS Check response clone use structureClone for teed ReadableStreams (DataViewchunk) 
 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-clone.html (205116 => 205117)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-clone.html	2016-08-29 09:33:40 UTC (rev 205116)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-clone.html	2016-08-29 10:52:42 UTC (rev 205117)
@@ -93,6 +93,46 @@
         });
     }, 'Cancelling stream should not affect cloned one');
 
+function testReadableStreamClone(initialBuffer, bufferType)
+{
+    promise_test(function(test) {
+        var response = new Response(new ReadableStream({start : function(controller) {
+            controller.enqueue(initialBuffer);
+            controller.close();
+        }}));
+
+        var clone = response.clone();
+        var stream1 = response.body;
+        var stream2 = clone.body;
+
+        var buffer;
+        return stream1.getReader().read().then(function(data) {
+            assert_false(data.done);
+            assert_array_equals(data.value, initialBuffer, "Cloned buffer chunks have the same content");
+            assert_equals(Object.getPrototypeOf(data.value), Object.getPrototypeOf(initialBuffer), "Cloned buffers have the same type");
+            assert_true(data.value !== initialBuffer, "Cloned buffers are different objects");
+            return stream2.getReader().read();
+        }).then(function(data) {
+            assert_false(data.done);
+            assert_array_equals(data.value, initialBuffer, "Cloned buffer chunks have the same content");
+            assert_equals(Object.getPrototypeOf(data.value), Object.getPrototypeOf(initialBuffer), "Cloned buffers have the same type");
+            assert_true(data.value !== initialBuffer, "Cloned buffers are different objects");
+        });
+    }, "Check response clone use structureClone for teed ReadableStreams (" + bufferType  + "chunk)");
+}
+
+var arrayBuffer = new ArrayBuffer(16);
+testReadableStreamClone(new Int8Array(arrayBuffer, 1), "Int8Array");
+testReadableStreamClone(new Int16Array(arrayBuffer, 2, 2), "Int16Array");
+testReadableStreamClone(new Int32Array(arrayBuffer), "Int32Array");
+testReadableStreamClone(arrayBuffer, "ArrayBuffer");
+testReadableStreamClone(new Uint8Array(arrayBuffer), "Uint8Array");
+testReadableStreamClone(new Uint8ClampedArray(arrayBuffer), "Uint8ClampedArray");
+testReadableStreamClone(new Uint16Array(arrayBuffer, 2), "Uint16Array");
+testReadableStreamClone(new Uint32Array(arrayBuffer), "Uint32Array");
+testReadableStreamClone(new Float32Array(arrayBuffer), "Float32Array");
+testReadableStreamClone(new Float64Array(arrayBuffer), "Float64Array");
+testReadableStreamClone(new DataView(arrayBuffer, 2, 8), "DataView");
     </script>
   </body>
 </html>

Modified: trunk/Source/_javascript_Core/ChangeLog (205116 => 205117)


--- trunk/Source/_javascript_Core/ChangeLog	2016-08-29 09:33:40 UTC (rev 205116)
+++ trunk/Source/_javascript_Core/ChangeLog	2016-08-29 10:52:42 UTC (rev 205117)
@@ -1,3 +1,15 @@
+2016-08-29  Youenn Fablet  <you...@apple.com>
+
+        [Fetch API] Response cloning should structureClone when teeing Response stream
+        https://bugs.webkit.org/show_bug.cgi?id=161147
+
+        Reviewed by Darin Adler.
+
+        * 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.
+
 2016-08-29  Benjamin Poulain  <bpoul...@apple.com>
 
         [JSC] Improve ArithAbs with polymorphic input

Modified: trunk/Source/_javascript_Core/builtins/BuiltinNames.h (205116 => 205117)


--- trunk/Source/_javascript_Core/builtins/BuiltinNames.h	2016-08-29 09:33:40 UTC (rev 205116)
+++ trunk/Source/_javascript_Core/builtins/BuiltinNames.h	2016-08-29 10:52:42 UTC (rev 205117)
@@ -36,7 +36,6 @@
 #define JSC_COMMON_PRIVATE_IDENTIFIERS_EACH_PROPERTY_NAME(macro) \
     JSC_COMMON_BYTECODE_INTRINSIC_FUNCTIONS_EACH_NAME(macro) \
     JSC_COMMON_BYTECODE_INTRINSIC_CONSTANTS_EACH_NAME(macro) \
-    macro(iteratedObject) \
     macro(arrayIteratorNextIndex) \
     macro(arrayIterationKind) \
     macro(arrayIteratorNext) \
@@ -43,6 +42,8 @@
     macro(arrayIteratorIsDone) \
     macro(arrayIteratorKind) \
     macro(charCodeAt) \
+    macro(isView) \
+    macro(iteratedObject) \
     macro(iteratedString) \
     macro(stringIteratorNextIndex) \
     macro(promise) \
@@ -55,6 +56,7 @@
     macro(ownEnumerablePropertyKeys) \
     macro(Number) \
     macro(Array) \
+    macro(ArrayBuffer) \
     macro(String) \
     macro(RegExp) \
     macro(Map) \

Modified: trunk/Source/_javascript_Core/runtime/JSArrayBufferConstructor.cpp (205116 => 205117)


--- trunk/Source/_javascript_Core/runtime/JSArrayBufferConstructor.cpp	2016-08-29 09:33:40 UTC (rev 205116)
+++ trunk/Source/_javascript_Core/runtime/JSArrayBufferConstructor.cpp	2016-08-29 10:52:42 UTC (rev 205117)
@@ -26,6 +26,7 @@
 #include "config.h"
 #include "JSArrayBufferConstructor.h"
 
+#include "BuiltinNames.h"
 #include "Error.h"
 #include "ExceptionHelpers.h"
 #include "GetterSetter.h"
@@ -57,6 +58,7 @@
 
     JSGlobalObject* globalObject = this->globalObject();
     JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->isView, arrayBufferFuncIsView, DontEnum, 1);
+    JSC_NATIVE_FUNCTION_WITHOUT_TRANSITION(vm.propertyNames->builtinNames().isViewPrivateName(), arrayBufferFuncIsView, DontEnum, 1);
 }
 
 JSArrayBufferConstructor* JSArrayBufferConstructor::create(VM& vm, Structure* structure, JSArrayBufferPrototype* prototype, GetterSetter* speciesSymbol)

Modified: trunk/Source/_javascript_Core/runtime/JSDataView.h (205116 => 205117)


--- trunk/Source/_javascript_Core/runtime/JSDataView.h	2016-08-29 09:33:40 UTC (rev 205116)
+++ trunk/Source/_javascript_Core/runtime/JSDataView.h	2016-08-29 10:52:42 UTC (rev 205117)
@@ -40,7 +40,7 @@
     JSDataView(VM&, ConstructionContext&, ArrayBuffer*);
     
 public:
-    static JSDataView* create(
+    JS_EXPORT_PRIVATE static JSDataView* create(
         ExecState*, Structure*, PassRefPtr<ArrayBuffer>, unsigned byteOffset,
         unsigned byteLength);
     

Modified: trunk/Source/WebCore/CMakeLists.txt (205116 => 205117)


--- trunk/Source/WebCore/CMakeLists.txt	2016-08-29 09:33:40 UTC (rev 205116)
+++ trunk/Source/WebCore/CMakeLists.txt	2016-08-29 10:52:42 UTC (rev 205117)
@@ -1257,6 +1257,7 @@
     bindings/js/ScriptController.cpp
     bindings/js/ScriptGlobalObject.cpp
     bindings/js/ScriptState.cpp
+    bindings/js/StructuredClone.cpp
     bindings/js/SerializedScriptValue.cpp
     bindings/js/WebCoreTypedArrayController.cpp
     bindings/js/WorkerScriptController.cpp

Modified: trunk/Source/WebCore/ChangeLog (205116 => 205117)


--- trunk/Source/WebCore/ChangeLog	2016-08-29 09:33:40 UTC (rev 205116)
+++ trunk/Source/WebCore/ChangeLog	2016-08-29 10:52:42 UTC (rev 205117)
@@ -1,3 +1,32 @@
+2016-08-29  Youenn Fablet  <you...@apple.com>
+
+        [Fetch API] Response cloning should structureClone when teeing Response stream
+        https://bugs.webkit.org/show_bug.cgi?id=161147
+
+        Reviewed by Darin Adler.
+
+        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: 
+
 2016-08-16  Carlos Garcia Campos  <cgar...@igalia.com>
 
         [GTK] Accelerated compositing does not work in Wayland

Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.js (205116 => 205117)


--- trunk/Source/WebCore/Modules/fetch/FetchResponse.js	2016-08-29 09:33:40 UTC (rev 205116)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.js	2016-08-29 10:52:42 UTC (rev 205117)
@@ -96,7 +96,7 @@
     }
 
     if (this.@body) {
-        var teedReadableStreams = @teeReadableStream(this.@body, false);
+        var teedReadableStreams = @teeReadableStream(this.@body, true);
         this.@body = teedReadableStreams[0];
         cloned.@body = teedReadableStreams[1];
     }

Modified: trunk/Source/WebCore/Modules/streams/ReadableStreamInternals.js (205116 => 205117)


--- trunk/Source/WebCore/Modules/streams/ReadableStreamInternals.js	2016-08-29 09:33:40 UTC (rev 205116)
+++ trunk/Source/WebCore/Modules/streams/ReadableStreamInternals.js	2016-08-29 10:52:42 UTC (rev 205117)
@@ -111,6 +111,20 @@
     return [branch1, branch2];
 }
 
+function doStructuredClone(object)
+{
+    // FIXME: We should implement http://w3c.github.io/html/infrastructure.html#ref-for-structured-clone-4
+    // Implementation is currently limited to ArrayBuffer/ArrayBufferView to meet Fetch API needs.
+
+    if (object instanceof @ArrayBuffer)
+        return @structuredCloneArrayBuffer(object);
+
+    if (@ArrayBuffer.@isView(object))
+        return @structuredCloneArrayBufferView(object);
+
+    throw new @TypeError("structuredClone not implemented for: " + object);
+}
+
 function teeReadableStreamPullFunction(teeState, reader, shouldClone)
 {
     "use strict";
@@ -126,14 +140,10 @@
             }
             if (teeState.closedOrErrored)
                 return;
-            if (!teeState.canceled1) {
-                // FIXME: Implement cloning if shouldClone is true
-                @enqueueInReadableStream(teeState.branch1, result.value);
-            }
-            if (!teeState.canceled2) {
-                // FIXME: Implement cloning if shouldClone is true
-                @enqueueInReadableStream(teeState.branch2, result.value);
-            }
+            if (!teeState.canceled1)
+                @enqueueInReadableStream(teeState.branch1, shouldClone ? @doStructuredClone(result.value) : result.value);
+            if (!teeState.canceled2)
+                @enqueueInReadableStream(teeState.branch2, shouldClone ? @doStructuredClone(result.value) : result.value);
         });
     }
 }

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (205116 => 205117)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2016-08-29 09:33:40 UTC (rev 205116)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2016-08-29 10:52:42 UTC (rev 205117)
@@ -1513,6 +1513,8 @@
 		413C2C341BC29A8F0075204C /* JSDOMConstructor.h in Headers */ = {isa = PBXBuildFile; fileRef = 413C2C331BC29A7B0075204C /* JSDOMConstructor.h */; };
 		4147E2B71C89912C00A7E715 /* FetchLoader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4147E2B41C89912600A7E715 /* FetchLoader.cpp */; };
 		4147E2B81C89912F00A7E715 /* FetchBodyOwner.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4147E2B31C89912600A7E715 /* FetchBodyOwner.cpp */; };
+		414B82041D6DF0DF0077EBE3 /* StructuredClone.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 414B82021D6DF0D90077EBE3 /* StructuredClone.cpp */; };
+		414B82051D6DF0E50077EBE3 /* StructuredClone.h in Headers */ = {isa = PBXBuildFile; fileRef = 414B82031D6DF0D90077EBE3 /* StructuredClone.h */; };
 		415071571685067300C3C7B3 /* SelectorFilter.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 415071551685067300C3C7B3 /* SelectorFilter.cpp */; };
 		415071581685067300C3C7B3 /* SelectorFilter.h in Headers */ = {isa = PBXBuildFile; fileRef = 415071561685067300C3C7B3 /* SelectorFilter.h */; };
 		4150F9F112B6E0E70008C860 /* SliderThumbElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 4150F9EF12B6E0E70008C860 /* SliderThumbElement.h */; };
@@ -8404,6 +8406,8 @@
 		4147E2B41C89912600A7E715 /* FetchLoader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FetchLoader.cpp; sourceTree = "<group>"; };
 		4147E2B51C89912600A7E715 /* FetchLoader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FetchLoader.h; sourceTree = "<group>"; };
 		4147E2B61C89912600A7E715 /* FetchLoaderClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FetchLoaderClient.h; sourceTree = "<group>"; };
+		414B82021D6DF0D90077EBE3 /* StructuredClone.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StructuredClone.cpp; sourceTree = "<group>"; };
+		414B82031D6DF0D90077EBE3 /* StructuredClone.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StructuredClone.h; sourceTree = "<group>"; };
 		415071551685067300C3C7B3 /* SelectorFilter.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SelectorFilter.cpp; sourceTree = "<group>"; };
 		415071561685067300C3C7B3 /* SelectorFilter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SelectorFilter.h; sourceTree = "<group>"; };
 		4150F9EF12B6E0E70008C860 /* SliderThumbElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SliderThumbElement.h; sourceTree = "<group>"; };
@@ -20970,6 +20974,8 @@
 				1400D7A717136EA70077CE05 /* ScriptWrappableInlines.h */,
 				A75E497510752ACB00C9B896 /* SerializedScriptValue.cpp */,
 				A75E497410752ACB00C9B896 /* SerializedScriptValue.h */,
+				414B82021D6DF0D90077EBE3 /* StructuredClone.cpp */,
+				414B82031D6DF0D90077EBE3 /* StructuredClone.h */,
 				419BE7521BC7F3DB00E1C85B /* WebCoreBuiltinNames.h */,
 				BC53D910114310CC000D817E /* WebCoreJSClientData.h */,
 				0F099D0617B968A100FF84B9 /* WebCoreTypedArrayController.cpp */,
@@ -26927,6 +26933,7 @@
 				A5DEBDA416FB908700836FE0 /* WebKitPlaybackTargetAvailabilityEvent.h in Headers */,
 				494BD7950F55C8EE00747828 /* WebKitPoint.h in Headers */,
 				5709E8CF1D413D9A003244AC /* WebKitSubtleCrypto.h in Headers */,
+				414B82051D6DF0E50077EBE3 /* StructuredClone.h in Headers */,
 				31C0FF250E4CEB6E007D6FE5 /* WebKitTransitionEvent.h in Headers */,
 				0FCF332F0F2B9A25004B6795 /* WebLayer.h in Headers */,
 				0709D78F1AE55554004E42F8 /* WebMediaSessionManager.h in Headers */,
@@ -28668,6 +28675,7 @@
 				511EF2C417F0FD3500E4FA16 /* JSIDBFactory.cpp in Sources */,
 				511EF2C517F0FD3500E4FA16 /* JSIDBIndex.cpp in Sources */,
 				5141299B1C6C16740059E714 /* JSIDBIndexCustom.cpp in Sources */,
+				414B82041D6DF0DF0077EBE3 /* StructuredClone.cpp in Sources */,
 				511EF2C617F0FD3500E4FA16 /* JSIDBKeyRange.cpp in Sources */,
 				511EF2C717F0FD3500E4FA16 /* JSIDBObjectStore.cpp in Sources */,
 				511EF2D117F0FDF100E4FA16 /* JSIDBObjectStoreCustom.cpp in Sources */,

Modified: trunk/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp (205116 => 205117)


--- trunk/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp	2016-08-29 09:33:40 UTC (rev 205116)
+++ trunk/Source/WebCore/bindings/js/JSDOMGlobalObject.cpp	2016-08-29 10:52:42 UTC (rev 205117)
@@ -38,8 +38,10 @@
 #include "JSReadableStreamPrivateConstructors.h"
 #include "JSWorkerGlobalScope.h"
 #include "RuntimeEnabledFeatures.h"
+#include "StructuredClone.h"
 #include "WebCoreJSClientData.h"
 #include "WorkerGlobalScope.h"
+#include <builtins/BuiltinNames.h>
 
 using namespace JSC;
 
@@ -105,9 +107,14 @@
     JSVMClientData& clientData = *static_cast<JSVMClientData*>(vm.clientData);
     JSDOMGlobalObject::GlobalPropertyInfo staticGlobals[] = {
         JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().makeThisTypeErrorPrivateName(),
-                JSFunction::create(vm, this, 2, String(), makeThisTypeErrorForBuiltins), DontDelete | ReadOnly),
+            JSFunction::create(vm, this, 2, String(), makeThisTypeErrorForBuiltins), DontDelete | ReadOnly),
         JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().makeGetterTypeErrorPrivateName(),
-                JSFunction::create(vm, this, 2, String(), makeGetterTypeErrorForBuiltins), DontDelete | ReadOnly),
+            JSFunction::create(vm, this, 2, String(), makeGetterTypeErrorForBuiltins), DontDelete | ReadOnly),
+        JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().structuredCloneArrayBufferPrivateName(),
+            JSFunction::create(vm, this, 1, String(), structuredCloneArrayBuffer), DontDelete | ReadOnly),
+        JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().structuredCloneArrayBufferViewPrivateName(),
+            JSFunction::create(vm, this, 1, String(), structuredCloneArrayBufferView), DontDelete | ReadOnly),
+        JSDOMGlobalObject::GlobalPropertyInfo(vm.propertyNames->builtinNames().ArrayBufferPrivateName(), getDirect(vm, vm.propertyNames->ArrayBuffer), DontDelete | ReadOnly),
 #if ENABLE(STREAMS_API)
         JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().streamClosedPrivateName(), jsNumber(1), DontDelete | ReadOnly),
         JSDOMGlobalObject::GlobalPropertyInfo(clientData.builtinNames().streamClosingPrivateName(), jsNumber(2), DontDelete | ReadOnly),

Added: trunk/Source/WebCore/bindings/js/StructuredClone.cpp (0 => 205117)


--- trunk/Source/WebCore/bindings/js/StructuredClone.cpp	                        (rev 0)
+++ trunk/Source/WebCore/bindings/js/StructuredClone.cpp	2016-08-29 10:52:42 UTC (rev 205117)
@@ -0,0 +1,94 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+#include "config.h"
+#include "StructuredClone.h"
+
+#include "ExceptionCode.h"
+#include "JSDOMBinding.h"
+#include <runtime/JSTypedArrays.h>
+
+using namespace JSC;
+
+namespace WebCore {
+
+EncodedJSValue JSC_HOST_CALL structuredCloneArrayBuffer(ExecState* execState)
+{
+    ASSERT(execState);
+    ASSERT(execState->argumentCount());
+    ASSERT(execState->lexicalGlobalObject());
+
+    ArrayBuffer* buffer = toArrayBuffer(execState->uncheckedArgument(0));
+    if (!buffer) {
+        setDOMException(execState, DATA_CLONE_ERR);
+        return JSValue::encode(jsUndefined());
+    }
+
+    return JSValue::encode(JSArrayBuffer::create(execState->vm(), execState->lexicalGlobalObject()->arrayBufferStructure(), ArrayBuffer::tryCreate(buffer->data(), buffer->byteLength())));
+}
+
+EncodedJSValue JSC_HOST_CALL structuredCloneArrayBufferView(ExecState* execState)
+{
+    ASSERT(execState);
+    ASSERT(execState->argumentCount());
+
+    JSValue value = execState->uncheckedArgument(0);
+    auto* bufferView = JSC::jsDynamicCast<JSArrayBufferView*>(value);
+    ASSERT(bufferView);
+
+    auto* buffer = bufferView->buffer();
+    if (!buffer) {
+        setDOMException(execState, DATA_CLONE_ERR);
+        return JSValue::encode(jsUndefined());
+    }
+    auto bufferClone = ArrayBuffer::tryCreate(buffer->data(), buffer->byteLength());
+
+    if (JSC::jsDynamicCast<JSInt8Array*>(value))
+        return JSValue::encode(JSInt8Array::create(execState, bufferView->structure(), WTFMove(bufferClone), bufferView->byteOffset(), bufferView->length()));
+    if (JSC::jsDynamicCast<JSInt16Array*>(value))
+        return JSValue::encode(JSInt16Array::create(execState, bufferView->structure(), WTFMove(bufferClone), bufferView->byteOffset(), bufferView->length()));
+    if (JSC::jsDynamicCast<JSInt32Array*>(value))
+        return JSValue::encode(JSInt32Array::create(execState, bufferView->structure(), WTFMove(bufferClone), bufferView->byteOffset(), bufferView->length()));
+    if (JSC::jsDynamicCast<JSUint8Array*>(value))
+        return JSValue::encode(JSUint8Array::create(execState, bufferView->structure(), WTFMove(bufferClone), bufferView->byteOffset(), bufferView->length()));
+    if (JSC::jsDynamicCast<JSUint8ClampedArray*>(value))
+        return JSValue::encode(JSUint8ClampedArray::create(execState, bufferView->structure(), WTFMove(bufferClone), bufferView->byteOffset(), bufferView->length()));
+    if (JSC::jsDynamicCast<JSUint16Array*>(value))
+        return JSValue::encode(JSUint16Array::create(execState, bufferView->structure(), WTFMove(bufferClone), bufferView->byteOffset(), bufferView->length()));
+    if (JSC::jsDynamicCast<JSUint32Array*>(value))
+        return JSValue::encode(JSUint32Array::create(execState, bufferView->structure(), WTFMove(bufferClone), bufferView->byteOffset(), bufferView->length()));
+    if (JSC::jsDynamicCast<JSFloat32Array*>(value))
+        return JSValue::encode(JSFloat32Array::create(execState, bufferView->structure(), WTFMove(bufferClone), bufferView->byteOffset(), bufferView->length()));
+    if (JSC::jsDynamicCast<JSFloat64Array*>(value))
+        return JSValue::encode(JSFloat64Array::create(execState, bufferView->structure(), WTFMove(bufferClone), bufferView->byteOffset(), bufferView->length()));
+    if (JSC::jsDynamicCast<JSDataView*>(value))
+        return JSValue::encode(JSDataView::create(execState, bufferView->structure(), WTFMove(bufferClone), bufferView->byteOffset(), bufferView->length()));
+
+    ASSERT_NOT_REACHED();
+    return JSValue::encode(jsUndefined());
+}
+
+} // namespace WebCore

Added: trunk/Source/WebCore/bindings/js/StructuredClone.h (0 => 205117)


--- trunk/Source/WebCore/bindings/js/StructuredClone.h	                        (rev 0)
+++ trunk/Source/WebCore/bindings/js/StructuredClone.h	2016-08-29 10:52:42 UTC (rev 205117)
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All Rights Reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+namespace JSC {
+using EncodedJSValue = int64_t;
+class ExecState;
+}
+
+namespace WebCore {
+
+JSC::EncodedJSValue JSC_HOST_CALL structuredCloneArrayBuffer(JSC::ExecState*);
+JSC::EncodedJSValue JSC_HOST_CALL structuredCloneArrayBufferView(JSC::ExecState*);
+
+} // namespace WebCore

Modified: trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h (205116 => 205117)


--- trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h	2016-08-29 09:33:40 UTC (rev 205116)
+++ trunk/Source/WebCore/bindings/js/WebCoreBuiltinNames.h	2016-08-29 10:52:42 UTC (rev 205117)
@@ -90,6 +90,8 @@
     macro(streamReadable) \
     macro(streamWaiting) \
     macro(streamWritable) \
+    macro(structuredCloneArrayBuffer) \
+    macro(structuredCloneArrayBufferView) \
     macro(underlyingSink) \
     macro(underlyingSource) \
     macro(writing) \
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to