[Streams API] Split ReadableStream/Reader implementation according source type (JS...
authoryouenn.fablet@crf.canon.fr <youenn.fablet@crf.canon.fr@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Apr 2015 08:07:34 +0000 (08:07 +0000)
committeryouenn.fablet@crf.canon.fr <youenn.fablet@crf.canon.fr@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 3 Apr 2015 08:07:34 +0000 (08:07 +0000)
https://bugs.webkit.org/show_bug.cgi?id=143130

Reviewed by Benjamin Poulain.

Introduce ReadableJSStream and ReadableJSStreamReader as subclasses of ReadableStream and ReadableStreamReader.
These classes manage JS based sources: ReadableStream JS constructor instantiates ReadableJStream.
These classes are expected to handle JS source specific handling, in particular JSValue error storage and JSValue chunk queue.
Making ReadableStream and ReadableStreamReader abstract, to be subclassed for native sources.

Current tests cover the changes.

* Modules/streams/ReadableStream.cpp:
(WebCore::ReadableStream::ReadableStream): Moved suspendIfNeeded inside constructor to ease subclassing.
(WebCore::ReadableStream::create): Deleted as ReadableStream is now abstarct.
* Modules/streams/ReadableStream.h: Made createReader virtual pure.
* Modules/streams/ReadableStream.idl: Skipping VTable validation as subclasses of ReadableStream may be JS wrapped.
* Modules/streams/ReadableStreamReader.cpp: Removed ReadableStreamReader::create.
* Modules/streams/ReadableStreamReader.h: Ditto.
* Modules/streams/ReadableStreamReader.idl: Skipping VTable validation as subclasses of ReadableStreamReader may be JS wrapped.
* bindings/js/JSReadableStreamCustom.cpp:
(WebCore::constructJSReadableStream): Instantiating ReadableJSStream in lieu of ReadableStream within JS constructor.
* bindings/js/ReadableStreamJSSource.cpp:
(WebCore::ReadableJSStream::create):
(WebCore::ReadableJSStream::createReader): Instantiating ReadableJSStreamReader.
(WebCore::ReadableJSStream::ReadableJSStream):
(WebCore::ReadableJSStreamReader::create):
(WebCore::ReadableJSStreamReader::ReadableJSStreamReader):
* bindings/js/ReadableStreamJSSource.h: Definition of ReadableJSStream and ReadableJSStreamReader.

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

Source/WebCore/ChangeLog
Source/WebCore/Modules/streams/ReadableStream.cpp
Source/WebCore/Modules/streams/ReadableStream.h
Source/WebCore/Modules/streams/ReadableStream.idl
Source/WebCore/Modules/streams/ReadableStreamReader.cpp
Source/WebCore/Modules/streams/ReadableStreamReader.h
Source/WebCore/Modules/streams/ReadableStreamReader.idl
Source/WebCore/bindings/js/JSReadableStreamCustom.cpp
Source/WebCore/bindings/js/ReadableStreamJSSource.cpp
Source/WebCore/bindings/js/ReadableStreamJSSource.h

index 2408319ad2523202e6eae0f742a955db9e2c1b9d..d44e3e23a8190d762b83731911eb6c352a981de0 100644 (file)
@@ -1,3 +1,35 @@
+2015-04-01 Xabier Rodriguez Calvar <calvaris@igalia.com> and Youenn Fablet <youenn.fablet@crf.canon.fr>
+
+        [Streams API] Split ReadableStream/Reader implementation according source type (JS vs native)
+        https://bugs.webkit.org/show_bug.cgi?id=143130
+
+        Reviewed by Benjamin Poulain.
+
+        Introduce ReadableJSStream and ReadableJSStreamReader as subclasses of ReadableStream and ReadableStreamReader.
+        These classes manage JS based sources: ReadableStream JS constructor instantiates ReadableJStream.
+        These classes are expected to handle JS source specific handling, in particular JSValue error storage and JSValue chunk queue.
+        Making ReadableStream and ReadableStreamReader abstract, to be subclassed for native sources.
+
+        Current tests cover the changes.
+
+        * Modules/streams/ReadableStream.cpp:
+        (WebCore::ReadableStream::ReadableStream): Moved suspendIfNeeded inside constructor to ease subclassing.
+        (WebCore::ReadableStream::create): Deleted as ReadableStream is now abstarct.
+        * Modules/streams/ReadableStream.h: Made createReader virtual pure.
+        * Modules/streams/ReadableStream.idl: Skipping VTable validation as subclasses of ReadableStream may be JS wrapped.
+        * Modules/streams/ReadableStreamReader.cpp: Removed ReadableStreamReader::create.
+        * Modules/streams/ReadableStreamReader.h: Ditto.
+        * Modules/streams/ReadableStreamReader.idl: Skipping VTable validation as subclasses of ReadableStreamReader may be JS wrapped.
+        * bindings/js/JSReadableStreamCustom.cpp:
+        (WebCore::constructJSReadableStream): Instantiating ReadableJSStream in lieu of ReadableStream within JS constructor.
+        * bindings/js/ReadableStreamJSSource.cpp:
+        (WebCore::ReadableJSStream::create):
+        (WebCore::ReadableJSStream::createReader): Instantiating ReadableJSStreamReader.
+        (WebCore::ReadableJSStream::ReadableJSStream):
+        (WebCore::ReadableJSStreamReader::create):
+        (WebCore::ReadableJSStreamReader::ReadableJSStreamReader):
+        * bindings/js/ReadableStreamJSSource.h: Definition of ReadableJSStream and ReadableJSStreamReader.
+
 2015-04-02  Timothy Horton  <timothy_horton@apple.com>
 
         Scrollbars are left in the wrong position when resizing a fixed layout view
index e104b67b1e1ac038d829e988975e249b02a40c8d..60ba835c5cb679f869ae19a514aeaa62a7a1ac44 100644 (file)
@@ -40,14 +40,6 @@ namespace WebCore {
 
 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, readableStreamCounter, ("ReadableStream"));
 
-Ref<ReadableStream> ReadableStream::create(ScriptExecutionContext& scriptExecutionContext, Ref<ReadableStreamSource>&& source)
-{
-    auto readableStream = adoptRef(*new ReadableStream(scriptExecutionContext, WTF::move(source)));
-    readableStream.get().suspendIfNeeded();
-
-    return readableStream;
-}
-
 ReadableStream::ReadableStream(ScriptExecutionContext& scriptExecutionContext, Ref<ReadableStreamSource>&& source)
     : ActiveDOMObject(&scriptExecutionContext)
     , m_state(State::Readable)
@@ -56,6 +48,7 @@ ReadableStream::ReadableStream(ScriptExecutionContext& scriptExecutionContext, R
 #ifndef NDEBUG
     readableStreamCounter.increment();
 #endif
+    suspendIfNeeded();
 }
 
 ReadableStream::~ReadableStream()
@@ -76,11 +69,6 @@ bool ReadableStream::canSuspend() const
     return false;
 }
 
-Ref<ReadableStreamReader> ReadableStream::createReader()
-{
-    return ReadableStreamReader::create(*this);
-}
-
 }
 
 #endif
index bf5141adacfef2597672a909e32de817051cbe87..263247ba828b0815830ba10a8657b74dad0bb31d 100644 (file)
@@ -55,19 +55,19 @@ public:
         Errored
     };
 
-    static Ref<ReadableStream> create(ScriptExecutionContext&, Ref<ReadableStreamSource>&&);
     virtual ~ReadableStream();
 
     ReadableStreamReader* reader() { return m_reader; }
     void lock(ReadableStreamReader& reader) { m_reader = &reader; }
     void release() { m_reader = nullptr; }
-    Ref<ReadableStreamReader> createReader();
+    virtual Ref<ReadableStreamReader> createReader() = 0;
 
     State internalState() { return m_state; }
 
-private:
+protected:
     ReadableStream(ScriptExecutionContext&, Ref<ReadableStreamSource>&&);
 
+private:
     // ActiveDOMObject API.
     const char* activeDOMObjectName() const override;
     bool canSuspend() const override;
index 92872be4ce5932edd15249b50726f9cbd22212aa..c0558003e558db8b84b9f2f71cf434f1f3789927 100644 (file)
@@ -29,7 +29,8 @@
 
 [
     CustomConstructor(any properties),
-    Conditional=STREAMS_API
+    Conditional=STREAMS_API,
+    SkipVTableValidation
 ] interface ReadableStream {
     // FIXME: Remove RaisesException once methods are actually implemented.
     [Custom, RaisesException] Promise cancel(DOMString reason);
index fc76e48501578da6ee02d73bbaea01b52cebfdf1..6f39989940aadc82186e2d555715e3d3677e2a6c 100644 (file)
@@ -39,12 +39,6 @@ namespace WebCore {
 
 DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, readableStreamReaderCounter, ("ReadableStreamReader"));
 
-Ref<ReadableStreamReader> ReadableStreamReader::create(ReadableStream& stream)
-{
-    auto readableStreamReader = adoptRef(*new ReadableStreamReader(stream));
-    return readableStreamReader;
-}
-
 ReadableStreamReader::ReadableStreamReader(ReadableStream& stream)
     : ActiveDOMObject(stream.scriptExecutionContext())
 {
index 64b6dd23efda76c5630f9b25b1e4d3f4c7e4bb2c..b9bf2bdd825b9407f6b46f6867d81662f90b4631 100644 (file)
@@ -46,7 +46,6 @@ namespace WebCore {
 // See https://streams.spec.whatwg.org/#reader-class for more information.
 class ReadableStreamReader : public ActiveDOMObject, public ScriptWrappable, public RefCounted<ReadableStreamReader> {
 public:
-    static Ref<ReadableStreamReader> create(ReadableStream&);
     virtual ~ReadableStreamReader();
 
     ReadableStream* stream() { return m_stream.get(); }
@@ -55,9 +54,10 @@ public:
     typedef std::function<void()> ClosedErrorCallback;
     void closed(ClosedSuccessCallback, ClosedErrorCallback);
 
-private:
+protected:
     ReadableStreamReader(ReadableStream&);
 
+private:
     // ActiveDOMObject API.
     const char* activeDOMObjectName() const override;
     bool canSuspend() const override;
index 80aa1d18314bef9094e497dd965527f7bd0f1634..44049428e632d0c437507a0c3261d06222b3ecaa 100644 (file)
@@ -30,7 +30,8 @@
 [
     ActiveDOMObject,
     CustomConstructor(any properties),
-    Conditional=STREAMS_API
+    Conditional=STREAMS_API,
+    SkipVTableValidation
 ] interface ReadableStreamReader {
     // FIXME: Remove RaisesException once methods are implemented.
     [Custom, RaisesException] Object read();
index f912ab312a914748115ac6ff16566c4d0faa8030..59865155a83cb03eadc0f541beca7e75f2f5b420 100644 (file)
@@ -80,9 +80,8 @@ EncodedJSValue JSC_HOST_CALL constructJSReadableStream(ExecState* exec)
     ASSERT(jsConstructor);
     ScriptExecutionContext* scriptExecutionContext = jsConstructor->scriptExecutionContext();
 
-
     Ref<ReadableStreamJSSource> source = ReadableStreamJSSource::create(exec);
-    RefPtr<ReadableStream> readableStream = ReadableStream::create(*scriptExecutionContext, Ref<ReadableStreamSource>(source.get()));
+    RefPtr<ReadableStream> readableStream = ReadableJSStream::create(*scriptExecutionContext, Ref<ReadableStreamJSSource>(source.get()));
 
     VM& vm = exec->vm();
     JSGlobalObject* globalObject = exec->callee()->globalObject();
index 0fbc8967705f6c2294c8b3be29aa7954570a5394..c49486cdaa40b3a71552f40a863841c498e3fcb3 100644 (file)
@@ -81,6 +81,34 @@ void ReadableStreamJSSource::start(JSC::ExecState*)
     notImplemented();
 }
 
+Ref<ReadableJSStream> ReadableJSStream::create(ScriptExecutionContext& scriptExecutionContext, Ref<ReadableStreamJSSource>&& source)
+{
+    auto readableStream = adoptRef(*new ReadableJSStream(scriptExecutionContext, WTF::move(source)));
+    return readableStream;
+}
+
+Ref<ReadableStreamReader> ReadableJSStream::createReader()
+{
+    RefPtr<ReadableStreamReader> reader = ReadableJSStreamReader::create(*this);
+    return reader.releaseNonNull();
+}
+
+ReadableJSStream::ReadableJSStream(ScriptExecutionContext& scriptExecutionContext, Ref<ReadableStreamJSSource>&& source)
+    : ReadableStream(scriptExecutionContext, WTF::move(source))
+{
+}
+
+Ref<ReadableJSStreamReader> ReadableJSStreamReader::create(ReadableJSStream& stream)
+{
+    auto readableStreamReader = adoptRef(*new ReadableJSStreamReader(stream));
+    return readableStreamReader;
+}
+
+ReadableJSStreamReader::ReadableJSStreamReader(ReadableJSStream& readableStream)
+    : ReadableStreamReader(readableStream)
+{
+}
+
 } // namespace WebCore
 
 #endif
index a3e437d556a97c067f6fb51e6ded2d33f152f7b3..e0ead0289523e18b5e02fcebf06c509d2dfabef0 100644 (file)
@@ -32,6 +32,8 @@
 
 #if ENABLE(STREAMS_API)
 
+#include "ReadableStream.h"
+#include "ReadableStreamReader.h"
 #include "ReadableStreamSource.h"
 #include <heap/Strong.h>
 #include <heap/StrongInlines.h>
@@ -54,6 +56,21 @@ private:
     ReadableStreamJSSource(JSC::ExecState*);
 };
 
+class ReadableJSStream: public ReadableStream {
+public:
+    static Ref<ReadableJSStream> create(ScriptExecutionContext&, Ref<ReadableStreamJSSource>&&);
+    virtual Ref<ReadableStreamReader> createReader() override;
+private:
+    ReadableJSStream(ScriptExecutionContext&, Ref<ReadableStreamJSSource>&&);
+};
+
+class ReadableJSStreamReader: public ReadableStreamReader {
+public:
+    static Ref<ReadableJSStreamReader> create(ReadableJSStream&);
+private:
+    ReadableJSStreamReader(ReadableJSStream&);
+};
+
 void setInternalSlotToObject(JSC::ExecState*, JSC::JSValue, JSC::PrivateName&, JSC::JSValue);
 JSC::JSValue getInternalSlotFromObject(JSC::ExecState*, JSC::JSValue, JSC::PrivateName&);