Title: [221329] trunk
Revision
221329
Author
[email protected]
Date
2017-08-29 17:39:26 -0700 (Tue, 29 Aug 2017)

Log Message

Add support for FetchRequest.body
https://bugs.webkit.org/show_bug.cgi?id=176066

Patch by Youenn Fablet <[email protected]> on 2017-08-29
Reviewed by Alex Christensen.

LayoutTests/imported/w3c:

* web-platform-tests/fetch/api/request/request-disturbed-expected.txt:
* web-platform-tests/fetch/api/request/request-idl-expected.txt:

Source/WebCore:

Covered by existing tests.

Adding support for body attribute getter for FetchRequest.
To do so, FetchRequest will need to create a ReadableStream.
Adding support for DOM based creation of ReadableStream and conversion to JS values.
Small refactoring to make names more consistent.

* CMakeLists.txt:
* Modules/beacon/NavigatorBeacon.cpp:
(WebCore::NavigatorBeacon::sendBeacon):
* Modules/cache/Cache.cpp:
(WebCore::Cache::put):
* Modules/fetch/FetchBody.cpp:
(WebCore::FetchBody::extract):
* Modules/fetch/FetchBody.h:
(WebCore::FetchBody::hasReadableStream const):
(WebCore::FetchBody::readableStream):
(WebCore::FetchBody::setReadableStream):
(WebCore::FetchBody::FetchBody):
(WebCore::FetchBody::isReadableStream const): Deleted.
(WebCore::FetchBody::setAsReadableStream): Deleted.
* Modules/fetch/FetchBody.idl:
* Modules/fetch/FetchBodyOwner.cpp:
(WebCore::FetchBodyOwner::readableStream):
* Modules/fetch/FetchBodyOwner.h:
(WebCore::FetchBodyOwner::hasReadableStreamBody const):
(WebCore::FetchBodyOwner::isReadableStreamBody const): Deleted.
* Modules/fetch/FetchRequest.cpp:
(WebCore::FetchRequest::setBody):
* Modules/fetch/FetchRequest.h:
* Modules/fetch/FetchResponse.cpp:
(WebCore::FetchResponse::setBodyAsReadableStream):
(WebCore::FetchResponse::fetch):
* Modules/fetch/FetchResponse.h:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/ReadableStream.h:
(WebCore::JSConverter<IDLInterface<ReadableStream>>::convert):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/imported/w3c/ChangeLog (221328 => 221329)


--- trunk/LayoutTests/imported/w3c/ChangeLog	2017-08-30 00:29:39 UTC (rev 221328)
+++ trunk/LayoutTests/imported/w3c/ChangeLog	2017-08-30 00:39:26 UTC (rev 221329)
@@ -1,3 +1,13 @@
+2017-08-29  Youenn Fablet  <[email protected]>
+
+        Add support for FetchRequest.body
+        https://bugs.webkit.org/show_bug.cgi?id=176066
+
+        Reviewed by Alex Christensen.
+
+        * web-platform-tests/fetch/api/request/request-disturbed-expected.txt:
+        * web-platform-tests/fetch/api/request/request-idl-expected.txt:
+
 2017-08-25  Youenn Fablet  <[email protected]>
 
         WPT server should not need to copy test harness files

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-disturbed-expected.txt (221328 => 221329)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-disturbed-expected.txt	2017-08-30 00:29:39 UTC (rev 221328)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-disturbed-expected.txt	2017-08-30 00:39:26 UTC (rev 221329)
@@ -1,9 +1,9 @@
 
-FAIL Request's body: initial state assert_equals: body's default value is null expected (object) null but got (undefined) undefined
+PASS Request's body: initial state 
 PASS Request without body cannot be disturbed 
 PASS Check cloning a disturbed request 
 PASS Check creating a new request from a disturbed request 
-FAIL Input request used for creating new request became disturbed assert_not_equals: body should not be undefined got disallowed value undefined
+FAIL Input request used for creating new request became disturbed assert_equals: body should not change expected object "[object ReadableStream]" but got object "[object ReadableStream]"
 FAIL Input request used for creating new request became disturbed even if body is not used assert_true: bodyUsed is true when request is disturbed expected true got false
 PASS Check consuming a disturbed request 
 PASS Request construction failure should not set "bodyUsed" 

Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-idl-expected.txt (221328 => 221329)


--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-idl-expected.txt	2017-08-30 00:29:39 UTC (rev 221328)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-idl-expected.txt	2017-08-30 00:39:26 UTC (rev 221329)
@@ -18,7 +18,7 @@
 PASS Request interface: attribute integrity 
 PASS Request interface: attribute keepalive 
 PASS Request interface: operation clone() 
-FAIL Request interface: attribute body assert_true: The prototype object must have a property "body" expected true got false
+PASS Request interface: attribute body 
 PASS Request interface: attribute bodyUsed 
 PASS Request interface: operation arrayBuffer() 
 PASS Request interface: operation blob() 
@@ -39,7 +39,7 @@
 PASS Request interface: new Request("") must inherit property "integrity" with the proper type (11) 
 PASS Request interface: new Request("") must inherit property "keepalive" with the proper type (12) 
 PASS Request interface: new Request("") must inherit property "clone" with the proper type (13) 
-FAIL Request interface: new Request("") must inherit property "body" with the proper type (14) assert_inherits: property "body" not found in prototype chain
+PASS Request interface: new Request("") must inherit property "body" with the proper type (14) 
 PASS Request interface: new Request("") must inherit property "bodyUsed" with the proper type (15) 
 PASS Request interface: new Request("") must inherit property "arrayBuffer" with the proper type (16) 
 PASS Request interface: new Request("") must inherit property "blob" with the proper type (17) 

Modified: trunk/Source/WebCore/CMakeLists.txt (221328 => 221329)


--- trunk/Source/WebCore/CMakeLists.txt	2017-08-30 00:29:39 UTC (rev 221328)
+++ trunk/Source/WebCore/CMakeLists.txt	2017-08-30 00:39:26 UTC (rev 221329)
@@ -1285,6 +1285,7 @@
     bindings/js/JSXMLHttpRequestCustom.cpp
     bindings/js/JSXPathNSResolverCustom.cpp
     bindings/js/JSXPathResultCustom.cpp
+    bindings/js/ReadableStream.cpp
     bindings/js/ReadableStreamDefaultController.cpp
     bindings/js/ScheduledAction.cpp
     bindings/js/ScriptCachedFrameData.cpp

Modified: trunk/Source/WebCore/ChangeLog (221328 => 221329)


--- trunk/Source/WebCore/ChangeLog	2017-08-30 00:29:39 UTC (rev 221328)
+++ trunk/Source/WebCore/ChangeLog	2017-08-30 00:39:26 UTC (rev 221329)
@@ -1,3 +1,48 @@
+2017-08-29  Youenn Fablet  <[email protected]>
+
+        Add support for FetchRequest.body
+        https://bugs.webkit.org/show_bug.cgi?id=176066
+
+        Reviewed by Alex Christensen.
+
+        Covered by existing tests.
+
+        Adding support for body attribute getter for FetchRequest.
+        To do so, FetchRequest will need to create a ReadableStream.
+        Adding support for DOM based creation of ReadableStream and conversion to JS values.
+        Small refactoring to make names more consistent.
+
+        * CMakeLists.txt:
+        * Modules/beacon/NavigatorBeacon.cpp:
+        (WebCore::NavigatorBeacon::sendBeacon):
+        * Modules/cache/Cache.cpp:
+        (WebCore::Cache::put):
+        * Modules/fetch/FetchBody.cpp:
+        (WebCore::FetchBody::extract):
+        * Modules/fetch/FetchBody.h:
+        (WebCore::FetchBody::hasReadableStream const):
+        (WebCore::FetchBody::readableStream):
+        (WebCore::FetchBody::setReadableStream):
+        (WebCore::FetchBody::FetchBody):
+        (WebCore::FetchBody::isReadableStream const): Deleted.
+        (WebCore::FetchBody::setAsReadableStream): Deleted.
+        * Modules/fetch/FetchBody.idl:
+        * Modules/fetch/FetchBodyOwner.cpp:
+        (WebCore::FetchBodyOwner::readableStream):
+        * Modules/fetch/FetchBodyOwner.h:
+        (WebCore::FetchBodyOwner::hasReadableStreamBody const):
+        (WebCore::FetchBodyOwner::isReadableStreamBody const): Deleted.
+        * Modules/fetch/FetchRequest.cpp:
+        (WebCore::FetchRequest::setBody):
+        * Modules/fetch/FetchRequest.h:
+        * Modules/fetch/FetchResponse.cpp:
+        (WebCore::FetchResponse::setBodyAsReadableStream):
+        (WebCore::FetchResponse::fetch):
+        * Modules/fetch/FetchResponse.h:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/ReadableStream.h:
+        (WebCore::JSConverter<IDLInterface<ReadableStream>>::convert):
+
 2017-08-29  Yusuke Suzuki  <[email protected]>
 
         [JSC] Use reifying system for "name" property of builtin JSFunction

Modified: trunk/Source/WebCore/Modules/beacon/NavigatorBeacon.cpp (221328 => 221329)


--- trunk/Source/WebCore/Modules/beacon/NavigatorBeacon.cpp	2017-08-30 00:29:39 UTC (rev 221328)
+++ trunk/Source/WebCore/Modules/beacon/NavigatorBeacon.cpp	2017-08-30 00:39:26 UTC (rev 221329)
@@ -130,7 +130,7 @@
         String mimeType;
         auto fetchBody = FetchBody::extract(document, WTFMove(body.value()), mimeType);
 
-        if (fetchBody.isReadableStream())
+        if (fetchBody.hasReadableStream())
             return Exception { TypeError, ASCIILiteral("Beacons cannot send ReadableStream body") };
 
         request.setHTTPBody(fetchBody.bodyAsFormData(document));

Modified: trunk/Source/WebCore/Modules/cache/Cache.cpp (221328 => 221329)


--- trunk/Source/WebCore/Modules/cache/Cache.cpp	2017-08-30 00:29:39 UTC (rev 221328)
+++ trunk/Source/WebCore/Modules/cache/Cache.cpp	2017-08-30 00:39:26 UTC (rev 221329)
@@ -296,7 +296,7 @@
     }
 
     // FIXME: Add support for ReadableStream.
-    if (response->isReadableStreamBody()) {
+    if (response->hasReadableStreamBody()) {
         promise.reject(Exception { NotSupportedError, ASCIILiteral("Caching a Response with data stored in a ReadableStream is not yet supported") });
         return;
     }

Modified: trunk/Source/WebCore/Modules/fetch/FetchBody.cpp (221328 => 221329)


--- trunk/Source/WebCore/Modules/fetch/FetchBody.cpp	2017-08-30 00:29:39 UTC (rev 221328)
+++ trunk/Source/WebCore/Modules/fetch/FetchBody.cpp	2017-08-30 00:39:26 UTC (rev 221329)
@@ -61,10 +61,8 @@
     }, [&](RefPtr<ArrayBufferView>& value) mutable {
         Ref<const ArrayBufferView> buffer = value.releaseNonNull();
         return FetchBody(WTFMove(buffer));
-    }, [&](RefPtr<ReadableStream>&) mutable {
-        FetchBody body;
-        body.m_isReadableStream = true;
-        return body;
+    }, [&](RefPtr<ReadableStream>& stream) mutable {
+        return FetchBody(stream.releaseNonNull());
     }, [&](String& value) {
         contentType = HTTPHeaderValues::textPlainContentType();
         return FetchBody(WTFMove(value));

Modified: trunk/Source/WebCore/Modules/fetch/FetchBody.h (221328 => 221329)


--- trunk/Source/WebCore/Modules/fetch/FetchBody.h	2017-08-30 00:29:39 UTC (rev 221328)
+++ trunk/Source/WebCore/Modules/fetch/FetchBody.h	2017-08-30 00:39:26 UTC (rev 221329)
@@ -60,13 +60,12 @@
     bool isArrayBufferView() const { return WTF::holds_alternative<Ref<const ArrayBufferView>>(m_data); }
     bool isURLSearchParams() const { return WTF::holds_alternative<Ref<const URLSearchParams>>(m_data); }
     bool isText() const { return WTF::holds_alternative<String>(m_data); }
-    bool isReadableStream() const { return m_isReadableStream; }
+    bool hasReadableStream() const { return !!m_readableStream; }
 
     using Init = Variant<RefPtr<Blob>, RefPtr<ArrayBufferView>, RefPtr<ArrayBuffer>, RefPtr<DOMFormData>, RefPtr<URLSearchParams>, RefPtr<ReadableStream>, String>;
     static FetchBody extract(ScriptExecutionContext&, Init&&, String&);
     static FetchBody loadingBody() { return { }; }
 
-    void setAsReadableStream() { m_isReadableStream = true; }
     void loadingFailed();
     void loadingSucceeded();
 
@@ -82,6 +81,12 @@
     void cleanConsumePromise() { m_consumePromise = nullptr; }
 
     FetchBody clone() const;
+    ReadableStream* readableStream() { return m_readableStream.get(); }
+    void setReadableStream(Ref<ReadableStream>&& stream)
+    {
+        ASSERT(!m_readableStream);
+        m_readableStream = WTFMove(stream);
+    }
 
 private:
     explicit FetchBody(Ref<const Blob>&& data) : m_data(WTFMove(data)) { }
@@ -91,6 +96,7 @@
     explicit FetchBody(String&& data) : m_data(WTFMove(data)) { }
     explicit FetchBody(Ref<const URLSearchParams>&& data) : m_data(WTFMove(data)) { }
     explicit FetchBody(const FetchBodyConsumer& consumer) : m_consumer(consumer) { }
+    explicit FetchBody(Ref<ReadableStream>&& stream) : m_readableStream(WTFMove(stream)) { }
     FetchBody() = default;
 
     void consume(FetchBodyOwner&, Ref<DeferredPromise>&&);
@@ -114,9 +120,7 @@
 
     FetchBodyConsumer m_consumer { FetchBodyConsumer::Type::None };
     RefPtr<DeferredPromise> m_consumePromise;
-
-    // FIXME: We probably want to keep the stream as a specific field in m_data when we will support stream data upload.
-    bool m_isReadableStream { false };
+    RefPtr<ReadableStream> m_readableStream;
 };
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/Modules/fetch/FetchBody.idl (221328 => 221329)


--- trunk/Source/WebCore/Modules/fetch/FetchBody.idl	2017-08-30 00:29:39 UTC (rev 221328)
+++ trunk/Source/WebCore/Modules/fetch/FetchBody.idl	2017-08-30 00:39:26 UTC (rev 221329)
@@ -33,7 +33,7 @@
     NoInterfaceObject
 ] interface FetchBody {
     // FIMXE: Add missing body attribute.
-    // readonly attribute ReadableStream? body;
+    [ImplementedAs=readableStream, CallWith=ScriptState] readonly attribute ReadableStream? body;
     readonly attribute boolean bodyUsed;
     [NewObject] Promise<ArrayBuffer> arrayBuffer();
     [NewObject] Promise<Blob> blob();

Modified: trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp (221328 => 221329)


--- trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp	2017-08-30 00:29:39 UTC (rev 221328)
+++ trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp	2017-08-30 00:39:26 UTC (rev 221329)
@@ -288,4 +288,15 @@
         owner.blobLoadingFailed();
 }
 
+ReadableStream* FetchBodyOwner::readableStream(JSC::ExecState& state)
+{
+    if (isBodyNull())
+        return nullptr;
+
+    if (!m_body->hasReadableStream())
+        m_body->setReadableStream(ReadableStream::create(state, m_readableStreamSource));
+
+    return m_body->readableStream();
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.h (221328 => 221329)


--- trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.h	2017-08-30 00:29:39 UTC (rev 221328)
+++ trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.h	2017-08-30 00:39:26 UTC (rev 221329)
@@ -57,7 +57,8 @@
 
     bool isActive() const { return !!m_blobLoader; }
 
-    bool isReadableStreamBody() const { return m_body && m_body->isReadableStream(); }
+    ReadableStream* readableStream(JSC::ExecState&);
+    virtual bool hasReadableStreamBody() const { return m_body && m_body->hasReadableStream(); }
 
 protected:
     const FetchBody& body() const { return *m_body; }

Modified: trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp (221328 => 221329)


--- trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp	2017-08-30 00:29:39 UTC (rev 221328)
+++ trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp	2017-08-30 00:39:26 UTC (rev 221329)
@@ -225,6 +225,7 @@
     if (!request.isBodyNull()) {
         if (!methodCanHaveBody(m_internalRequest))
             return Exception { TypeError };
+        // FIXME: If body has a readable stream, we should pipe it to this new body stream.
         m_body = WTFMove(request.m_body);
         request.setDisturbed();
     }

Modified: trunk/Source/WebCore/Modules/fetch/FetchRequest.h (221328 => 221329)


--- trunk/Source/WebCore/Modules/fetch/FetchRequest.h	2017-08-30 00:29:39 UTC (rev 221328)
+++ trunk/Source/WebCore/Modules/fetch/FetchRequest.h	2017-08-30 00:39:26 UTC (rev 221329)
@@ -85,7 +85,6 @@
     const ResourceRequest& internalRequest() const { return m_internalRequest.request; }
     const String& internalRequestReferrer() const { return m_internalRequest.referrer; }
     const URL& url() const { return m_internalRequest.request.url(); }
-    bool isBodyReadableStream() const { return !isBodyNull() && body().isReadableStream(); }
 
     ResourceRequest resourceRequest() const;
 

Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp (221328 => 221329)


--- trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp	2017-08-30 00:29:39 UTC (rev 221328)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp	2017-08-30 00:39:26 UTC (rev 221329)
@@ -83,7 +83,7 @@
 {
     if (isBodyNull())
         setBody(FetchBody::loadingBody());
-    body().setAsReadableStream();
+    m_isReadableStream = true;
     updateContentType();
 }
 
@@ -105,7 +105,7 @@
 
 void FetchResponse::fetch(ScriptExecutionContext& context, FetchRequest& request, NotificationCallback&& responseCallback)
 {
-    if (request.isBodyReadableStream()) {
+    if (request.hasReadableStreamBody()) {
         if (responseCallback)
             responseCallback(Exception { NotSupportedError, "ReadableStream uploading is not supported" });
         return;

Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.h (221328 => 221329)


--- trunk/Source/WebCore/Modules/fetch/FetchResponse.h	2017-08-30 00:29:39 UTC (rev 221328)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.h	2017-08-30 00:39:26 UTC (rev 221329)
@@ -102,6 +102,9 @@
 
     const ResourceResponse& resourceResponse() const { return m_response; }
 
+    // FIXME: Remove this method and use FetchBodyOwner one once we have full support in DOM ReadableStream.
+    bool hasReadableStreamBody() const final { return m_isReadableStream; }
+
 private:
     FetchResponse(ScriptExecutionContext&, std::optional<FetchBody>&&, Ref<FetchHeaders>&&, ResourceResponse&&);
 
@@ -144,6 +147,8 @@
     std::optional<BodyLoader> m_bodyLoader;
     mutable String m_responseURL;
     bool m_shouldExposeBody { true };
+    // FIXME: Remove that flag once we have full support in DOM ReadableStream.
+    bool m_isReadableStream { false };
 
     FetchBodyConsumer m_consumer { FetchBodyConsumer::Type::ArrayBuffer  };
 };

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (221328 => 221329)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-08-30 00:29:39 UTC (rev 221328)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2017-08-30 00:39:26 UTC (rev 221329)
@@ -1762,6 +1762,7 @@
 		41ABE67C1D0580E0006D862D /* CrossOriginPreflightChecker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41ABE6791D0580D5006D862D /* CrossOriginPreflightChecker.cpp */; };
 		41AD753A1CEF6BD100A31486 /* FetchOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 41AD75391CEF6BCE00A31486 /* FetchOptions.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		41B2A6261EF1BF6D002B9D7A /* WebAudioSourceProvider.h in Headers */ = {isa = PBXBuildFile; fileRef = 41B2A6251EF1BF60002B9D7A /* WebAudioSourceProvider.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		41B459EF1F55EBD10000F6FD /* ReadableStream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41B459ED1F55EBC70000F6FD /* ReadableStream.cpp */; };
 		41BF700C0FE86F49005E8DEC /* MessagePortChannel.h in Headers */ = {isa = PBXBuildFile; fileRef = 41BF700A0FE86F49005E8DEC /* MessagePortChannel.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		41BF700F0FE86F61005E8DEC /* PlatformMessagePortChannel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41BF700D0FE86F61005E8DEC /* PlatformMessagePortChannel.cpp */; };
 		41BF70100FE86F61005E8DEC /* PlatformMessagePortChannel.h in Headers */ = {isa = PBXBuildFile; fileRef = 41BF700E0FE86F61005E8DEC /* PlatformMessagePortChannel.h */; };
@@ -9485,6 +9486,7 @@
 		41AD75391CEF6BCE00A31486 /* FetchOptions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FetchOptions.h; sourceTree = "<group>"; };
 		41B2A6251EF1BF60002B9D7A /* WebAudioSourceProvider.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = WebAudioSourceProvider.h; sourceTree = "<group>"; };
 		41B459DA1F4CADB90000F6FD /* ReadableStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReadableStream.h; sourceTree = "<group>"; };
+		41B459ED1F55EBC70000F6FD /* ReadableStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ReadableStream.cpp; sourceTree = "<group>"; };
 		41BF700A0FE86F49005E8DEC /* MessagePortChannel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessagePortChannel.h; sourceTree = "<group>"; };
 		41BF700D0FE86F61005E8DEC /* PlatformMessagePortChannel.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = PlatformMessagePortChannel.cpp; path = default/PlatformMessagePortChannel.cpp; sourceTree = "<group>"; };
 		41BF700E0FE86F61005E8DEC /* PlatformMessagePortChannel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PlatformMessagePortChannel.h; path = default/PlatformMessagePortChannel.h; sourceTree = "<group>"; };
@@ -23877,6 +23879,7 @@
 				E1C36D320EB0A094007410BC /* JSWorkerGlobalScopeBase.cpp */,
 				E1C36D330EB0A094007410BC /* JSWorkerGlobalScopeBase.h */,
 				709A01FD1E3D0BCC006B0D4C /* ModuleFetchFailureKind.h */,
+				41B459ED1F55EBC70000F6FD /* ReadableStream.cpp */,
 				41B459DA1F4CADB90000F6FD /* ReadableStream.h */,
 				418C395E1C8F0AAB0051C8A3 /* ReadableStreamDefaultController.cpp */,
 				418C395F1C8F0AAB0051C8A3 /* ReadableStreamDefaultController.h */,
@@ -33293,6 +33296,7 @@
 				93F19AB908245E59001E9ABC /* Range.cpp in Sources */,
 				F55B3DCD1251F12D003EF269 /* RangeInputType.cpp in Sources */,
 				6E84E9E017668BEE00815B68 /* RasterShape.cpp in Sources */,
+				41B459EF1F55EBD10000F6FD /* ReadableStream.cpp in Sources */,
 				418C39611C8F0AB10051C8A3 /* ReadableStreamDefaultController.cpp in Sources */,
 				FD31603B12B0267600C1A359 /* RealtimeAnalyser.cpp in Sources */,
 				41103AAE1E39791000769F03 /* RealtimeIncomingAudioSource.cpp in Sources */,

Added: trunk/Source/WebCore/bindings/js/ReadableStream.cpp (0 => 221329)


--- trunk/Source/WebCore/bindings/js/ReadableStream.cpp	                        (rev 0)
+++ trunk/Source/WebCore/bindings/js/ReadableStream.cpp	2017-08-30 00:39:26 UTC (rev 221329)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2017 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 CANON 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 CANON 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 "ReadableStream.h"
+
+#include "JSReadableStreamSource.h"
+#include "WebCoreJSClientData.h"
+
+using namespace JSC;
+
+namespace WebCore {
+
+Ref<ReadableStream> ReadableStream::create(JSC::ExecState& execState, RefPtr<ReadableStreamSource>&& source)
+{
+    VM& vm = execState.vm();
+    auto& clientData = *static_cast<JSVMClientData*>(vm.clientData);
+    auto& globalObject = *JSC::jsCast<JSDOMGlobalObject*>(execState.lexicalGlobalObject());
+
+    auto* constructor = JSC::asObject(globalObject.get(&execState, clientData.builtinNames().ReadableStreamPrivateName()));
+
+    ConstructData constructData;
+    ConstructType constructType = constructor->methodTable(vm)->getConstructData(constructor, constructData);
+    ASSERT(constructType != ConstructType::None);
+
+    MarkedArgumentBuffer args;
+    args.append(source ? toJSNewlyCreated(&execState, &globalObject, source.releaseNonNull()) : JSC::jsUndefined());
+
+    auto newReadableStream = jsDynamicDowncast<JSReadableStream*>(vm, JSC::construct(&execState, constructor, constructType, constructData, args));
+
+    return create(globalObject, *newReadableStream);
+}
+
+}

Modified: trunk/Source/WebCore/bindings/js/ReadableStream.h (221328 => 221329)


--- trunk/Source/WebCore/bindings/js/ReadableStream.h	2017-08-30 00:29:39 UTC (rev 221328)
+++ trunk/Source/WebCore/bindings/js/ReadableStream.h	2017-08-30 00:39:26 UTC (rev 221329)
@@ -32,10 +32,14 @@
 
 namespace WebCore {
 
+class ReadableStreamSource;
+
 class ReadableStream final : public DOMGuarded<JSReadableStream> {
 public:
     static Ref<ReadableStream> create(JSDOMGlobalObject& globalObject, JSReadableStream& readableStream) { return adoptRef(*new ReadableStream(globalObject, readableStream)); }
 
+    static Ref<ReadableStream> create(JSC::ExecState&, RefPtr<ReadableStreamSource>&&);
+
     JSReadableStream* readableStream() { return guarded(); }
 
 protected:
@@ -64,4 +68,16 @@
     static constexpr bool needsState = true;
 };
 
+template<> struct JSConverter<IDLInterface<ReadableStream>> {
+    static constexpr bool needsState = false;
+    static constexpr bool needsGlobalObject = false;
+
+    static JSC::JSValue convert(ReadableStream* value)
+    {
+        if (!value)
+            return JSC::jsNull();
+        return value->readableStream();
+    }
+};
+
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to