[Streams API] Refactor ReadableJSStream and ReadableStreamJSSource
authoryouenn.fablet@crf.canon.fr <youenn.fablet@crf.canon.fr@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 May 2015 13:30:18 +0000 (13:30 +0000)
committeryouenn.fablet@crf.canon.fr <youenn.fablet@crf.canon.fr@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 4 May 2015 13:30:18 +0000 (13:30 +0000)
https://bugs.webkit.org/show_bug.cgi?id=144387

Reviewed by Darin Adler.

Made ReadableStreamReader a private class of ReadableJSStream.
Simplified ReadableJSStream construction so that binding constructor does not need to know about ReadableStreamJSSource.

No functional change, existing tests cover the changes.

* Modules/streams/ReadableStream.h:
(WebCore::ReadableStream::source): Added to implement jsSource(), needed by ReadableJSStream.
* bindings/js/JSReadableStreamCustom.cpp:
(WebCore::constructJSReadableStream): Simplified to not have to handle source creation.
* bindings/js/ReadableStreamJSSource.cpp:
(WebCore::ReadableStreamJSSource::globalObject): Helper function to be used in other future methods.
(WebCore::ReadableStreamJSSource::start):
(WebCore::ReadableJSStream::create):
(WebCore::ReadableJSStream::createReader):
(WebCore::ReadableJSStream::jsSource):
(WebCore::ReadableJSStream::Reader::create):
(WebCore::ReadableJSStream::Reader::Reader):
* bindings/js/ReadableStreamJSSource.h:

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

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

index 593c409615a688509f4a174ffb70ca13a5497cce..bc761d1eb57391efd8f2f9fb5dd4fb4556859a3f 100644 (file)
@@ -1,3 +1,29 @@
+2015-05-04  Xabier Rodriguez Calvar  <calvaris@igalia.com> and Youenn Fablet  <youenn.fablet@crf.canon.fr>
+
+        [Streams API] Refactor ReadableJSStream and ReadableStreamJSSource
+        https://bugs.webkit.org/show_bug.cgi?id=144387
+
+        Reviewed by Darin Adler.
+
+        Made ReadableStreamReader a private class of ReadableJSStream.
+        Simplified ReadableJSStream construction so that binding constructor does not need to know about ReadableStreamJSSource. 
+
+        No functional change, existing tests cover the changes.
+
+        * Modules/streams/ReadableStream.h:
+        (WebCore::ReadableStream::source): Added to implement jsSource(), needed by ReadableJSStream.
+        * bindings/js/JSReadableStreamCustom.cpp:
+        (WebCore::constructJSReadableStream): Simplified to not have to handle source creation.
+        * bindings/js/ReadableStreamJSSource.cpp:
+        (WebCore::ReadableStreamJSSource::globalObject): Helper function to be used in other future methods.
+        (WebCore::ReadableStreamJSSource::start):
+        (WebCore::ReadableJSStream::create):
+        (WebCore::ReadableJSStream::createReader):
+        (WebCore::ReadableJSStream::jsSource):
+        (WebCore::ReadableJSStream::Reader::create):
+        (WebCore::ReadableJSStream::Reader::Reader):
+        * bindings/js/ReadableStreamJSSource.h:
+
 2015-05-04  Csaba Osztrogon√°c  <ossy@webkit.org>
 
         Remove move-js-headers.sh
 2015-05-04  Csaba Osztrogon√°c  <ossy@webkit.org>
 
         Remove move-js-headers.sh
index 5b5727bde8bcaf7f5a3bbd287154f50553f68202..2e5888d456a953535280149a8c2ac739d0e36db9 100644 (file)
@@ -70,6 +70,8 @@ public:
     void start();
     void changeStateToClosed();
 
     void start();
     void changeStateToClosed();
 
+    ReadableStreamSource& source() { return m_source.get(); }
+
 protected:
     ReadableStream(ScriptExecutionContext&, Ref<ReadableStreamSource>&&);
 
 protected:
     ReadableStream(ScriptExecutionContext&, Ref<ReadableStreamSource>&&);
 
index d8b0681163f714c1a2b63e65f169ea9da08e65d4..11a015394b4affa80a7cb753b70c5e99337b603b 100644 (file)
@@ -78,18 +78,9 @@ EncodedJSValue JSC_HOST_CALL constructJSReadableStream(ExecState* exec)
 
     DOMConstructorObject* jsConstructor = jsCast<DOMConstructorObject*>(exec->callee());
     ASSERT(jsConstructor);
 
     DOMConstructorObject* jsConstructor = jsCast<DOMConstructorObject*>(exec->callee());
     ASSERT(jsConstructor);
-    ScriptExecutionContext* scriptExecutionContext = jsConstructor->scriptExecutionContext();
 
 
-    Ref<ReadableStreamJSSource> source = ReadableStreamJSSource::create(exec);
-    RefPtr<ReadableStream> readableStream = ReadableJSStream::create(*scriptExecutionContext, Ref<ReadableStreamJSSource>(source.get()));
-
-    VM& vm = exec->vm();
-    JSGlobalObject* globalObject = exec->callee()->globalObject();
-    JSReadableStream* jsReadableStream = JSReadableStream::create(JSReadableStream::createStructure(vm, globalObject, JSReadableStream::createPrototype(vm, globalObject)), jsCast<JSDOMGlobalObject*>(globalObject), readableStream.releaseNonNull());
-
-    source->start(exec, jsReadableStream);
-
-    return JSValue::encode(jsReadableStream);
+    Ref<ReadableJSStream> readableStream = ReadableJSStream::create(*exec, *jsConstructor->scriptExecutionContext());
+    return JSValue::encode(toJS(exec, jsCast<JSDOMGlobalObject*>(exec->callee()->globalObject()), WTF::move(readableStream)));
 }
 
 } // namespace WebCore
 }
 
 } // namespace WebCore
index 05228f7958c2e79067b75f6dd3cb376f41991dc7..2220ecd131ca2241fb1108a2c59d99d28b4a8c0d 100644 (file)
@@ -102,19 +102,24 @@ static void startReadableStreamAsync(ReadableStream& readableStream)
     });
 }
 
     });
 }
 
-void ReadableStreamJSSource::start(JSC::ExecState* exec, JSReadableStream* readableStream)
+JSDOMGlobalObject* ReadableStreamJSSource::globalObject()
 {
 {
-    JSLockHolder lock(exec);
+    return jsDynamicCast<JSDOMGlobalObject*>(m_source->globalObject());
+}
+
+void ReadableStreamJSSource::start(ExecState& exec, ReadableJSStream& readableStream)
+{
+    JSLockHolder lock(&exec);
 
 
-    Ref<ReadableStreamController> controller = ReadableStreamController::create(static_cast<ReadableJSStream&>(readableStream->impl()));
-    m_controller.set(exec->vm(), jsDynamicCast<JSReadableStreamController*>(toJS(exec, readableStream->globalObject(), controller)));
+    Ref<ReadableStreamController> controller = ReadableStreamController::create(readableStream);
+    m_controller.set(exec.vm(), jsDynamicCast<JSReadableStreamController*>(toJS(&exec, globalObject(), controller)));
 
 
-    JSValue startFunction = getPropertyFromObject(exec, m_source.get(), "start");
+    JSValue startFunction = getPropertyFromObject(&exec, m_source.get(), "start");
     if (!startFunction.isFunction()) {
         if (!startFunction.isUndefined())
     if (!startFunction.isFunction()) {
         if (!startFunction.isUndefined())
-            throwVMError(exec, createTypeError(exec, ASCIILiteral("ReadableStream constructor object start property should be a function.")));
+            throwVMError(&exec, createTypeError(&exec, ASCIILiteral("ReadableStream constructor object start property should be a function.")));
         else
         else
-            startReadableStreamAsync(readableStream->impl());
+            startReadableStreamAsync(readableStream);
         return;
     }
 
         return;
     }
 
@@ -122,27 +127,28 @@ void ReadableStreamJSSource::start(JSC::ExecState* exec, JSReadableStream* reada
     arguments.append(m_controller.get());
 
     JSValue exception;
     arguments.append(m_controller.get());
 
     JSValue exception;
-    callFunction(exec, startFunction, m_source.get(), arguments, &exception);
+    callFunction(&exec, startFunction, m_source.get(), arguments, &exception);
 
     if (exception) {
 
     if (exception) {
-        throwVMError(exec, exception);
+        throwVMError(&exec, exception);
         return;
     }
 
     // FIXME: Implement handling promise as result of calling start function.
         return;
     }
 
     // FIXME: Implement handling promise as result of calling start function.
-    startReadableStreamAsync(readableStream->impl());
+    startReadableStreamAsync(readableStream);
 }
 
 }
 
-Ref<ReadableJSStream> ReadableJSStream::create(ScriptExecutionContext& scriptExecutionContext, Ref<ReadableStreamJSSource>&& source)
+Ref<ReadableJSStream> ReadableJSStream::create(ExecState& exec, ScriptExecutionContext& scriptExecutionContext)
 {
 {
-    auto readableStream = adoptRef(*new ReadableJSStream(scriptExecutionContext, WTF::move(source)));
+    Ref<ReadableStreamJSSource> source = ReadableStreamJSSource::create(&exec);
+    Ref<ReadableJSStream> readableStream = adoptRef(*new ReadableJSStream(scriptExecutionContext, WTF::move(source)));
+    readableStream->jsSource().start(exec, readableStream.get());
     return readableStream;
 }
 
 Ref<ReadableStreamReader> ReadableJSStream::createReader()
 {
     return readableStream;
 }
 
 Ref<ReadableStreamReader> ReadableJSStream::createReader()
 {
-    RefPtr<ReadableStreamReader> reader = ReadableJSStreamReader::create(*this);
-    return reader.releaseNonNull();
+    return Reader::create(*this);
 }
 
 ReadableJSStream::ReadableJSStream(ScriptExecutionContext& scriptExecutionContext, Ref<ReadableStreamJSSource>&& source)
 }
 
 ReadableJSStream::ReadableJSStream(ScriptExecutionContext& scriptExecutionContext, Ref<ReadableStreamJSSource>&& source)
@@ -150,13 +156,17 @@ ReadableJSStream::ReadableJSStream(ScriptExecutionContext& scriptExecutionContex
 {
 }
 
 {
 }
 
-Ref<ReadableJSStreamReader> ReadableJSStreamReader::create(ReadableJSStream& stream)
+ReadableStreamJSSource& ReadableJSStream::jsSource()
+{
+    return static_cast<ReadableStreamJSSource&>(source());
+}
+
+Ref<ReadableJSStream::Reader> ReadableJSStream::Reader::create(ReadableJSStream& stream)
 {
 {
-    auto readableStreamReader = adoptRef(*new ReadableJSStreamReader(stream));
-    return readableStreamReader;
+    return adoptRef(*new Reader(stream));
 }
 
 }
 
-ReadableJSStreamReader::ReadableJSStreamReader(ReadableJSStream& readableStream)
+ReadableJSStream::Reader::Reader(ReadableJSStream& readableStream)
     : ReadableStreamReader(readableStream)
 {
 }
     : ReadableStreamReader(readableStream)
 {
 }
index 223b27763e11be7dad4047d16c25cab73544fbc6..131d411b48fe20df3aec79713ed1b02f90c7ee88 100644 (file)
 
 namespace WebCore {
 
 
 namespace WebCore {
 
-class JSReadableStream;
-
 class ReadableStreamJSSource: public ReadableStreamSource {
 public:
     static Ref<ReadableStreamJSSource> create(JSC::ExecState*);
     ~ReadableStreamJSSource();
 
 class ReadableStreamJSSource: public ReadableStreamSource {
 public:
     static Ref<ReadableStreamJSSource> create(JSC::ExecState*);
     ~ReadableStreamJSSource();
 
-    void start(JSC::ExecState*, JSReadableStream*);
+    JSDOMGlobalObject* globalObject();
+    void start(JSC::ExecState&, ReadableJSStream&);
 
 private:
     ReadableStreamJSSource(JSC::ExecState*);
 
 private:
     ReadableStreamJSSource(JSC::ExecState*);
@@ -64,17 +63,19 @@ private:
 
 class ReadableJSStream: public ReadableStream {
 public:
 
 class ReadableJSStream: public ReadableStream {
 public:
-    static Ref<ReadableJSStream> create(ScriptExecutionContext&, Ref<ReadableStreamJSSource>&&);
+    static Ref<ReadableJSStream> create(JSC::ExecState&, ScriptExecutionContext&);
     virtual Ref<ReadableStreamReader> createReader() override;
     virtual Ref<ReadableStreamReader> createReader() override;
+    ReadableStreamJSSource& jsSource();
+
 private:
     ReadableJSStream(ScriptExecutionContext&, Ref<ReadableStreamJSSource>&&);
 private:
     ReadableJSStream(ScriptExecutionContext&, Ref<ReadableStreamJSSource>&&);
-};
 
 
-class ReadableJSStreamReader: public ReadableStreamReader {
-public:
-    static Ref<ReadableJSStreamReader> create(ReadableJSStream&);
-private:
-    ReadableJSStreamReader(ReadableJSStream&);
+    class Reader: public ReadableStreamReader {
+    public:
+        static Ref<Reader> create(ReadableJSStream&);
+    private:
+        explicit Reader(ReadableJSStream&);
+    };
 };
 
 void setInternalSlotToObject(JSC::ExecState*, JSC::JSValue, JSC::PrivateName&, JSC::JSValue);
 };
 
 void setInternalSlotToObject(JSC::ExecState*, JSC::JSValue, JSC::PrivateName&, JSC::JSValue);