[Streams API] ReadableJSStream does not need a ReadableStreamSource
authoryouenn.fablet@crf.canon.fr <youenn.fablet@crf.canon.fr@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 4 Jun 2015 07:52:55 +0000 (07:52 +0000)
committeryouenn.fablet@crf.canon.fr <youenn.fablet@crf.canon.fr@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 4 Jun 2015 07:52:55 +0000 (07:52 +0000)
https://bugs.webkit.org/show_bug.cgi?id=145601

Reviewed by Darin Adler.

Covered by existing tests.

* Modules/streams/ReadableStream.cpp:
(WebCore::ReadableStream::ReadableStream): Remoed m_source.
* Modules/streams/ReadableStream.h: Ditto
* Modules/streams/ReadableStreamSource.h: Deleted.
* WebCore.vcxproj/WebCore.vcxproj: Removing Modules/streams/ReadableStreamSource.h.
* WebCore.vcxproj/WebCore.vcxproj.filters: Ditto.
* WebCore.xcodeproj/project.pbxproj: Ditto.
* bindings/js/ReadableJSStream.cpp:
(WebCore::ReadableJSStream::globalObject):
(WebCore::ReadableJSStream::doStart): Equivalent of ReadableJSStream::Source::start().
(WebCore::ReadableJSStream::create): Updated according new constructor.
(WebCore::ReadableJSStream::ReadableJSStream):
(WebCore::startReadableStreamAsync): Deleted.
(WebCore::ReadableJSStream::jsController): Deleted.
(WebCore::ReadableJSStream::storeError): Deleted.
* bindings/js/ReadableJSStream.h: Added m_source member to store the JS source as a JS object.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@185196 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/Modules/streams/ReadableStream.cpp
Source/WebCore/Modules/streams/ReadableStream.h
Source/WebCore/Modules/streams/ReadableStreamSource.h [deleted file]
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/ReadableJSStream.cpp
Source/WebCore/bindings/js/ReadableJSStream.h

index 4639f50..00621b2 100644 (file)
@@ -1,3 +1,29 @@
+2015-06-04  Xabier Rodriguez Calvar  <calvaris@igalia.com> and Youenn Fablet <youenn.fablet@crf.canon.fr>
+
+        [Streams API] ReadableJSStream does not need a ReadableStreamSource
+        https://bugs.webkit.org/show_bug.cgi?id=145601
+
+        Reviewed by Darin Adler.
+
+        Covered by existing tests.
+
+        * Modules/streams/ReadableStream.cpp:
+        (WebCore::ReadableStream::ReadableStream): Remoed m_source.
+        * Modules/streams/ReadableStream.h: Ditto
+        * Modules/streams/ReadableStreamSource.h: Deleted.
+        * WebCore.vcxproj/WebCore.vcxproj: Removing Modules/streams/ReadableStreamSource.h.
+        * WebCore.vcxproj/WebCore.vcxproj.filters: Ditto.
+        * WebCore.xcodeproj/project.pbxproj: Ditto.
+        * bindings/js/ReadableJSStream.cpp:
+        (WebCore::ReadableJSStream::globalObject):
+        (WebCore::ReadableJSStream::doStart): Equivalent of ReadableJSStream::Source::start().
+        (WebCore::ReadableJSStream::create): Updated according new constructor.
+        (WebCore::ReadableJSStream::ReadableJSStream):
+        (WebCore::startReadableStreamAsync): Deleted.
+        (WebCore::ReadableJSStream::jsController): Deleted.
+        (WebCore::ReadableJSStream::storeError): Deleted.
+        * bindings/js/ReadableJSStream.h: Added m_source member to store the JS source as a JS object.
+
 2015-06-04  Zan Dobersek  <zdobersek@igalia.com>
 
         Shrink the ArabicCharShapingMode enum in SVGGlyph.cpp
index f019b44..80c0562 100644 (file)
@@ -41,9 +41,8 @@ namespace WebCore {
 
 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, readableStreamCounter, ("ReadableStream"));
 
-ReadableStream::ReadableStream(ScriptExecutionContext& scriptExecutionContext, Ref<ReadableStreamSource>&& source)
+ReadableStream::ReadableStream(ScriptExecutionContext& scriptExecutionContext)
     : ActiveDOMObject(&scriptExecutionContext)
-    , m_source(WTF::move(source))
 {
 #ifndef NDEBUG
     readableStreamCounter.increment();
index 2bd2ca5..d1d3344 100644 (file)
 #if ENABLE(STREAMS_API)
 
 #include "ActiveDOMObject.h"
-#include "ReadableStreamSource.h"
 #include "ScriptWrappable.h"
 #include <functional>
 #include <wtf/Ref.h>
+#include <wtf/RefCounted.h>
+#include <wtf/Vector.h>
 
 namespace JSC {
 class JSValue;
@@ -73,8 +74,6 @@ public:
     void changeStateToClosed();
     void changeStateToErrored();
 
-    ReadableStreamSource& source() { return m_source.get(); }
-
     typedef std::function<void(JSC::JSValue)> FailureCallback;
 
     typedef std::function<void()> ClosedSuccessCallback;
@@ -85,7 +84,7 @@ public:
     void read(ReadSuccessCallback&&, ReadEndCallback&&, FailureCallback&&);
 
 protected:
-    ReadableStream(ScriptExecutionContext&, Ref<ReadableStreamSource>&&);
+    explicit ReadableStream(ScriptExecutionContext&);
 
 private:
     // ActiveDOMObject API.
@@ -111,7 +110,6 @@ private:
     Vector<ReadCallbacks> m_readRequests;
 
     State m_state { State::Readable };
-    Ref<ReadableStreamSource> m_source;
 };
 
 }
diff --git a/Source/WebCore/Modules/streams/ReadableStreamSource.h b/Source/WebCore/Modules/streams/ReadableStreamSource.h
deleted file mode 100644 (file)
index a8fcf21..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Copyright (C) 2015 Canon Inc.
- * Copyright (C) 2015 Igalia S.L.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted, provided that the following conditions
- * are required to be 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.
- * 3.  Neither the name of Canon Inc. nor the names of
- *     its contributors may be used to endorse or promote products derived
- *     from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY CANON INC. AND ITS CONTRIBUTORS "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. AND ITS 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.
- */
-
-#ifndef ReadableStreamSource_h
-#define ReadableStreamSource_h
-
-#if ENABLE(STREAMS_API)
-
-#include "ExceptionCode.h"
-#include <wtf/RefCounted.h>
-#include <wtf/text/WTFString.h>
-
-namespace WebCore {
-
-// ReadableStreamSource is the interface used by ReadableStream to pull data.
-class ReadableStreamSource: public RefCounted<ReadableStreamSource> {
-public:
-    virtual ~ReadableStreamSource() { }
-
-    virtual void pull() { }
-
-    virtual bool shouldApplyBackpressure(unsigned /*queueSize*/)
-    {
-        return true;
-    }
-
-    // Return true if cancelled (sync case) and false in async case.
-    virtual bool cancel(const String& /*reason*/)
-    {
-        return true;
-    }
-};
-
-}
-
-#endif
-
-#endif // ReadableStreamSource_h
index 689bc54..46ff32d 100644 (file)
     <ClInclude Include="..\Modules\streams\ReadableStream.h" />
     <ClInclude Include="..\Modules\streams\ReadableStreamController.h" />
     <ClInclude Include="..\Modules\streams\ReadableStreamReader.h" />
-    <ClInclude Include="..\Modules\streams\ReadableStreamSource.h" />
     <ClInclude Include="..\Modules\webdatabase\AbstractDatabaseServer.h" />
     <ClInclude Include="..\Modules\webdatabase\ChangeVersionData.h" />
     <ClInclude Include="..\Modules\webdatabase\ChangeVersionWrapper.h" />
   <ImportGroup Label="ExtensionTargets">
     <Import Project="$(VCTargetsPath)\BuildCustomizations\masm.targets" />
   </ImportGroup>
-</Project>
\ No newline at end of file
+</Project>
index 28b0001..d2c6d1b 100644 (file)
     <ClInclude Include="..\platform\graphics\FontCascadeFonts.h">
       <Filter>platform\graphics</Filter>
     </ClInclude>
-    <ClInclude Include="..\Modules\streams\ReadableStreamSource.h">
-      <Filter>Modules\streams</Filter>
-    </ClInclude>
     <ClInclude Include="..\Modules\streams\ReadableStream.h">
       <Filter>Modules\streams</Filter>
     </ClInclude>
index 4e717a4..d7d5cca 100644 (file)
                419FAFB11ABABDED005B828B /* JSReadableStreamReaderCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 419FAFB01ABABD7B005B828B /* JSReadableStreamReaderCustom.cpp */; };
                41A023EF1A39DB7A00F722CF /* ReadableStream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41A023EB1A39DB7900F722CF /* ReadableStream.cpp */; };
                41A023F01A39DB7A00F722CF /* ReadableStream.h in Headers */ = {isa = PBXBuildFile; fileRef = 41A023EC1A39DB7900F722CF /* ReadableStream.h */; };
-               41A023F21A39DB7A00F722CF /* ReadableStreamSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 41A023EE1A39DB7A00F722CF /* ReadableStreamSource.h */; };
                41A023F61A39DBCB00F722CF /* JSReadableStreamCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41A023F31A39DBCB00F722CF /* JSReadableStreamCustom.cpp */; };
                41A3D58E101C152D00316D07 /* DedicatedWorkerThread.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41A3D58C101C152D00316D07 /* DedicatedWorkerThread.cpp */; };
                41A3D58F101C152D00316D07 /* DedicatedWorkerThread.h in Headers */ = {isa = PBXBuildFile; fileRef = 41A3D58D101C152D00316D07 /* DedicatedWorkerThread.h */; };
                41A023EB1A39DB7900F722CF /* ReadableStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ReadableStream.cpp; sourceTree = "<group>"; };
                41A023EC1A39DB7900F722CF /* ReadableStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReadableStream.h; sourceTree = "<group>"; };
                41A023ED1A39DB7900F722CF /* ReadableStream.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ReadableStream.idl; sourceTree = "<group>"; };
-               41A023EE1A39DB7A00F722CF /* ReadableStreamSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReadableStreamSource.h; sourceTree = "<group>"; };
                41A023F31A39DBCB00F722CF /* JSReadableStreamCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSReadableStreamCustom.cpp; sourceTree = "<group>"; };
                41A3D58C101C152D00316D07 /* DedicatedWorkerThread.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DedicatedWorkerThread.cpp; sourceTree = "<group>"; };
                41A3D58D101C152D00316D07 /* DedicatedWorkerThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DedicatedWorkerThread.h; sourceTree = "<group>"; };
                                419FAFAB1ABABCD5005B828B /* ReadableStreamReader.cpp */,
                                419FAFAC1ABABCD5005B828B /* ReadableStreamReader.h */,
                                419FAFAD1ABABCD5005B828B /* ReadableStreamReader.idl */,
-                               41A023EE1A39DB7A00F722CF /* ReadableStreamSource.h */,
                        );
                        path = streams;
                        sourceTree = "<group>";
                                4198BDF11A81143100B22FB5 /* ReadableJSStream.h in Headers */,
                                41A023F01A39DB7A00F722CF /* ReadableStream.h in Headers */,
                                419FAFAF1ABABD0C005B828B /* ReadableStreamReader.h in Headers */,
-                               41A023F21A39DB7A00F722CF /* ReadableStreamSource.h in Headers */,
                                FD31603C12B0267600C1A359 /* RealtimeAnalyser.h in Headers */,
                                4A4F65711AA997F100E38CDD /* RealtimeMediaSource.h in Headers */,
                                4A4F65721AA997F100E38CDD /* RealtimeMediaSourceCapabilities.h in Headers */,
index d487314..c9593a9 100644 (file)
@@ -59,19 +59,7 @@ static inline JSValue callFunction(ExecState* exec, JSValue jsFunction, JSValue
     return call(exec, jsFunction, callType, callData, thisValue, arguments, exception);
 }
 
-Ref<ReadableJSStream::Source> ReadableJSStream::Source::create(ExecState& exec)
-{
-    return adoptRef(*new Source(exec));
-}
-
-ReadableJSStream::Source::Source(ExecState& exec)
-{
-    ASSERT_WITH_MESSAGE(!exec.argumentCount() || exec.argument(0).isObject(), "Caller of ReadableJSStream::Source constructor should ensure that passed argument if any is an object.");
-    JSObject* source =  exec.argumentCount() ? exec.argument(0).getObject() : JSFinalObject::create(exec.vm(), JSFinalObject::createStructure(exec.vm(), exec.callee()->globalObject(), jsNull(), 1));
-    m_source.set(exec.vm(), source);
-}
-
-JSDOMGlobalObject* ReadableJSStream::Source::globalObject()
+JSDOMGlobalObject* ReadableJSStream::globalObject()
 {
     return jsDynamicCast<JSDOMGlobalObject*>(m_source->globalObject());
 }
@@ -84,7 +72,7 @@ static void startReadableStreamAsync(ReadableStream& readableStream)
     });
 }
 
-void ReadableJSStream::Source::start(ExecState& exec, ReadableJSStream& readableStream)
+void ReadableJSStream::doStart(ExecState& exec)
 {
     JSLockHolder lock(&exec);
 
@@ -93,12 +81,12 @@ void ReadableJSStream::Source::start(ExecState& exec, ReadableJSStream& readable
         if (!startFunction.isUndefined())
             throwVMError(&exec, createTypeError(&exec, ASCIILiteral("ReadableStream constructor object start property should be a function.")));
         else
-            startReadableStreamAsync(readableStream);
+            startReadableStreamAsync(*this);
         return;
     }
 
     MarkedArgumentBuffer arguments;
-    arguments.append(readableStream.jsController(exec, globalObject()));
+    arguments.append(jsController(exec, globalObject()));
 
     JSValue exception;
     callFunction(&exec, startFunction, m_source.get(), arguments, &exception);
@@ -109,26 +97,23 @@ void ReadableJSStream::Source::start(ExecState& exec, ReadableJSStream& readable
     }
 
     // FIXME: Implement handling promise as result of calling start function.
-    startReadableStreamAsync(readableStream);
+    startReadableStreamAsync(*this);
 }
 
 Ref<ReadableJSStream> ReadableJSStream::create(ExecState& exec, ScriptExecutionContext& scriptExecutionContext)
 {
-    Ref<ReadableJSStream::Source> source = ReadableJSStream::Source::create(exec);
-    Ref<ReadableJSStream> readableStream = adoptRef(*new ReadableJSStream(scriptExecutionContext, WTF::move(source)));
+    ASSERT_WITH_MESSAGE(!exec.argumentCount() || exec.argument(0).isObject(), "Caller of ReadableJSStream constructor should ensure that passed argument if any is an object.");
+    JSObject* source =  exec.argumentCount() ? exec.argument(0).getObject() : JSFinalObject::create(exec.vm(), JSFinalObject::createStructure(exec.vm(), exec.callee()->globalObject(), jsNull(), 1));
 
-    readableStream->jsSource().start(exec, readableStream.get());
+    Ref<ReadableJSStream> readableStream = adoptRef(*new ReadableJSStream(scriptExecutionContext, exec, source));
+    readableStream->doStart(exec);
     return readableStream;
 }
 
-ReadableJSStream::ReadableJSStream(ScriptExecutionContext& scriptExecutionContext, Ref<ReadableJSStream::Source>&& source)
-    : ReadableStream(scriptExecutionContext, WTF::move(source))
-{
-}
-
-ReadableJSStream::Source& ReadableJSStream::jsSource()
+ReadableJSStream::ReadableJSStream(ScriptExecutionContext& scriptExecutionContext, ExecState& exec, JSObject* source)
+    : ReadableStream(scriptExecutionContext)
 {
-    return static_cast<ReadableJSStream::Source&>(source());
+    m_source.set(exec.vm(), source);
 }
 
 JSValue ReadableJSStream::jsController(ExecState& exec, JSDOMGlobalObject* globalObject)
index 68ab89a..6c572fe 100644 (file)
@@ -33,8 +33,6 @@
 #if ENABLE(STREAMS_API)
 
 #include "ReadableStream.h"
-#include "ReadableStreamReader.h"
-#include "ReadableStreamSource.h"
 #include <heap/Strong.h>
 #include <heap/StrongInlines.h>
 #include <runtime/JSCJSValue.h>
@@ -47,37 +45,27 @@ class JSDOMGlobalObject;
 class ReadableStreamController;
 
 class ReadableJSStream: public ReadableStream {
-private:
-    class Source: public ReadableStreamSource {
-    public:
-        static Ref<Source> create(JSC::ExecState&);
-
-        JSDOMGlobalObject* globalObject();
-        void start(JSC::ExecState&, ReadableJSStream&);
-
-    private:
-        Source(JSC::ExecState&);
-
-        JSC::Strong<JSC::JSObject> m_source;
-    };
-
 public:
     static Ref<ReadableJSStream> create(JSC::ExecState&, ScriptExecutionContext&);
 
-    ReadableJSStream::Source& jsSource();
     JSC::JSValue jsController(JSC::ExecState&, JSDOMGlobalObject*);
 
     void storeError(JSC::ExecState&);
     JSC::JSValue error() { return m_error.get(); }
 
 private:
-    ReadableJSStream(ScriptExecutionContext&, Ref<ReadableJSStream::Source>&&);
+    ReadableJSStream(ScriptExecutionContext&, JSC::ExecState&, JSC::JSObject*);
+
+    void doStart(JSC::ExecState&);
 
     virtual bool hasValue() const override;
     virtual JSC::JSValue read() override;
 
+    JSDOMGlobalObject* globalObject();
+
     std::unique_ptr<ReadableStreamController> m_controller;
     JSC::Strong<JSC::Unknown> m_error;
+    JSC::Strong<JSC::JSObject> m_source;
 };
 
 } // namespace WebCore