Migrate streams API to JS Builtins
authoryouenn.fablet@crf.canon.fr <youenn.fablet@crf.canon.fr@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Oct 2015 06:20:58 +0000 (06:20 +0000)
committeryouenn.fablet@crf.canon.fr <youenn.fablet@crf.canon.fr@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 6 Oct 2015 06:20:58 +0000 (06:20 +0000)
https://bugs.webkit.org/show_bug.cgi?id=147092

Reviewed by Darin Adler.

Source/WebCore:

Moved ReadableStream implementation from C++ to JS Builtins.
Created specific private constructors for ReadableStreamReader and ReadableStreamController.
Added these constructors to  JSDOMWindowBase.
Constructors are based on a template found in JSDOMConstructor which might serve to webidl-generated classes as well.

Covered by existing tests.

* CMakeLists.txt:
* DerivedSources.make:
* Modules/streams/ReadableStream.cpp: Removed.
* Modules/streams/ReadableStream.h: Removed.
* Modules/streams/ReadableStream.idl:
* Modules/streams/ReadableStream.js:
(strategy.size):
(initializeReadableStream):
(cancel):
(getReader):
(pipeTo):
(tee):
(locked):
* Modules/streams/ReadableStreamController.h:
* Modules/streams/ReadableStreamController.idl:
* Modules/streams/ReadableStreamController.js: Added.
(enqueue):
(error):
(close):
(desiredSize):
* Modules/streams/ReadableStreamInternals.js:
(privateInitializeReadableStreamReader):
(privateInitializeReadableStreamController):
(isReadableStream):
(isReadableStreamReader):
(isReadableStreamController):
(errorReadableStream):
(requestReadableStreamPull):
(getReadableStreamDesiredSize):
(releaseReadableStreamReader):
(cancelReadableStream):
(finishClosingReadableStream):
(closeReadableStream):
(closeReadableStreamReader):
(enqueueInReadableStream):
(readFromReadableStreamReader):
(invokeOrNoop):
(promiseInvokeOrNoop):
* Modules/streams/ReadableStreamReader.cpp: Removed.
* Modules/streams/ReadableStreamReader.h:
* Modules/streams/ReadableStreamReader.idl:
* Modules/streams/ReadableStreamReader.js: Copied from Source/WebCore/Modules/streams/ReadableStream.js.
(cancel):
(read):
(releaseLock):
(closed):
* WebCore.vcxproj/WebCore.vcxproj:
* WebCore.vcxproj/WebCore.vcxproj.filters:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSBindingsAllInOne.cpp:
* bindings/js/JSDOMConstructor.h: Added.
(WebCore::JSBuiltinConstructor::create):
(WebCore::JSBuiltinConstructor::createStructure):
(WebCore::JSBuiltinConstructor::JSBuiltinConstructor):
(WebCore::JSBuiltinConstructor::initializeProperties):
(WebCore::JSBuiltinConstructor<JSClass>::finishCreation):
(WebCore::JSBuiltinConstructor<JSClass>::construct):
(WebCore::JSBuiltinConstructor<JSClass>::getConstructData):
* bindings/js/JSDOMWindowBase.cpp:
(WebCore::JSDOMWindowBase::finishCreation):
* bindings/js/JSReadableStreamControllerCustom.cpp: Removed.
* bindings/js/JSReadableStreamCustom.cpp: Removed.
* bindings/js/JSReadableStreamPrivateConstructors.cpp: Added.
(WebCore::constructJSReadableStreamController):
(WebCore::constructJSReadableStreamReader):
(WebCore::JSBuiltinConstructor<JSReadableStreamReader>::createJSObject):
(WebCore::JSBuiltinConstructor<JSReadableStreamController>::createJSObject):
(WebCore::JSBuiltinReadableStreamReaderPrivateConstructor::createInitializeFunction):
(WebCore::JSBuiltinReadableStreamControllerPrivateConstructor::createInitializeFunction):
(WebCore::createReadableStreamReaderPrivateConstructor):
(WebCore::createReadableStreamControllerPrivateConstructor):
* bindings/js/JSReadableStreamPrivateConstructors.h: Added.
* bindings/js/JSReadableStreamReaderCustom.cpp: Removed.
* bindings/js/ReadableJSStream.cpp: Removed.
* bindings/js/ReadableJSStream.h: Removed.
* bindings/js/WebCoreBuiltinNames.h: Added.
(WebCore::WebCoreBuiltinNames::WebCoreBuiltinNames):
* bindings/js/WebCoreJSBuiltins.cpp:
* bindings/js/WebCoreJSClientData.h:
(WebCore::WebCoreJSClientData::WebCoreJSClientData):
(WebCore::WebCoreJSClientData::builtinNames):
(WebCore::WebCoreJSClientData::readableStreamControllerBuiltins):
(WebCore::WebCoreJSClientData::readableStreamReaderBuiltins):

LayoutTests:

Rebasing some tests, one subtest passing, two others still failing but with different reasons.

* streams/reference-implementation/brand-checks-expected.txt:
* streams/reference-implementation/readable-stream-reader-expected.txt:

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

34 files changed:
LayoutTests/ChangeLog
LayoutTests/streams/reference-implementation/brand-checks-expected.txt
LayoutTests/streams/reference-implementation/readable-stream-reader-expected.txt
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/DerivedSources.make
Source/WebCore/Modules/streams/ReadableStream.cpp [deleted file]
Source/WebCore/Modules/streams/ReadableStream.h [deleted file]
Source/WebCore/Modules/streams/ReadableStream.idl
Source/WebCore/Modules/streams/ReadableStream.js
Source/WebCore/Modules/streams/ReadableStreamController.h
Source/WebCore/Modules/streams/ReadableStreamController.idl
Source/WebCore/Modules/streams/ReadableStreamController.js [new file with mode: 0644]
Source/WebCore/Modules/streams/ReadableStreamInternals.js
Source/WebCore/Modules/streams/ReadableStreamReader.cpp [deleted file]
Source/WebCore/Modules/streams/ReadableStreamReader.h
Source/WebCore/Modules/streams/ReadableStreamReader.idl
Source/WebCore/Modules/streams/ReadableStreamReader.js [new file with mode: 0644]
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/JSBindingsAllInOne.cpp
Source/WebCore/bindings/js/JSDOMConstructor.h [new file with mode: 0644]
Source/WebCore/bindings/js/JSDOMWindowBase.cpp
Source/WebCore/bindings/js/JSReadableStreamControllerCustom.cpp [deleted file]
Source/WebCore/bindings/js/JSReadableStreamCustom.cpp [deleted file]
Source/WebCore/bindings/js/JSReadableStreamPrivateConstructors.cpp [new file with mode: 0644]
Source/WebCore/bindings/js/JSReadableStreamPrivateConstructors.h [new file with mode: 0644]
Source/WebCore/bindings/js/JSReadableStreamReaderCustom.cpp [deleted file]
Source/WebCore/bindings/js/ReadableJSStream.cpp [deleted file]
Source/WebCore/bindings/js/ReadableJSStream.h [deleted file]
Source/WebCore/bindings/js/WebCoreBuiltinNames.h [new file with mode: 0644]
Source/WebCore/bindings/js/WebCoreJSBuiltins.cpp
Source/WebCore/bindings/js/WebCoreJSClientData.h

index 7fd842b..ea53318 100644 (file)
@@ -1,3 +1,15 @@
+2015-10-05  Youenn Fablet  <youenn.fablet@crf.canon.fr>
+
+        Migrate streams API to JS Builtins
+        https://bugs.webkit.org/show_bug.cgi?id=147092
+
+        Reviewed by Darin Adler.
+
+        Rebasing some tests, one subtest passing, two others still failing but with different reasons.
+
+        * streams/reference-implementation/brand-checks-expected.txt:
+        * streams/reference-implementation/readable-stream-reader-expected.txt:
+
 2015-10-05  Chris Dumez  <cdumez@apple.com>
 
         data: URLs should not be preloaded
index 50ad17f..c56b0f8 100644 (file)
@@ -4,10 +4,10 @@ PASS Can get the ReadableStreamController constructor indirectly
 FAIL ReadableStream.prototype.cancel enforces a brand check Can't find variable: WritableStream
 FAIL ReadableStream.prototype.getReader enforces a brand check Can't find variable: WritableStream
 PASS ReadableStream.prototype.pipeThrough works generically on its this and its arguments 
-FAIL ReadableStream.prototype.pipeTo works generically on its this and its arguments Can only call ReadableStream.pipeTo on instances of ReadableStream
+FAIL ReadableStream.prototype.pipeTo works generically on its this and its arguments pipeTo is not implemented
 FAIL ReadableStream.prototype.tee enforces a brand check Can't find variable: WritableStream
 PASS ReadableStreamReader enforces a brand check on its argument 
-FAIL ReadableStreamReader.prototype.closed enforces a brand check undefined is not an object (evaluating 'Object.getOwnPropertyDescriptor(obj, getterName).get')
+PASS ReadableStreamReader.prototype.closed enforces a brand check 
 PASS ReadableStreamReader.prototype.cancel enforces a brand check 
 PASS ReadableStreamReader.prototype.read enforces a brand check 
 PASS ReadableStreamReader.prototype.read enforces a brand check 
index 2640cd2..58ac94c 100644 (file)
@@ -1,7 +1,7 @@
 
 PASS Can get the ReadableStreamReader constructor indirectly 
 PASS ReadableStreamReader constructor should get a ReadableStream object as argument 
-FAIL ReadableStreamReader instances should have the correct list of properties assert_array_equals: lengths differ, expected 5 got 4
+FAIL ReadableStreamReader instances should have the correct list of properties assert_equals: method should be non-enumerable expected false but got true
 PASS ReadableStreamReader closed should always return the same promise object 
 PASS Constructing a ReadableStreamReader directly should fail if the stream is already locked (via direct construction) 
 PASS Getting a ReadableStreamReader via getReader should fail if the stream is already locked (via direct construction) 
index 6c50c70..b052fd9 100644 (file)
@@ -979,9 +979,6 @@ set(WebCore_SOURCES
     Modules/speech/SpeechSynthesisUtterance.cpp
     Modules/speech/SpeechSynthesisVoice.cpp
 
-    Modules/streams/ReadableStream.cpp
-    Modules/streams/ReadableStreamReader.cpp
-
     Modules/vibration/NavigatorVibration.cpp
     Modules/vibration/Vibration.cpp
 
@@ -1208,13 +1205,11 @@ set(WebCore_SOURCES
     bindings/js/JSPerformanceEntryCustom.cpp
     bindings/js/JSPluginElementFunctions.cpp
     bindings/js/JSPopStateEventCustom.cpp
+    bindings/js/JSReadableStreamPrivateConstructors.cpp
     bindings/js/JSRTCIceCandidateCustom.cpp
     bindings/js/JSRTCPeerConnectionCustom.cpp
     bindings/js/JSRTCSessionDescriptionCustom.cpp
     bindings/js/JSRTCStatsResponseCustom.cpp
-    bindings/js/JSReadableStreamControllerCustom.cpp
-    bindings/js/JSReadableStreamCustom.cpp
-    bindings/js/JSReadableStreamReaderCustom.cpp
     bindings/js/JSSQLResultSetRowListCustom.cpp
     bindings/js/JSSQLTransactionCustom.cpp
     bindings/js/JSSVGLengthCustom.cpp
@@ -1241,7 +1236,6 @@ set(WebCore_SOURCES
     bindings/js/JSXMLHttpRequestCustom.cpp
     bindings/js/JSXPathResultCustom.cpp
     bindings/js/JSXSLTProcessorCustom.cpp
-    bindings/js/ReadableJSStream.cpp
     bindings/js/ScheduledAction.cpp
     bindings/js/ScriptCachedFrameData.cpp
     bindings/js/ScriptController.cpp
@@ -3355,7 +3349,9 @@ set(WEBCORE_JS_BUILTINS
     ${WEBCORE_DIR}/Modules/streams/ByteLengthQueuingStrategy.js
     ${WEBCORE_DIR}/Modules/streams/CountQueuingStrategy.js
     ${WEBCORE_DIR}/Modules/streams/ReadableStream.js
+    ${WEBCORE_DIR}/Modules/streams/ReadableStreamController.js
     ${WEBCORE_DIR}/Modules/streams/ReadableStreamInternals.js
+    ${WEBCORE_DIR}/Modules/streams/ReadableStreamReader.js
 )
 
 WEBKIT_INCLUDE_CONFIG_FILES_IF_EXISTS()
index da1af28..b33c2ba 100644 (file)
@@ -1,3 +1,101 @@
+2015-10-05  Youenn Fablet  <youenn.fablet@crf.canon.fr>
+
+        Migrate streams API to JS Builtins
+        https://bugs.webkit.org/show_bug.cgi?id=147092
+
+        Reviewed by Darin Adler.
+
+        Moved ReadableStream implementation from C++ to JS Builtins.
+        Created specific private constructors for ReadableStreamReader and ReadableStreamController.
+        Added these constructors to  JSDOMWindowBase.
+        Constructors are based on a template found in JSDOMConstructor which might serve to webidl-generated classes as well.
+
+        Covered by existing tests.
+
+        * CMakeLists.txt:
+        * DerivedSources.make:
+        * Modules/streams/ReadableStream.cpp: Removed.
+        * Modules/streams/ReadableStream.h: Removed.
+        * Modules/streams/ReadableStream.idl:
+        * Modules/streams/ReadableStream.js:
+        (strategy.size):
+        (initializeReadableStream):
+        (cancel):
+        (getReader):
+        (pipeTo):
+        (tee):
+        (locked):
+        * Modules/streams/ReadableStreamController.h:
+        * Modules/streams/ReadableStreamController.idl:
+        * Modules/streams/ReadableStreamController.js: Added.
+        (enqueue):
+        (error):
+        (close):
+        (desiredSize):
+        * Modules/streams/ReadableStreamInternals.js:
+        (privateInitializeReadableStreamReader):
+        (privateInitializeReadableStreamController):
+        (isReadableStream):
+        (isReadableStreamReader):
+        (isReadableStreamController):
+        (errorReadableStream):
+        (requestReadableStreamPull):
+        (getReadableStreamDesiredSize):
+        (releaseReadableStreamReader):
+        (cancelReadableStream):
+        (finishClosingReadableStream):
+        (closeReadableStream):
+        (closeReadableStreamReader):
+        (enqueueInReadableStream):
+        (readFromReadableStreamReader):
+        (invokeOrNoop):
+        (promiseInvokeOrNoop):
+        * Modules/streams/ReadableStreamReader.cpp: Removed.
+        * Modules/streams/ReadableStreamReader.h:
+        * Modules/streams/ReadableStreamReader.idl:
+        * Modules/streams/ReadableStreamReader.js: Copied from Source/WebCore/Modules/streams/ReadableStream.js.
+        (cancel):
+        (read):
+        (releaseLock):
+        (closed):
+        * WebCore.vcxproj/WebCore.vcxproj:
+        * WebCore.vcxproj/WebCore.vcxproj.filters:
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/JSBindingsAllInOne.cpp:
+        * bindings/js/JSDOMConstructor.h: Added.
+        (WebCore::JSBuiltinConstructor::create):
+        (WebCore::JSBuiltinConstructor::createStructure):
+        (WebCore::JSBuiltinConstructor::JSBuiltinConstructor):
+        (WebCore::JSBuiltinConstructor::initializeProperties):
+        (WebCore::JSBuiltinConstructor<JSClass>::finishCreation):
+        (WebCore::JSBuiltinConstructor<JSClass>::construct):
+        (WebCore::JSBuiltinConstructor<JSClass>::getConstructData):
+        * bindings/js/JSDOMWindowBase.cpp:
+        (WebCore::JSDOMWindowBase::finishCreation):
+        * bindings/js/JSReadableStreamControllerCustom.cpp: Removed.
+        * bindings/js/JSReadableStreamCustom.cpp: Removed.
+        * bindings/js/JSReadableStreamPrivateConstructors.cpp: Added.
+        (WebCore::constructJSReadableStreamController):
+        (WebCore::constructJSReadableStreamReader):
+        (WebCore::JSBuiltinConstructor<JSReadableStreamReader>::createJSObject):
+        (WebCore::JSBuiltinConstructor<JSReadableStreamController>::createJSObject):
+        (WebCore::JSBuiltinReadableStreamReaderPrivateConstructor::createInitializeFunction):
+        (WebCore::JSBuiltinReadableStreamControllerPrivateConstructor::createInitializeFunction):
+        (WebCore::createReadableStreamReaderPrivateConstructor):
+        (WebCore::createReadableStreamControllerPrivateConstructor):
+        * bindings/js/JSReadableStreamPrivateConstructors.h: Added.
+        * bindings/js/JSReadableStreamReaderCustom.cpp: Removed.
+        * bindings/js/ReadableJSStream.cpp: Removed.
+        * bindings/js/ReadableJSStream.h: Removed.
+        * bindings/js/WebCoreBuiltinNames.h: Added.
+        (WebCore::WebCoreBuiltinNames::WebCoreBuiltinNames):
+        * bindings/js/WebCoreJSBuiltins.cpp:
+        * bindings/js/WebCoreJSClientData.h:
+        (WebCore::WebCoreJSClientData::WebCoreJSClientData):
+        (WebCore::WebCoreJSClientData::builtinNames):
+        (WebCore::WebCoreJSClientData::readableStreamControllerBuiltins):
+        (WebCore::WebCoreJSClientData::readableStreamReaderBuiltins):
+
 2015-10-05  Chris Dumez  <cdumez@apple.com>
 
         data: URLs should not be preloaded
index 1016415..46654f2 100644 (file)
@@ -1255,7 +1255,9 @@ WEBCORE_JS_BUILTINS = \
     $(WebCore)/Modules/streams/ByteLengthQueuingStrategy.js \
     $(WebCore)/Modules/streams/CountQueuingStrategy.js \
     $(WebCore)/Modules/streams/ReadableStream.js \
+    $(WebCore)/Modules/streams/ReadableStreamController.js \
     $(WebCore)/Modules/streams/ReadableStreamInternals.js \
+    $(WebCore)/Modules/streams/ReadableStreamReader.js \
 #
 
 all : $(WEBCORE_JS_BUILTINS:%.js=%Builtins.cpp)
diff --git a/Source/WebCore/Modules/streams/ReadableStream.cpp b/Source/WebCore/Modules/streams/ReadableStream.cpp
deleted file mode 100644 (file)
index 40edeba..0000000
+++ /dev/null
@@ -1,288 +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.
- */
-
-#include "config.h"
-#include "ReadableStream.h"
-
-#if ENABLE(STREAMS_API)
-
-#include "ExceptionCode.h"
-#include "ReadableJSStream.h"
-#include "ReadableStreamReader.h"
-#include "ScriptExecutionContext.h"
-#include <runtime/JSCJSValueInlines.h>
-#include <wtf/RefCountedLeakCounter.h>
-
-namespace WebCore {
-
-DEFINE_DEBUG_ONLY_GLOBAL(WTF::RefCountedLeakCounter, readableStreamCounter, ("ReadableStream"));
-
-RefPtr<ReadableStream> ReadableStream::create(JSC::ExecState& state, JSC::JSValue value, const Dictionary& strategy)
-{
-    return RefPtr<ReadableStream>(ReadableJSStream::create(state, value, strategy));
-}
-
-ReadableStream::ReadableStream(ScriptExecutionContext& scriptExecutionContext)
-    : ActiveDOMObject(&scriptExecutionContext)
-{
-#ifndef NDEBUG
-    readableStreamCounter.increment();
-#endif
-    suspendIfNeeded();
-}
-
-ReadableStream::~ReadableStream()
-{
-#ifndef NDEBUG
-    readableStreamCounter.decrement();
-#endif
-}
-
-void ReadableStream::clearCallbacks()
-{
-    m_closedPromise = Nullopt;
-    m_readRequests.clear();
-}
-
-void ReadableStream::changeStateToClosed()
-{
-    ASSERT(!m_closeRequested);
-    ASSERT(m_state != State::Errored);
-
-    m_closeRequested = true;
-
-    if (m_state != State::Readable || hasValue())
-        return;
-    close();
-}
-
-void ReadableStream::close()
-{
-    m_state = State::Closed;
-    releaseReader();
-}
-
-void ReadableStream::releaseReader()
-{
-    for (auto& request : m_readRequests)
-        request.resolveEnd();
-    if (m_reader)
-        m_releasedReaders.append(WTF::move(m_reader));
-
-    if (m_closedPromise)
-        m_closedPromise.value().resolve(nullptr);
-    clearCallbacks();
-}
-
-void ReadableStream::changeStateToErrored()
-{
-    if (m_state != State::Readable)
-        return;
-
-    clearValues();
-
-    m_state = State::Errored;
-
-    if (!m_reader)
-        return;
-
-    JSC::JSValue error = this->error();
-    for (auto& request : m_readRequests)
-        request.reject(error);
-    m_releasedReaders.append(WTF::move(m_reader));
-
-    if (m_closedPromise)
-        m_closedPromise.value().reject(error);
-    clearCallbacks();
-}
-
-void ReadableStream::start()
-{
-    m_isStarted = true;
-    pull();
-}
-
-void ReadableStream::pull()
-{
-    if (!m_isStarted || m_state == State::Closed || m_state == State::Errored || m_closeRequested)
-        return;
-
-    if (m_readRequests.isEmpty() && hasEnoughValues())
-        return;
-
-    if (m_isPulling) {
-        m_shouldPullAgain = true;
-        return;
-    }
-
-    m_isPulling = true;
-    if (doPull()) {
-        RefPtr<ReadableStream> protectedStream(this);
-        scriptExecutionContext()->postTask([protectedStream](ScriptExecutionContext&) {
-            protectedStream->finishPulling();
-        });
-    }
-}
-
-void ReadableStream::finishPulling()
-{
-    m_isPulling = false;
-    if (m_shouldPullAgain) {
-        m_shouldPullAgain = false;
-        pull();
-    }
-}
-
-ReadableStreamReader* ReadableStream::getReader(ExceptionCode& ec)
-{
-    if (locked()) {
-        ec = TypeError;
-        return nullptr;
-    }
-    ASSERT(!m_reader);
-
-    std::unique_ptr<ReadableStreamReader> newReader = std::make_unique<ReadableStreamReader>(*this);
-    ReadableStreamReader& reader = *newReader.get();
-
-    if (m_state == State::Readable) {
-        m_reader = WTF::move(newReader);
-        return &reader;
-    }
-
-    m_releasedReaders.append(WTF::move(newReader));
-    return &reader;
-}
-
-void ReadableStream::cancel(JSC::JSValue reason, CancelPromise&& promise, ExceptionCode& ec)
-{
-    if (locked()) {
-        ec = TypeError;
-        return;
-    }
-    cancelNoCheck(reason, WTF::move(promise));
-}
-
-void ReadableStream::cancelNoCheck(JSC::JSValue reason, CancelPromise&& promise)
-{
-    if (m_state == State::Closed) {
-        promise.resolve(nullptr);
-        return;
-    }
-    if (m_state == State::Errored) {
-        promise.reject(error());
-        return;
-    }
-    ASSERT(m_state == State::Readable);
-
-    clearValues();
-
-    m_cancelPromise = WTF::move(promise);
-
-    close();
-
-    if (doCancel(reason))
-        error() ? notifyCancelFailed() : notifyCancelSucceeded();
-}
-
-void ReadableStream::notifyCancelSucceeded()
-{
-    ASSERT(m_state == State::Closed);
-    ASSERT(m_cancelPromise);
-
-    m_cancelPromise.value().resolve(nullptr);
-    m_cancelPromise = Nullopt;
-}
-
-void ReadableStream::notifyCancelFailed()
-{
-    ASSERT(m_state == State::Closed);
-    ASSERT(m_cancelPromise);
-
-    m_cancelPromise.value().reject(error());
-    m_cancelPromise = Nullopt;
-}
-
-void ReadableStream::closed(ClosedPromise&& promise)
-{
-    if (m_state == State::Closed) {
-        promise.resolve(nullptr);
-        return;
-    }
-    if (m_state == State::Errored) {
-        promise.reject(error());
-        return;
-    }
-    m_closedPromise = WTF::move(promise);
-}
-
-void ReadableStream::read(ReadPromise&& readPromise)
-{
-    if (m_state == State::Closed) {
-        readPromise.resolveEnd();
-        return;
-    }
-    if (m_state == State::Errored) {
-        readPromise.reject(error());
-        return;
-    }
-    if (hasValue()) {
-        readPromise.resolve(read());
-        if (!m_closeRequested)
-            pull();
-        else if (!hasValue())
-            close();
-        return;
-    }
-    m_readRequests.append(WTF::move(readPromise));
-    pull();
-}
-
-bool ReadableStream::resolveReadCallback(JSC::JSValue value)
-{
-    if (m_readRequests.isEmpty())
-        return false;
-
-    m_readRequests.takeFirst().resolve(value);
-    return true;
-}
-
-const char* ReadableStream::activeDOMObjectName() const
-{
-    return "ReadableStream";
-}
-
-bool ReadableStream::canSuspendForPageCache() const
-{
-    // FIXME: We should try and do better here.
-    return false;
-}
-
-}
-
-#endif
diff --git a/Source/WebCore/Modules/streams/ReadableStream.h b/Source/WebCore/Modules/streams/ReadableStream.h
deleted file mode 100644 (file)
index 4e77ba5..0000000
+++ /dev/null
@@ -1,169 +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 ReadableStream_h
-#define ReadableStream_h
-
-#if ENABLE(STREAMS_API)
-
-#include "ActiveDOMObject.h"
-#include "DOMRequestState.h"
-#include "JSDOMPromise.h"
-#include "ScriptState.h"
-#include "ScriptWrappable.h"
-#include <functional>
-#include <wtf/Deque.h>
-#include <wtf/Optional.h>
-#include <wtf/Ref.h>
-#include <wtf/RefCounted.h>
-
-namespace JSC {
-class JSValue;
-}
-
-namespace WebCore {
-
-class Dictionary;
-class ReadableStreamReader;
-class ScriptExecutionContext;
-
-typedef int ExceptionCode;
-
-// ReadableStream implements the core of the streams API ReadableStream functionality.
-// It handles in particular the backpressure according the queue size.
-// ReadableStream is using a ReadableStreamSource to get data in its queue.
-// See https://streams.spec.whatwg.org/#rs
-class ReadableStream : public ActiveDOMObject, public ScriptWrappable, public RefCounted<ReadableStream> {
-public:
-    enum class State {
-        Readable,
-        Closed,
-        Errored
-    };
-
-    static RefPtr<ReadableStream> create(JSC::ExecState&, JSC::JSValue, const Dictionary&);
-    virtual ~ReadableStream();
-
-    ReadableStreamReader* getReader(ExceptionCode&);
-    const ReadableStreamReader* reader() const { return m_reader.get(); }
-
-    bool locked() const { return !!m_reader; }
-
-    void releaseReader();
-    bool hasReadPendingRequests() { return !m_readRequests.isEmpty(); }
-
-    bool isErrored() const { return m_state == State::Errored; }
-    bool isReadable() const { return m_state == State::Readable; }
-    bool isCloseRequested() const { return m_closeRequested; }
-
-    virtual JSC::JSValue error() = 0;
-
-    void start();
-    void changeStateToClosed();
-    void changeStateToErrored();
-    void finishPulling();
-    void notifyCancelSucceeded();
-    void notifyCancelFailed();
-
-    typedef DOMPromise<std::nullptr_t, JSC::JSValue> CancelPromise;
-    void cancel(JSC::JSValue, CancelPromise&&, ExceptionCode&);
-    void cancelNoCheck(JSC::JSValue, CancelPromise&&);
-
-    typedef DOMPromise<std::nullptr_t, JSC::JSValue> ClosedPromise;
-    void closed(ClosedPromise&&);
-
-    typedef DOMPromiseIteratorWithCallback<JSC::JSValue, JSC::JSValue> ReadPromise;
-    void read(ReadPromise&&);
-
-protected:
-    explicit ReadableStream(ScriptExecutionContext&);
-
-    bool resolveReadCallback(JSC::JSValue);
-    void pull();
-
-private:
-    // ActiveDOMObject API.
-    const char* activeDOMObjectName() const override;
-    bool canSuspendForPageCache() const override;
-
-    void clearCallbacks();
-    void close();
-
-    virtual void clearValues() = 0;
-    virtual bool hasEnoughValues() const = 0;
-    virtual bool hasValue() const = 0;
-    virtual JSC::JSValue read() = 0;
-    virtual bool doPull() = 0;
-    virtual bool doCancel(JSC::JSValue) = 0;
-
-    std::unique_ptr<ReadableStreamReader> m_reader;
-    Vector<std::unique_ptr<ReadableStreamReader>> m_releasedReaders;
-
-    Optional<CancelPromise> m_cancelPromise;
-    Optional<ClosedPromise> m_closedPromise;
-
-    Deque<ReadPromise> m_readRequests;
-
-    bool m_isStarted { false };
-    bool m_isPulling { false };
-    bool m_shouldPullAgain { false };
-    bool m_closeRequested { false };
-    State m_state { State::Readable };
-};
-
-// This class manages the queue and knows whether there is sufficient data in it.
-//   Subclasses should implement error storage, pulling and cancelling.
-template<typename ChunkType>
-class ReadableEnqueuingStream final : public ReadableStream {
-protected:
-    explicit ReadableEnqueuingStream(ScriptExecutionContext& context) : ReadableStream(context) { }
-
-    void enqueueChunk(ChunkType&& chunk) { m_queue.append(std::forward(chunk)); }
-
-private:
-    virtual void clearValues() override { m_queue.clear(); }
-    virtual bool hasEnoughValues() const override { return m_queue.size(); }
-    virtual bool hasValue() const override { return m_queue.size(); }
-    virtual JSC::JSValue read() override;
-
-    Deque<ChunkType> m_queue;
-};
-
-template<typename ChunkType>
-inline JSC::JSValue ReadableEnqueuingStream<ChunkType>::read()
-{
-    DOMRequestState state(scriptExecutionContext());
-    return toJS(state.exec(), toJSDOMGlobalObject(scriptExecutionContext(), state.exec()), m_queue.read());
-}
-
-}
-
-#endif
-
-#endif // ReadableStream_h
index c6ef8aa..049cc9f 100644 (file)
  */
 
 [
-    ConstructorCallWith=ScriptState,
-    Constructor([Default=Undefined] optional any source, [Default=Undefined] optional Dictionary strategy),
     Conditional=STREAMS_API,
-    SkipVTableValidation
+    JSBuiltinConstructor
 ] interface ReadableStream {
-    [RaisesException] Promise cancel([Default=Undefined] optional any reason);
-    [RaisesException] ReadableStreamReader getReader();
-    [Custom] Promise pipeTo(any streams, any options);
+    [JSBuiltin] Promise cancel([Default=Undefined] optional any reason);
+    [JSBuiltin] Object getReader();
+    [JSBuiltin] Promise pipeTo(any streams, any options);
     [JSBuiltin] Object pipeThrough(any dest, any options);
     [JSBuiltin] Object tee();
 
-    readonly attribute boolean locked;
+    [JSBuiltin] readonly attribute boolean locked;
 };
index 66b18d4..d36693a 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+function initializeReadableStream(underlyingSource, strategy)
+{
+    "use strict";
+
+     if (typeof underlyingSource === "undefined")
+         underlyingSource = { };
+     if (typeof strategy === "undefined")
+         strategy = { highWaterMark: 1, size: function() { return 1; } };
+
+    if (!@isObject(underlyingSource))
+        throw new @TypeError("ReadableStream constructor takes an object as first argument");
+
+    if (strategy !== undefined && !@isObject(strategy))
+        throw new @TypeError("ReadableStream constructor takes an object as second argument, if any");
+
+    this.@underlyingSource = underlyingSource;
+
+    this.@queue = [];
+    this.@queueSize = 0;
+    this.@state = @readableStreamReadable;
+    this.@started = false;
+    this.@closeRequested = false;
+    this.@pullAgain = false;
+    this.@pulling = false;
+    this.@reader = undefined;
+    this.@storedError = undefined;
+    this.@controller = new @ReadableStreamController(this);
+    this.@strategySize = strategy.size;
+    this.@highWaterMark = Number(strategy.highWaterMark);
+
+    if (Number.isNaN(this.@highWaterMark))
+        throw new TypeError("highWaterMark parameter is not correct");
+    if (this.@highWaterMark < 0)
+        throw new RangeError("highWaterMark is negative");
+
+    var result = @invokeOrNoop(underlyingSource, "start", [this.@controller]);
+    var _this = this;
+    Promise.resolve(result).then(function() {
+        _this.@started = true;
+        @requestReadableStreamPull(_this);
+    }, function(error) {
+        if (_this.@state === @readableStreamReadable)
+            @errorReadableStream(_this, error);
+    });
+
+    return this;
+}
+
+function cancel(reason)
+{
+    "use strict";
+
+    if (!@isReadableStream(this))
+        return Promise.reject(new @TypeError("Function should be called on a ReadableStream"));
+
+    if (@isReadableStreamLocked(this))
+        return Promise.reject(new @TypeError("ReadableStream is locked"));
+
+    return @cancelReadableStream(this, reason);
+}
+
+function getReader()
+{
+    "use strict";
+
+    if (!@isReadableStream(this))
+        throw new @TypeError("Function should be called on a ReadableStream");
+
+    if (@isReadableStreamLocked(this))
+        throw new @TypeError("ReadableStream is locked");
+
+    return new @ReadableStreamReader(this);
+}
+
 function pipeThrough(streams, options)
 {
     "use strict";
@@ -31,10 +105,29 @@ function pipeThrough(streams, options)
     return streams.readable;
 }
 
+function pipeTo(dest)
+{
+    "use strict";
+
+    throw new @TypeError("pipeTo is not implemented");
+}
+
 function tee()
 {
     "use strict";
 
-    // TODO: check this is a ReadableStream
-    return @teeReadableStream(this, false)
+    if (!@isReadableStream(this))
+        throw new @TypeError("Function should be called on a ReadableStream");
+
+    throw new @TypeError("tee is not implemented");
+}
+
+function locked()
+{
+    "use strict";
+
+    if (!@isReadableStream(this))
+        throw new @TypeError("Function should be called on a ReadableStream");
+
+    return @isReadableStreamLocked(this);
 }
index aa7ab3c..8fc478c 100644 (file)
 
 #if ENABLE(STREAMS_API)
 
-#include "ReadableJSStream.h"
+#include <wtf/RefCounted.h>
 
 namespace WebCore {
 
-typedef int ExceptionCode;
-
-// This class is only used for JS source readable streams to allow enqueuing, closing or erroring a readable stream.
-// Its definition is at https://streams.spec.whatwg.org/#rs-controller-class.
-// Note that its constructor is taking a ReadableJSStream as it should only be used for JS sources.
-class ReadableStreamController {
+// This is a dummy class needed as we cannot yet use JSBuiltinConstructor with NoInterfaceObject.
+// Implementation of ReadableStreamController functionality is done in ReadableStreamController.js
+// FIXME: Find a way to remove that class.
+class ReadableStreamController final : public RefCounted<ReadableStreamController> {
 public:
-    explicit ReadableStreamController(ReadableJSStream& stream)
-        : m_stream(stream) { }
-
-    ReadableJSStream& stream() { return m_stream; }
-
-    void error(JSC::ExecState& state, JSC::JSValue value, ExceptionCode& ec) { m_stream.error(state, value, ec); }
-
-    void enqueue(JSC::ExecState& state, JSC::JSValue value) { m_stream.enqueue(state, value); }
-
-    void ref() { m_stream.ref(); }
-    void deref() { m_stream.deref(); }
-
-    void close(ExceptionCode& ec) { m_stream.close(ec); }
-    double desiredSize() const { return m_stream.desiredSize(); }
-
+    static Ref<ReadableStreamController> create() { return adoptRef(* new ReadableStreamController); }
 private:
-    ReadableJSStream& m_stream;
+    ReadableStreamController() { }
 };
 
 }
index 30b8c8b..237b154 100644 (file)
@@ -33,9 +33,9 @@
     ImplementationLacksVTable,
     NoInterfaceObject
 ] interface ReadableStreamController {
-    [CallWith=ScriptState] void enqueue([Default=Undefined] optional any chunk);
-    [RaisesException] void close();
-    [CallWith=ScriptState, RaisesException] void error([Default=Undefined] optional any error);
+    [JSBuiltin] void enqueue([Default=Undefined] optional any chunk);
+    [JSBuiltin] void close();
+    [JSBuiltin] void error([Default=Undefined] optional any error);
 
-    readonly attribute double desiredSize;
+    [JSBuiltin] readonly attribute double desiredSize;
 };
diff --git a/Source/WebCore/Modules/streams/ReadableStreamController.js b/Source/WebCore/Modules/streams/ReadableStreamController.js
new file mode 100644 (file)
index 0000000..30c03d1
--- /dev/null
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2015 Canon Inc.
+ *
+ * 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.
+ */
+
+function enqueue(chunk)
+{
+    "use strict";
+
+    if (!@isReadableStreamController(this))
+        throw new @TypeError("Function should be called on a ReadableStreamController");
+
+    var stream = this.@controlledReadableStream;
+    if (stream.@state === @readableStreamErrored)
+        throw stream.@storedError;
+
+    if (stream.@closeRequested)
+        throw new @TypeError("ReadableStream is requested to close");
+
+    return @enqueueInReadableStream(stream, chunk)
+}
+
+function error(error)
+{
+    "use strict";
+
+    if (!@isReadableStreamController(this))
+        throw new @TypeError("Function should be called on a ReadableStreamController");
+
+    var stream = this.@controlledReadableStream;
+    if (stream.@state !== @readableStreamReadable)
+        throw new @TypeError("ReaableStream is not readable");
+
+    @errorReadableStream(stream, error);
+}
+
+function close()
+{
+    "use strict";
+
+    if (!@isReadableStreamController(this))
+        throw new @TypeError("Function should be called on a ReadableStreamController");
+
+    var stream = this.@controlledReadableStream;
+    if (stream.@closeRequested)
+        throw new @TypeError("ReadableStream is already requested to close");
+
+    if (stream.@state === @readableStreamErrored)
+        throw new @TypeError("ReadableStream is already errored");
+
+    @closeReadableStream(stream);
+}
+
+function desiredSize()
+{
+    "use strict";
+
+    if (!@isReadableStreamController(this))
+        throw new @TypeError("Function should be called on a ReadableStreamController");
+
+    return @getReadableStreamDesiredSize(this.@controlledReadableStream);
+}
index 4fc7e2e..ebd7f99 100644 (file)
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+function privateInitializeReadableStreamReader(stream)
+{
+    "use strict";
+
+    if (!@isReadableStream(stream))
+       throw new @TypeError("ReadableStreamReader needs a ReadableStream");
+    if (@isReadableStreamLocked(stream))
+       throw new @TypeError("ReadableStream is locked");
+
+    this.@state = stream.@state;
+    this.@readRequests = [];
+    if (stream.@state === @readableStreamReadable) {
+        this.@ownerReadableStream = stream;
+        this.@storedError = undefined;
+        stream.@reader = this;
+        this.@closedPromise = new Promise(function(resolve, reject) {
+            stream.@reader.@closedPromiseResolve = resolve;
+            stream.@reader.@closedPromiseReject = reject;
+        });
+        return this;
+    }
+    if (stream.@state === @readableStreamClosed) {
+        this.@ownerReadableStream = null;
+        this.@storedError = undefined;
+        this.@closedPromise = Promise.resolve();
+        return this;
+    }
+    // TODO: ASSERT(stream.@state === @readableStreamErrored);
+    this.@ownerReadableStream = null;
+    this.@storedError = stream.@storedError;
+    this.@closedPromise = Promise.reject(stream.@storedError);
+
+    return this;
+}
+
+function privateInitializeReadableStreamController(stream)
+{
+    "use strict";
+
+    if (!@isReadableStream(stream))
+        throw new @TypeError("ReadableStreamController needs a ReadableStream");
+    if (typeof stream.@controller !== "undefined")
+        throw new @TypeError("ReadableStream already has a controller");
+    this.@controlledReadableStream = stream;
+
+    return this;
+}
+
 function teeReadableStream(stream, shouldClone)
 {
     "use strict";
 
     throw new @TypeError("tee is not implemented");
 }
+
+function isReadableStream(stream)
+{
+    "use strict";
+
+    return @isObject(stream) && !!stream.@underlyingSource;
+}
+
+function isReadableStreamReader(reader)
+{
+    "use strict";
+
+    return @isObject(reader) && typeof reader.@ownerReadableStream !== "undefined";
+}
+
+function isReadableStreamController(controller)
+{
+    "use strict";
+
+    return @isObject(controller) && !!controller.@controlledReadableStream;
+}
+
+function errorReadableStream(stream, error)
+{
+    "use strict";
+
+    // TODO: ASSERT(stream.@state === @readableStreamReadable);
+    stream.@queue = [];
+    stream.@storedError = error;
+    stream.@state = @readableStreamErrored;
+
+    if (!stream.@reader)
+        return;
+    var reader = stream.@reader;
+
+    var requests = reader.@readRequests;
+    for (var index = 0, length = requests.length; index < length; ++index)
+        requests[index].reject(error);
+    reader.@readRequests = [];
+
+    @releaseReadableStreamReader(reader);
+    reader.@storedError = error;
+    reader.@state = @readableStreamErrored;
+
+    reader.@closedPromiseReject(error);
+}
+
+function requestReadableStreamPull(stream)
+{
+    "use strict";
+
+    if (stream.@state !== @readableStreamReadable)
+        return;
+    if (stream.@closeRequested)
+        return;
+    if (!stream.@started)
+        return;
+    if ((!@isReadableStreamLocked(stream) || !stream.@reader.@readRequests.length) && @getReadableStreamDesiredSize(stream) <= 0)
+        return;
+    if (stream.@pulling) {
+        stream.@pullAgain = true;
+        return;
+    }
+
+    stream.@pulling = true;
+
+    var promise = @promiseInvokeOrNoop(stream.@underlyingSource, "pull", [stream.@controller]);
+    promise.then(function() {
+        stream.@pulling = false;
+        if (stream.@pullAgain) {
+            stream.@pullAgain = false;
+            @requestReadableStreamPull(stream);
+        }
+    }, function(error) {
+        @errorReadableStream(stream, error);
+    });
+}
+
+function isReadableStreamLocked(stream)
+{
+   "use strict";
+
+    return !!stream.@reader;
+}
+
+function getReadableStreamDesiredSize(stream)
+{
+   "use strict";
+
+   return stream.@highWaterMark - stream.@queueSize;
+}
+
+function releaseReadableStreamReader(reader)
+{
+    "use strict";
+
+    reader.@ownerReadableStream.@reader = undefined;
+    reader.@ownerReadableStream = null;
+}
+
+function cancelReadableStream(stream, reason)
+{
+    "use strict";
+
+    if (stream.@state === @readableStreamClosed)
+        return Promise.resolve();
+    if (stream.@state === @readableStreamErrored)
+        return Promise.reject(stream.@storedError);
+    stream.@queue = [];
+    @finishClosingReadableStream(stream);
+    return @promiseInvokeOrNoop(stream.@underlyingSource, "cancel", [reason]).then(function() { });
+}
+
+function finishClosingReadableStream(stream)
+{
+    "use strict";
+
+    // TODO: ASSERT(stream.@state ===  @readableStreamReadable);
+    stream.@state = @readableStreamClosed;
+    var reader = stream.@reader;
+    if (reader)
+        @closeReadableStreamReader(reader);
+}
+
+function closeReadableStream(stream)
+{
+    "use strict";
+
+    // TODO. ASSERT(!stream.@closeRequested);
+    // TODO: ASSERT(stream.@state !== @readableStreamErrored);
+    if (stream.@state === @readableStreamClosed)
+        return; 
+    stream.@closeRequested = true;
+    if (!stream.@queue.length)
+        @finishClosingReadableStream(stream);
+}
+
+function closeReadableStreamReader(reader)
+{
+    "use strict";
+
+    var requests = reader.@readRequests;
+    for (var index = 0, length = requests.length; index < length; ++index)
+        requests[index].resolve({value:undefined, done: true});
+    reader.@readRequests = [];
+    @releaseReadableStreamReader(reader);
+    reader.@state = @readableStreamClosed;
+    reader.@closedPromiseResolve();
+}
+
+function enqueueInReadableStream(stream, chunk)
+{
+    "use strict";
+
+    // TODO: ASSERT(!stream.@closeRequested);
+    // TODO: ASSERT(stream.@state !== @readableStreamErrored);
+    if (stream.@state === @readableStreamClosed)
+        return undefined;
+    if (@isReadableStreamLocked(stream) && stream.@reader.@readRequests.length) {
+        stream.@reader.@readRequests.shift().resolve({value: chunk, done: false});
+        @requestReadableStreamPull(stream);
+        return;
+    }
+    try {
+        var size = 1;
+        if (stream.@strategySize) {
+            size = Number(stream.@strategySize(chunk));
+            if (Number.isNaN(size) || size === +Infinity || size < 0)
+                throw new RangeError("Chunk size is not valid");
+        }
+        stream.@queue.push({ value: chunk, size: size });
+        stream.@queueSize += size;
+    }
+    catch(error) {
+        @errorReadableStream(stream, error);
+        throw error;
+    }
+    @requestReadableStreamPull(stream);
+}
+
+function readFromReadableStreamReader(reader)
+{
+    "use strict";
+
+    if (reader.@state === @readableStreamClosed)
+        return Promise.resolve({value: undefined, done: true});
+    if (reader.@state === @readableStreamErrored)
+        return Promise.reject(reader.@storedError);
+    // TODO: ASSERT(!!reader.@ownerReadableStream);
+    // TODO: ASSERT(reader.@ownerReadableStream.@state === @readableStreamReadable);
+    var stream = reader.@ownerReadableStream;
+    if (stream.@queue.length) {
+        var chunk = stream.@queue.shift();
+        stream.@queueSize -= chunk.size;
+        if (!stream.@closeRequested)
+            @requestReadableStreamPull(stream);
+        else if (!stream.@queue.length)
+            @finishClosingReadableStream(stream);
+        return Promise.resolve({value: chunk.value, done: false});
+    }
+    var readRequest = {};
+    var readPromise = new Promise(function(resolve, reject) {
+        readRequest.resolve = resolve;
+        readRequest.reject = reject;
+    });
+    reader.@readRequests.push(readRequest);
+    @requestReadableStreamPull(stream);
+    return readPromise;
+}
+
+function invokeOrNoop(object, key, args)
+{
+    "use strict";
+
+    var method = object[key];
+    if (typeof method === "undefined")
+        return;
+    return method.@apply(object, args);
+}
+
+function promiseInvokeOrNoop(object, key, args)
+{
+    "use strict";
+
+    try {
+        var method = object[key];
+        if (typeof method === "undefined")
+            return Promise.resolve();
+        var result = method.@apply(object, args);
+        return Promise.resolve(result);
+    }
+    catch(error) {
+        return Promise.reject(error);
+    }
+}
diff --git a/Source/WebCore/Modules/streams/ReadableStreamReader.cpp b/Source/WebCore/Modules/streams/ReadableStreamReader.cpp
deleted file mode 100644 (file)
index 3f37d99..0000000
+++ /dev/null
@@ -1,80 +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.
- */
-
-#include "config.h"
-#include "ReadableStreamReader.h"
-
-#include "ExceptionCode.h"
-#include <runtime/JSCJSValueInlines.h>
-
-#if ENABLE(STREAMS_API)
-
-namespace WebCore {
-
-void ReadableStreamReader::cancel(JSC::JSValue reason, ReadableStream::CancelPromise&& promise)
-{
-    if (m_stream.isReadable() && m_stream.reader() != this) {
-        promise.resolve(nullptr);
-        return;
-    }
-    m_stream.cancelNoCheck(reason, WTF::move(promise));
-}
-
-void ReadableStreamReader::closed(ReadableStream::ClosedPromise&& promise)
-{
-    if (m_stream.isReadable() && m_stream.reader() != this) {
-        promise.resolve(nullptr);
-        return;
-    }
-    m_stream.closed(WTF::move(promise));
-}
-
-void ReadableStreamReader::read(ReadableStream::ReadPromise&& promise)
-{
-    if (m_stream.isReadable() && m_stream.reader() != this) {
-        promise.resolveEnd();
-        return;
-    }
-    m_stream.read(WTF::move(promise));
-}
-
-void ReadableStreamReader::releaseLock(ExceptionCode& ec)
-{
-    if (m_stream.reader() != this)
-        return;
-    if (m_stream.hasReadPendingRequests()) {
-        ec = TypeError;
-        return;
-    }
-    m_stream.releaseReader();
-}
-
-}
-
-#endif
index b4d2fb5..3922c92 100644 (file)
 
 #if ENABLE(STREAMS_API)
 
-#include "ActiveDOMObject.h"
-#include "ReadableStream.h"
-#include "ScriptWrappable.h"
-#include <functional>
-#include <wtf/Ref.h>
 #include <wtf/RefCounted.h>
 
 namespace WebCore {
 
-typedef int ExceptionCode;
-
-// ReadableStreamReader implements access to ReadableStream from JavaScript.
-// It basically allows access to the ReadableStream iff the ReadableStreamReader instance is the active reader
-// of the ReadableStream.
-// Most of this handling is happening in the custom JS binding of ReadableStreamReader.
-// See https://streams.spec.whatwg.org/#reader-class for more information.
-class ReadableStreamReader {
+// This is a dummy class needed as we cannot yet use JSBuiltinConstructor with NoInterfaceObject.
+// Implementation of ReadableStreamReader functionality is done in ReadableStreamReader.js
+// FIXME: Find a way to remove that class.
+class ReadableStreamReader final : public RefCounted<ReadableStreamReader> {
 public:
-    ReadableStreamReader(ReadableStream& stream)
-        : m_stream(stream) { }
-
-    void cancel(JSC::JSValue, ReadableStream::CancelPromise&&);
-    void closed(ReadableStream::ClosedPromise&&);
-    void read(ReadableStream::ReadPromise&&);
-    void releaseLock(ExceptionCode&);
-
-    void ref() { m_stream.ref(); }
-    void deref() { m_stream.deref(); }
-
+    static Ref<ReadableStreamReader> create() { return adoptRef(* new ReadableStreamReader); }
 private:
-    ReadableStream& m_stream;
+    ReadableStreamReader() { }
 };
 
 }
index 41afe25..3fe8bec 100644 (file)
 
 [
     Conditional=STREAMS_API,
-    CustomConstructor(any properties),
-    NoInterfaceObject,
-    SkipVTableValidation
+    CustomConstructor,
+    ImplementationLacksVTable,
+    NoInterfaceObject
 ] interface ReadableStreamReader {
-    Promise read();
-    Promise cancel([Default=Undefined] optional any reason);
-    [RaisesException] void releaseLock();
+    [JSBuiltin] Promise read();
+    [JSBuiltin] Promise cancel([Default=Undefined] optional any reason);
+    [JSBuiltin] void releaseLock();
 
-    [CustomGetter, CachedAttribute] readonly attribute Promise closed;
+    [JSBuiltin] readonly attribute Promise closed;
 };
diff --git a/Source/WebCore/Modules/streams/ReadableStreamReader.js b/Source/WebCore/Modules/streams/ReadableStreamReader.js
new file mode 100644 (file)
index 0000000..26940c3
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2015 Canon Inc.
+ *
+ * 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.
+ */
+
+function cancel(reason)
+{
+    "use strict";
+
+    if (!@isReadableStreamReader(this))
+        return Promise.reject(new @TypeError("Function should be called on a ReadableStreamReader"));
+
+    if (this.@state === @readableStreamClosed)
+        return Promise.resolve();
+
+    if (this.@state === @readableStreamErrored)
+        return Promise.reject(this.@storedError);
+
+    // TODO ASSERT(@isReadableStream(this.@ownerReadableStream));
+    // TODO ASSERT(this.@ownerReadableStream.@state === @readableStreamReadable);
+    return @cancelReadableStream(this.@ownerReadableStream, reason);
+}
+
+function read()
+{
+    "use strict";
+
+    if (!@isReadableStreamReader(this))
+        return Promise.reject(new @TypeError("Function should be called on a ReadableStreamReader"));
+
+    return @readFromReadableStreamReader(this);
+}
+
+function releaseLock()
+{
+    "use strict";
+
+    if (!@isReadableStreamReader(this))
+        throw new @TypeError("Function should be called on a ReadableStreamReader");
+
+    if (!this.@ownerReadableStream)
+         return;
+
+    if (this.@readRequests.length)
+        throw new @TypeError();
+
+    @closeReadableStreamReader(this);
+}
+
+function closed()
+{
+    "use strict";
+
+    if (!@isReadableStreamReader(this))
+        return Promise.reject(new @TypeError("Callee of closed is not a ReadableStreamReader"));
+
+    return this.@closedPromise;
+}
index eb59030..9492e06 100644 (file)
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|Win32'">true</ExcludedFromBuild>
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|x64'">true</ExcludedFromBuild>
     </ClCompile>
-    <ClCompile Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\ReadableStreamInternalsBuiltins.cpp">
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug_WinCairo|Win32'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug_WinCairo|x64'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='DebugSuffix|Win32'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='DebugSuffix|x64'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release_WinCairo|Win32'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release_WinCairo|x64'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|Win32'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|x64'">true</ExcludedFromBuild>
-    </ClCompile>
     <ClCompile Include="$(ConfigurationBuildDir)\obj$(PlatformArchitecture)\$(ProjectName)\DerivedSources\JSReadableStreamController.cpp">
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
     <ClCompile Include="..\Modules\notifications\Notification.cpp" />
     <ClCompile Include="..\Modules\notifications\NotificationCenter.cpp" />
     <ClCompile Include="..\Modules\notifications\WorkerGlobalScopeNotifications.cpp" />
-    <ClCompile Include="..\Modules\streams\ReadableStream.cpp" />
-    <ClCompile Include="..\Modules\streams\ReadableStreamReader.cpp" />
     <ClCompile Include="..\Modules\webdatabase\ChangeVersionWrapper.cpp" />
     <ClCompile Include="..\Modules\webdatabase\Database.cpp" />
     <ClCompile Include="..\Modules\webdatabase\DatabaseAuthorizer.cpp" />
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|Win32'">true</ExcludedFromBuild>
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|x64'">true</ExcludedFromBuild>
     </ClCompile>
-    <ClCompile Include="..\bindings\js\JSReadableStreamCustom.cpp">
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug_WinCairo|Win32'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug_WinCairo|x64'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='DebugSuffix|Win32'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='DebugSuffix|x64'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release_WinCairo|Win32'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release_WinCairo|x64'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|Win32'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|x64'">true</ExcludedFromBuild>
-    </ClCompile>
-    <ClCompile Include="..\bindings\js\JSReadableStreamControllerCustom.cpp">
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug_WinCairo|Win32'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug_WinCairo|x64'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='DebugSuffix|Win32'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='DebugSuffix|x64'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release_WinCairo|Win32'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release_WinCairo|x64'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|Win32'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|x64'">true</ExcludedFromBuild>
-    </ClCompile>
-    <ClCompile Include="..\bindings\js\JSReadableStreamReaderCustom.cpp">
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug_WinCairo|Win32'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug_WinCairo|x64'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='DebugSuffix|Win32'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='DebugSuffix|x64'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release_WinCairo|Win32'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release_WinCairo|x64'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|Win32'">true</ExcludedFromBuild>
-      <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Production|x64'">true</ExcludedFromBuild>
-    </ClCompile>
-    <ClCompile Include="..\bindings\js\ReadableJSStream.cpp">
+    <ClCompile Include="..\bindings\js\JSReadableStreamPrivateConstructors.cpp">
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
       <ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug_WinCairo|Win32'">true</ExcludedFromBuild>
     <ClInclude Include="..\Modules\notifications\NotificationClient.h" />
     <ClInclude Include="..\Modules\notifications\WorkerGlobalScopeNotifications.h" />
     <ClInclude Include="..\Modules\plugins\PluginReplacement.h" />
-    <ClInclude Include="..\Modules\streams\ReadableStream.h" />
-    <ClInclude Include="..\Modules\streams\ReadableStreamController.h" />
-    <ClInclude Include="..\Modules\streams\ReadableStreamReader.h" />
     <ClInclude Include="..\Modules\webdatabase\AbstractDatabaseServer.h" />
     <ClInclude Include="..\Modules\webdatabase\ChangeVersionData.h" />
     <ClInclude Include="..\Modules\webdatabase\ChangeVersionWrapper.h" />
     <ClInclude Include="..\bindings\js\JSCustomXPathNSResolver.h" />
     <ClInclude Include="..\bindings\js\JSDictionary.h" />
     <ClInclude Include="..\bindings\js\JSDOMBinding.h" />
+    <ClInclude Include="..\bindings\js\JSDOMConstructor.h" />
     <ClInclude Include="..\bindings\js\JSDOMGlobalObject.h" />
     <ClInclude Include="..\bindings\js\JSDOMGlobalObjectTask.h" />
     <ClInclude Include="..\bindings\js\JSDOMPromise.h" />
index 3207e98..0e8e512 100644 (file)
@@ -1,5 +1,4 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+<?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup>
     <Filter Include="DerivedSources">
       <UniqueIdentifier>{955487e8-94ad-45c1-9cc8-cb88911e9d7c}</UniqueIdentifier>
     <ClCompile Include="..\Modules\notifications\WorkerGlobalScopeNotifications.cpp">
       <Filter>Modules\notifications</Filter>
     </ClCompile>
-    <ClCompile Include="..\Modules\streams\ReadableStream.cpp">
-      <Filter>Modules\streams</Filter>
-    </ClCompile>
-    <ClCompile Include="..\Modules\streams\ReadableStreamReader.cpp">
-      <Filter>Modules\streams</Filter>
-    </ClCompile>
     <ClCompile Include="..\Modules\webdatabase\ChangeVersionWrapper.cpp">
       <Filter>Modules\webdatabase</Filter>
     </ClCompile>
     <ClCompile Include="..\bindings\js\JSPluginElementFunctions.cpp">
       <Filter>bindings\js</Filter>
     </ClCompile>
-    <ClCompile Include="..\bindings\js\JSReadableStreamCustom.cpp">
-      <Filter>bindings\js</Filter>
-    </ClCompile>
-    <ClCompile Include="..\bindings\js\JSReadableStreamControllerCustom.cpp">
-      <Filter>bindings\js</Filter>
-    </ClCompile>
-    <ClCompile Include="..\bindings\js\JSReadableStreamReaderCustom.cpp">
-      <Filter>bindings\js</Filter>
-    </ClCompile>
-    <ClCompile Include="..\bindings\js\ReadableJSStream.cpp">
+    <ClCompile Include="..\bindings\js\JSReadableStreamPrivateConstructors.cpp">
       <Filter>bindings\js</Filter>
     </ClCompile>
     <ClCompile Include="..\bindings\js\JSSQLResultSetRowListCustom.cpp">
index 8f2e488..6004e24 100644 (file)
                14D824080AF93AEB0004F057 /* ChromeClient.h in Headers */ = {isa = PBXBuildFile; fileRef = 14D824060AF93AEB0004F057 /* ChromeClient.h */; settings = {ATTRIBUTES = (Private, ); }; };
                14DC0D3709FED073007B0235 /* JSNode.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14DC0D3509FED073007B0235 /* JSNode.cpp */; };
                14DC0D3809FED073007B0235 /* JSNode.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 14DC0D3609FED073007B0235 /* JSNode.h */; settings = {ATTRIBUTES = (); }; };
-               14DCF3B21B6BE2080062D4C3 /* JSByteLengthQueuingStrategy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14DCF3B01B6BE2080062D4C3 /* JSByteLengthQueuingStrategy.cpp */; };
-               14DCF3B31B6BE2080062D4C3 /* JSByteLengthQueuingStrategy.h in Headers */ = {isa = PBXBuildFile; fileRef = 14DCF3B11B6BE2080062D4C3 /* JSByteLengthQueuingStrategy.h */; };
                14DCF3B21B6BE2080062D4C2 /* JSCountQueuingStrategy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14DCF3B01B6BE2080062D4C2 /* JSCountQueuingStrategy.cpp */; };
+               14DCF3B21B6BE2080062D4C3 /* JSByteLengthQueuingStrategy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14DCF3B01B6BE2080062D4C3 /* JSByteLengthQueuingStrategy.cpp */; };
                14DCF3B31B6BE2080062D4C2 /* JSCountQueuingStrategy.h in Headers */ = {isa = PBXBuildFile; fileRef = 14DCF3B11B6BE2080062D4C2 /* JSCountQueuingStrategy.h */; };
+               14DCF3B31B6BE2080062D4C3 /* JSByteLengthQueuingStrategy.h in Headers */ = {isa = PBXBuildFile; fileRef = 14DCF3B11B6BE2080062D4C3 /* JSByteLengthQueuingStrategy.h */; };
                14E8378409F85D1C00B85AE4 /* JSEvent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 14E8378309F85D1C00B85AE4 /* JSEvent.cpp */; };
                14E8378E09F85D4F00B85AE4 /* JSEvent.h in Headers */ = {isa = PBXBuildFile; fileRef = 14E8378D09F85D4F00B85AE4 /* JSEvent.h */; };
                14FFE31D0AE1963300136BF5 /* HTMLFrameElementBase.h in Headers */ = {isa = PBXBuildFile; fileRef = 14FFE31B0AE1963300136BF5 /* HTMLFrameElementBase.h */; settings = {ATTRIBUTES = (Private, ); }; };
                40ECAE7E16B8B67200C36103 /* JSDOMError.h in Headers */ = {isa = PBXBuildFile; fileRef = 40ECAE7D16B8B67200C36103 /* JSDOMError.h */; };
                40ECAE8116B8B68A00C36103 /* JSDOMError.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 40ECAE8016B8B68A00C36103 /* JSDOMError.cpp */; };
                410B7E721045FAB000D8224F /* JSMessageEventCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 410B7E711045FAB000D8224F /* JSMessageEventCustom.cpp */; };
-               41189EF91AD8273700B90A0D /* JSReadableStreamControllerCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 41189EF81AD8233C00B90A0D /* JSReadableStreamControllerCustom.cpp */; };
                411A90421BBAB47A000CF156 /* WebCoreJSBuiltins.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 411A90411BBAB46D000CF156 /* WebCoreJSBuiltins.cpp */; };
                4123081B138C429700BCCFCA /* WebCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 93F19B1A08245E5A001E9ABC /* WebCore.framework */; };
                41230913138C42FF00BCCFCA /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F8216299029F4FB501000131 /* JavaScriptCore.framework */; };
                4127D5370F8AAB1D00E424F5 /* ScriptState.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4127D5360F8AAB1D00E424F5 /* ScriptState.cpp */; };
+               4129DF851BB5B80700322A16 /* JSReadableStreamPrivateConstructors.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4129DF831BB5B7F700322A16 /* JSReadableStreamPrivateConstructors.cpp */; };
+               4129DF861BB5B80C00322A16 /* JSReadableStreamPrivateConstructors.h in Headers */ = {isa = PBXBuildFile; fileRef = 4129DF841BB5B7F700322A16 /* JSReadableStreamPrivateConstructors.h */; settings = {ATTRIBUTES = (Private, ); }; };
                4138D3351244054800323D33 /* EventContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 4138D3331244054800323D33 /* EventContext.h */; };
                4138D3361244054800323D33 /* EventContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4138D3341244054800323D33 /* EventContext.cpp */; };
+               413C2C341BC29A8F0075204C /* JSDOMConstructor.h in Headers */ = {isa = PBXBuildFile; fileRef = 413C2C331BC29A7B0075204C /* JSDOMConstructor.h */; settings = {ASSET_TAGS = (); }; };
                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 */; };
                418A06D1133C04D500CD379C /* EventDispatcher.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 418A06CF133C04D500CD379C /* EventDispatcher.cpp */; };
                418F88040FF957AE0080F045 /* JSAbstractWorker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 418F88020FF957AE0080F045 /* JSAbstractWorker.cpp */; };
                418F88050FF957AF0080F045 /* JSAbstractWorker.h in Headers */ = {isa = PBXBuildFile; fileRef = 418F88030FF957AE0080F045 /* JSAbstractWorker.h */; };
-               4198BDF01A81142200B22FB5 /* ReadableJSStream.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4198BDEE1A81123600B22FB5 /* ReadableJSStream.cpp */; };
-               4198BDF11A81143100B22FB5 /* ReadableJSStream.h in Headers */ = {isa = PBXBuildFile; fileRef = 4198BDEF1A81123600B22FB5 /* ReadableJSStream.h */; };
                419BC2DE1685329900D64D6D /* VisitedLinkState.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 419BC2DC1685329900D64D6D /* VisitedLinkState.cpp */; };
                419BC2DF1685329900D64D6D /* VisitedLinkState.h in Headers */ = {isa = PBXBuildFile; fileRef = 419BC2DD1685329900D64D6D /* VisitedLinkState.h */; };
-               419FAFAE1ABABD08005B828B /* ReadableStreamReader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 419FAFAB1ABABCD5005B828B /* ReadableStreamReader.cpp */; };
-               419FAFAF1ABABD0C005B828B /* ReadableStreamReader.h in Headers */ = {isa = PBXBuildFile; fileRef = 419FAFAC1ABABCD5005B828B /* ReadableStreamReader.h */; };
-               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 */; };
-               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 */; };
                41BF700C0FE86F49005E8DEC /* MessagePortChannel.h in Headers */ = {isa = PBXBuildFile; fileRef = 41BF700A0FE86F49005E8DEC /* MessagePortChannel.h */; settings = {ATTRIBUTES = (Private, ); }; };
                14813BF309EDF88E00F757E1 /* IDLParser.pm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.script.perl; name = IDLParser.pm; path = scripts/IDLParser.pm; sourceTree = "<group>"; };
                148AFDA30AF58360008CC700 /* ExceptionHandlers.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ExceptionHandlers.h; sourceTree = "<group>"; };
                148AFDA40AF58360008CC700 /* ExceptionHandlers.mm */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.objcpp; path = ExceptionHandlers.mm; sourceTree = "<group>"; };
-               148B4FFF1B6904C500C954E5 /* ByteLengthQueuingStrategy.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ByteLengthQueuingStrategy.idl; sourceTree = "<group>"; };
                148B4FFF1B6904C500C954E4 /* CountQueuingStrategy.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = CountQueuingStrategy.idl; sourceTree = "<group>"; };
+               148B4FFF1B6904C500C954E5 /* ByteLengthQueuingStrategy.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ByteLengthQueuingStrategy.idl; sourceTree = "<group>"; };
                14947FFB12F80CD200A0F631 /* DocumentOrderedMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DocumentOrderedMap.cpp; sourceTree = "<group>"; };
                14947FFC12F80CD200A0F631 /* DocumentOrderedMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DocumentOrderedMap.h; sourceTree = "<group>"; };
                14993BE30B2F2B1C0050497F /* FocusController.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = FocusController.cpp; sourceTree = "<group>"; };
                14DC0D0B09FECFA4007B0235 /* Node.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Node.idl; sourceTree = "<group>"; };
                14DC0D3509FED073007B0235 /* JSNode.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSNode.cpp; sourceTree = "<group>"; };
                14DC0D3609FED073007B0235 /* JSNode.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSNode.h; sourceTree = "<group>"; };
-               14DCF3B01B6BE2080062D4C3 /* JSByteLengthQueuingStrategy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSByteLengthQueuingStrategy.cpp; sourceTree = "<group>"; };
-               14DCF3B11B6BE2080062D4C3 /* JSByteLengthQueuingStrategy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSByteLengthQueuingStrategy.h; sourceTree = "<group>"; };
                14DCF3B01B6BE2080062D4C2 /* JSCountQueuingStrategy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSCountQueuingStrategy.cpp; sourceTree = "<group>"; };
+               14DCF3B01B6BE2080062D4C3 /* JSByteLengthQueuingStrategy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSByteLengthQueuingStrategy.cpp; sourceTree = "<group>"; };
                14DCF3B11B6BE2080062D4C2 /* JSCountQueuingStrategy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSCountQueuingStrategy.h; sourceTree = "<group>"; };
+               14DCF3B11B6BE2080062D4C3 /* JSByteLengthQueuingStrategy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSByteLengthQueuingStrategy.h; sourceTree = "<group>"; };
                14E836D209F8512000B85AE4 /* Event.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = Event.idl; sourceTree = "<group>"; };
                14E8378309F85D1C00B85AE4 /* JSEvent.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JSEvent.cpp; sourceTree = "<group>"; };
                14E8378D09F85D4F00B85AE4 /* JSEvent.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JSEvent.h; sourceTree = "<group>"; };
                40ECAE7D16B8B67200C36103 /* JSDOMError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDOMError.h; sourceTree = "<group>"; };
                40ECAE8016B8B68A00C36103 /* JSDOMError.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSDOMError.cpp; sourceTree = "<group>"; };
                410B7E711045FAB000D8224F /* JSMessageEventCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSMessageEventCustom.cpp; sourceTree = "<group>"; };
-               41189EF61AD8232800B90A0D /* ReadableStreamController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReadableStreamController.h; sourceTree = "<group>"; };
                41189EF71AD8232800B90A0D /* ReadableStreamController.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ReadableStreamController.idl; sourceTree = "<group>"; };
-               41189EF81AD8233C00B90A0D /* JSReadableStreamControllerCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSReadableStreamControllerCustom.cpp; sourceTree = "<group>"; };
                411A90411BBAB46D000CF156 /* WebCoreJSBuiltins.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = WebCoreJSBuiltins.cpp; sourceTree = "<group>"; };
                4127D5360F8AAB1D00E424F5 /* ScriptState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ScriptState.cpp; sourceTree = "<group>"; };
+               4129DF811BB5B79B00322A16 /* ReadableStreamController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReadableStreamController.h; sourceTree = "<group>"; };
+               4129DF821BB5B7A600322A16 /* ReadableStreamReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReadableStreamReader.h; sourceTree = "<group>"; };
+               4129DF831BB5B7F700322A16 /* JSReadableStreamPrivateConstructors.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSReadableStreamPrivateConstructors.cpp; sourceTree = "<group>"; };
+               4129DF841BB5B7F700322A16 /* JSReadableStreamPrivateConstructors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSReadableStreamPrivateConstructors.h; sourceTree = "<group>"; };
                4138D3331244054800323D33 /* EventContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EventContext.h; sourceTree = "<group>"; };
                4138D3341244054800323D33 /* EventContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EventContext.cpp; sourceTree = "<group>"; };
+               413C2C331BC29A7B0075204C /* JSDOMConstructor.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSDOMConstructor.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>"; };
                418A06CF133C04D500CD379C /* EventDispatcher.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = EventDispatcher.cpp; sourceTree = "<group>"; };
                418F88020FF957AE0080F045 /* JSAbstractWorker.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSAbstractWorker.cpp; sourceTree = "<group>"; };
                418F88030FF957AE0080F045 /* JSAbstractWorker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSAbstractWorker.h; sourceTree = "<group>"; };
-               4198BDEE1A81123600B22FB5 /* ReadableJSStream.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ReadableJSStream.cpp; sourceTree = "<group>"; };
-               4198BDEF1A81123600B22FB5 /* ReadableJSStream.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReadableJSStream.h; sourceTree = "<group>"; };
                419BC2DC1685329900D64D6D /* VisitedLinkState.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = VisitedLinkState.cpp; sourceTree = "<group>"; };
                419BC2DD1685329900D64D6D /* VisitedLinkState.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VisitedLinkState.h; sourceTree = "<group>"; };
-               419FAFAB1ABABCD5005B828B /* ReadableStreamReader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ReadableStreamReader.cpp; sourceTree = "<group>"; };
-               419FAFAC1ABABCD5005B828B /* ReadableStreamReader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ReadableStreamReader.h; sourceTree = "<group>"; };
                419FAFAD1ABABCD5005B828B /* ReadableStreamReader.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ReadableStreamReader.idl; sourceTree = "<group>"; };
-               419FAFB01ABABD7B005B828B /* JSReadableStreamReaderCustom.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSReadableStreamReaderCustom.cpp; sourceTree = "<group>"; };
-               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>"; };
-               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>"; };
                41BF700A0FE86F49005E8DEC /* MessagePortChannel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessagePortChannel.h; sourceTree = "<group>"; };
                        isa = PBXGroup;
                        children = (
                                148B4FFF1B6904C500C954E5 /* ByteLengthQueuingStrategy.idl */,
+                               4129DF821BB5B7A600322A16 /* ReadableStreamReader.h */,
+                               4129DF811BB5B79B00322A16 /* ReadableStreamController.h */,
                                148B4FFF1B6904C500C954E4 /* CountQueuingStrategy.idl */,
-                               41A023EB1A39DB7900F722CF /* ReadableStream.cpp */,
-                               41A023EC1A39DB7900F722CF /* ReadableStream.h */,
                                41A023ED1A39DB7900F722CF /* ReadableStream.idl */,
-                               41189EF61AD8232800B90A0D /* ReadableStreamController.h */,
                                41189EF71AD8232800B90A0D /* ReadableStreamController.idl */,
-                               419FAFAB1ABABCD5005B828B /* ReadableStreamReader.cpp */,
-                               419FAFAC1ABABCD5005B828B /* ReadableStreamReader.h */,
                                419FAFAD1ABABCD5005B828B /* ReadableStreamReader.idl */,
                        );
                        path = streams;
                                ADDA94BF19686F8000453029 /* JSDocumentCustom.h */,
                                93B70D4709EB0C7C009D8468 /* JSDOMBinding.cpp */,
                                93B70D4809EB0C7C009D8468 /* JSDOMBinding.h */,
+                               413C2C331BC29A7B0075204C /* JSDOMConstructor.h */,
                                E1C36CBC0EB08062007410BC /* JSDOMGlobalObject.cpp */,
                                E1C36C020EB076D6007410BC /* JSDOMGlobalObject.h */,
                                7C2BDD3B17C7F98B0038FF15 /* JSDOMGlobalObjectTask.cpp */,
                                7C91A38E1B498ABE003F9EFA /* JSNodeOrString.h */,
                                93B70D4F09EB0C7C009D8468 /* JSPluginElementFunctions.cpp */,
                                93B70D5009EB0C7C009D8468 /* JSPluginElementFunctions.h */,
-                               41189EF81AD8233C00B90A0D /* JSReadableStreamControllerCustom.cpp */,
+                               4129DF831BB5B7F700322A16 /* JSReadableStreamPrivateConstructors.cpp */,
+                               4129DF841BB5B7F700322A16 /* JSReadableStreamPrivateConstructors.h */,
                                E1C36D320EB0A094007410BC /* JSWorkerGlobalScopeBase.cpp */,
                                E1C36D330EB0A094007410BC /* JSWorkerGlobalScopeBase.h */,
                                E38838941BAD145F00D62EE3 /* JSModuleLoader.cpp */,
                                E38838951BAD145F00D62EE3 /* JSModuleLoader.h */,
-                               4198BDEE1A81123600B22FB5 /* ReadableJSStream.cpp */,
-                               4198BDEF1A81123600B22FB5 /* ReadableJSStream.h */,
                                BCA378BA0D15F64200B793D6 /* ScheduledAction.cpp */,
                                BCA378BB0D15F64200B793D6 /* ScheduledAction.h */,
                                41F1D21E0EF35C2A00DA8753 /* ScriptCachedFrameData.cpp */,
                                FDBD1DFB167FE27D0051A11E /* JSOscillatorNodeCustom.cpp */,
                                FD8AA63D169514A700D2EA68 /* JSPannerNodeCustom.cpp */,
                                A85F22081430377D007CC884 /* JSPopStateEventCustom.cpp */,
-                               41A023F31A39DBCB00F722CF /* JSReadableStreamCustom.cpp */,
-                               419FAFB01ABABD7B005B828B /* JSReadableStreamReaderCustom.cpp */,
                                4AE0BF881836083100F3852D /* JSRTCIceCandidateCustom.cpp */,
                                07CA120D182D67D800D12197 /* JSRTCPeerConnectionCustom.cpp */,
                                07D07B131834158800ABDD3C /* JSRTCSessionDescriptionCustom.cpp */,
                                B2FA3D4F0AB75A6F000E5AC4 /* JSSVGAnimatedString.h in Headers */,
                                B2FA3D510AB75A6F000E5AC4 /* JSSVGAnimatedTransformList.h in Headers */,
                                B2FA3D530AB75A6F000E5AC4 /* JSSVGAnimateElement.h in Headers */,
+                               413C2C341BC29A8F0075204C /* JSDOMConstructor.h in Headers */,
                                4496E39E1398136C003EE32A /* JSSVGAnimateMotionElement.h in Headers */,
                                B2FA3D550AB75A6F000E5AC4 /* JSSVGAnimateTransformElement.h in Headers */,
                                B2FA3D570AB75A6F000E5AC4 /* JSSVGAnimationElement.h in Headers */,
                                CE1252491A16C3BC00864480 /* MobileGestaltSPI.h in Headers */,
                                CDF2B0111820540600F2B424 /* MockBox.h in Headers */,
                                CDF2B0131820540600F2B424 /* MockMediaPlayerMediaSource.h in Headers */,
+                               4129DF861BB5B80C00322A16 /* JSReadableStreamPrivateConstructors.h in Headers */,
                                CDF2B0151820540600F2B424 /* MockMediaSourcePrivate.h in Headers */,
                                4A0FFA9E1AAF5E7E0062803B /* MockRealtimeMediaSourceCenter.h in Headers */,
                                CDF2B0171820540700F2B424 /* MockSourceBufferPrivate.h in Headers */,
                                F55B3DCE1251F12D003EF269 /* RangeInputType.h in Headers */,
                                6E84E9E117668BF100815B68 /* RasterShape.h in Headers */,
                                A84D827C11D333ED00972990 /* RawDataDocumentParser.h in Headers */,
-                               4198BDF11A81143100B22FB5 /* ReadableJSStream.h in Headers */,
-                               41A023F01A39DB7A00F722CF /* ReadableStream.h in Headers */,
-                               419FAFAF1ABABD0C005B828B /* ReadableStreamReader.h in Headers */,
                                FD31603C12B0267600C1A359 /* RealtimeAnalyser.h in Headers */,
                                4A4F65711AA997F100E38CDD /* RealtimeMediaSource.h in Headers */,
                                4A4F65721AA997F100E38CDD /* RealtimeMediaSourceCapabilities.h in Headers */,
                                65DF320109D1CC60000BE325 /* JSRange.cpp in Sources */,
                                7C4C96DC1AD4483500365A50 /* JSReadableStream.cpp in Sources */,
                                6C4C96DE1AD4483500365A50 /* JSReadableStreamController.cpp in Sources */,
-                               41189EF91AD8273700B90A0D /* JSReadableStreamControllerCustom.cpp in Sources */,
-                               41A023F61A39DBCB00F722CF /* JSReadableStreamCustom.cpp in Sources */,
                                7C4C96DE1AD4483500365A50 /* JSReadableStreamReader.cpp in Sources */,
-                               419FAFB11ABABDED005B828B /* JSReadableStreamReaderCustom.cpp in Sources */,
                                BCFE2F110C1B58370020235F /* JSRect.cpp in Sources */,
                                4998AECD13F9D6C90090B1AA /* JSRequestAnimationFrameCallback.cpp in Sources */,
                                BC74DA481013F468007987AD /* JSRGBColor.cpp in Sources */,
                                267726001A5B3AD9003C24DD /* NFAToDFA.cpp in Sources */,
                                BCEF43E00E674110001C1287 /* NinePieceImage.cpp in Sources */,
                                A8C4A80009D563270003AC8D /* Node.cpp in Sources */,
+                               4129DF851BB5B80700322A16 /* JSReadableStreamPrivateConstructors.cpp in Sources */,
                                854FE7320A2297BE0058D7AD /* NodeFilterCondition.cpp in Sources */,
                                854FE7340A2297BE0058D7AD /* NodeIterator.cpp in Sources */,
                                7CEAC1091B483D7F00334482 /* NodeOrString.cpp in Sources */,
                                93F19AB908245E59001E9ABC /* Range.cpp in Sources */,
                                F55B3DCD1251F12D003EF269 /* RangeInputType.cpp in Sources */,
                                6E84E9E017668BEE00815B68 /* RasterShape.cpp in Sources */,
-                               4198BDF01A81142200B22FB5 /* ReadableJSStream.cpp in Sources */,
-                               41A023EF1A39DB7A00F722CF /* ReadableStream.cpp in Sources */,
-                               419FAFAE1ABABD08005B828B /* ReadableStreamReader.cpp in Sources */,
                                FD31603B12B0267600C1A359 /* RealtimeAnalyser.cpp in Sources */,
                                4A4F65701AA997F100E38CDD /* RealtimeMediaSource.cpp in Sources */,
                                4A0FFAA11AAF5EA20062803B /* RealtimeMediaSourceCenter.cpp in Sources */,
index 19c951b..0a4a836 100644 (file)
 #include "JSNodeOrString.cpp"
 #include "JSPluginElementFunctions.cpp"
 #include "JSPopStateEventCustom.cpp"
-#if ENABLE(STREAMS_API)
-#include "JSReadableStreamControllerCustom.cpp"
-#include "JSReadableStreamCustom.cpp"
-#include "JSReadableStreamReaderCustom.cpp"
-#include "ReadableJSStream.cpp"
-#endif
+#include "JSReadableStreamPrivateConstructors.cpp"
 #include "JSSQLResultSetRowListCustom.cpp"
 #include "JSSQLTransactionCustom.cpp"
 #include "JSSVGLengthCustom.cpp"
diff --git a/Source/WebCore/bindings/js/JSDOMConstructor.h b/Source/WebCore/bindings/js/JSDOMConstructor.h
new file mode 100644 (file)
index 0000000..5d69c59
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ *  Copyright (C) 2015 Canon Inc. All rights reserved.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef JSDOMConstructor_h
+#define JSDOMConstructor_h
+
+#include "JSDOMBinding.h"
+
+namespace WebCore {
+
+template <typename JSClass> class JSBuiltinConstructor : public DOMConstructorJSBuiltinObject {
+public:
+    typedef DOMConstructorJSBuiltinObject Base;
+
+    static JSBuiltinConstructor* create(JSC::VM& vm, JSC::Structure* structure, JSDOMGlobalObject& globalObject)
+    {
+        JSBuiltinConstructor* constructor = new (NotNull, JSC::allocateCell<JSBuiltinConstructor>(vm.heap)) JSBuiltinConstructor(structure, globalObject);
+        constructor->finishCreation(vm, globalObject);
+        return constructor;
+    }
+
+    static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject& globalObject, JSC::JSValue prototype)
+    {
+        return JSC::Structure::create(vm, &globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
+    }
+
+    DECLARE_INFO;
+
+private:
+    JSBuiltinConstructor(JSC::Structure* structure, JSDOMGlobalObject& globalObject): Base(structure, &globalObject) { }
+
+    void finishCreation(JSC::VM&, JSDOMGlobalObject&);
+    void initializeProperties(JSC::VM&, JSDOMGlobalObject&) { }
+    static JSC::ConstructType getConstructData(JSC::JSCell*, JSC::ConstructData&);
+    static JSC::EncodedJSValue JSC_HOST_CALL construct(JSC::ExecState*);
+
+    // Must be defined for each specialization class.
+    JSC::JSFunction* createInitializeFunction(JSC::VM&, JSC::JSGlobalObject&);
+    JSC::JSObject* createJSObject();
+};
+
+template<typename JSClass> void JSBuiltinConstructor<JSClass>::finishCreation(JSC::VM& vm, JSDOMGlobalObject& globalObject)
+{
+    Base::finishCreation(vm);
+    ASSERT(inherits(info()));
+    setInitializeFunction(vm, *createInitializeFunction(vm, globalObject));
+    initializeProperties(vm, globalObject);
+}
+
+template<typename JSClass> JSC::EncodedJSValue JSC_HOST_CALL JSBuiltinConstructor<JSClass>::construct(JSC::ExecState* state)
+{
+    auto* castedThis = JSC::jsCast<JSBuiltinConstructor*>(state->callee());
+    JSObject* object = castedThis->createJSObject();
+    callFunctionWithCurrentArguments(*state, *object, *castedThis->initializeFunction());
+    return JSC::JSValue::encode(object);
+}
+
+template<typename JSClass> JSC::ConstructType JSBuiltinConstructor<JSClass>::getConstructData(JSC::JSCell*, JSC::ConstructData& constructData)
+{
+    constructData.native.function = construct;
+    return JSC::ConstructTypeHost;
+}
+
+} // namespace WebCore
+
+#endif // JSDOMConstructor_h
index 306ce4b..9e0ff4f 100644 (file)
@@ -48,6 +48,7 @@
 #endif
 
 #if ENABLE(STREAMS_API)
+#include "JSReadableStreamPrivateConstructors.h"
 #include "ReadableStreamInternalsBuiltins.h"
 #endif
 
@@ -88,6 +89,11 @@ void JSDOMWindowBase::finishCreation(VM& vm, JSDOMWindowShell* shell)
         GlobalPropertyInfo(vm.propertyNames->document, jsNull(), DontDelete | ReadOnly),
         GlobalPropertyInfo(vm.propertyNames->window, m_shell, DontDelete | ReadOnly),
 #if ENABLE(STREAMS_API)
+        GlobalPropertyInfo(static_cast<WebCoreJSClientData*>(vm.clientData)->builtinNames().readableStreamClosedPrivateName(), jsNumber(1), DontDelete | ReadOnly),
+        GlobalPropertyInfo(static_cast<WebCoreJSClientData*>(vm.clientData)->builtinNames().readableStreamErroredPrivateName(), jsNumber(2), DontDelete | ReadOnly),
+        GlobalPropertyInfo(static_cast<WebCoreJSClientData*>(vm.clientData)->builtinNames().readableStreamReadablePrivateName(), jsNumber(3), DontDelete | ReadOnly),
+        GlobalPropertyInfo(static_cast<WebCoreJSClientData*>(vm.clientData)->builtinNames().ReadableStreamControllerPrivateName(), createReadableStreamControllerPrivateConstructor(vm, *this), DontDelete | ReadOnly),
+        GlobalPropertyInfo(static_cast<WebCoreJSClientData*>(vm.clientData)->builtinNames().ReadableStreamReaderPrivateName(), createReadableStreamReaderPrivateConstructor(vm, *this), DontDelete | ReadOnly),
 #define DECLARE_GLOBAL_STATIC(name)\
         GlobalPropertyInfo(\
             static_cast<WebCoreJSClientData*>(vm.clientData)->readableStreamInternalsBuiltins().name##PrivateName(),\
diff --git a/Source/WebCore/bindings/js/JSReadableStreamControllerCustom.cpp b/Source/WebCore/bindings/js/JSReadableStreamControllerCustom.cpp
deleted file mode 100644 (file)
index 3817e33..0000000
+++ /dev/null
@@ -1,50 +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.
- */
-
-#include "config.h"
-#include "JSReadableStreamController.h"
-
-#if ENABLE(STREAMS_API)
-
-#include "JSDOMBinding.h"
-#include "ReadableJSStream.h"
-#include <runtime/Error.h>
-
-using namespace JSC;
-
-namespace WebCore {
-
-EncodedJSValue JSC_HOST_CALL constructJSReadableStreamController(ExecState* exec)
-{
-    return throwVMError(exec, createTypeError(exec, ASCIILiteral("ReadableStreamController constructor should not be called directly")));
-}
-
-} // namespace WebCore
-
-#endif
diff --git a/Source/WebCore/bindings/js/JSReadableStreamCustom.cpp b/Source/WebCore/bindings/js/JSReadableStreamCustom.cpp
deleted file mode 100644 (file)
index 2b663ce..0000000
+++ /dev/null
@@ -1,58 +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.
- */
-
-#include "config.h"
-
-#if ENABLE(STREAMS_API)
-#include "JSReadableStream.h"
-
-#include "ExceptionCode.h"
-#include "JSDOMBinding.h"
-#include "JSDOMPromise.h"
-#include "JSReadableStreamReader.h"
-#include "ReadableJSStream.h"
-#include "ReadableStream.h"
-#include "ReadableStreamReader.h"
-#include <runtime/Error.h>
-#include <runtime/Exception.h>
-#include <wtf/NeverDestroyed.h>
-
-using namespace JSC;
-
-namespace WebCore {
-
-JSValue JSReadableStream::pipeTo(ExecState& state)
-{
-    JSValue error = createError(&state, ASCIILiteral("pipeTo is not implemented"));
-    return state.vm().throwException(&state, error);
-}
-
-} // namespace WebCore
-
-#endif
diff --git a/Source/WebCore/bindings/js/JSReadableStreamPrivateConstructors.cpp b/Source/WebCore/bindings/js/JSReadableStreamPrivateConstructors.cpp
new file mode 100644 (file)
index 0000000..d6ac311
--- /dev/null
@@ -0,0 +1,98 @@
+/*
+ *  Copyright (C) 2015 Canon Inc. All rights reserved.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "config.h"
+#include "JSReadableStreamPrivateConstructors.h"
+
+#if ENABLE(STREAMS_API)
+
+#include "JSDOMBinding.h"
+#include "JSDOMConstructor.h"
+#include "JSReadableStream.h"
+#include "JSReadableStreamController.h"
+#include "JSReadableStreamReader.h"
+#include "ReadableStreamInternalsBuiltins.h"
+#include <runtime/CallData.h>
+
+using namespace JSC;
+
+namespace WebCore {
+
+// Public JS ReadableStreamReder and ReadableStreamController constructor callbacks.
+EncodedJSValue JSC_HOST_CALL constructJSReadableStreamController(ExecState* state)
+{
+    return throwVMError(state, createTypeError(state, ASCIILiteral("ReadableStreamController constructor should not be called directly")));
+}
+
+EncodedJSValue JSC_HOST_CALL constructJSReadableStreamReader(ExecState* state)
+{
+    JSReadableStream* stream = jsDynamicCast<JSReadableStream*>(state->argument(0));
+    if (!stream)
+        return throwVMError(state, createTypeError(state, ASCIILiteral("ReadableStreamReader constructor parameter is not a ReadableStream")));
+
+    JSValue jsFunction = stream->get(state, Identifier::fromString(state, "getReader"));
+
+    CallData callData;
+    CallType callType = getCallData(jsFunction, callData);
+    MarkedArgumentBuffer noArguments;
+    return JSValue::encode(call(state, jsFunction, callType, callData, stream, noArguments));
+}
+
+// Private JS ReadableStreamReder and ReadableStreamController constructors.
+typedef JSBuiltinConstructor<JSReadableStreamReader> JSBuiltinReadableStreamReaderPrivateConstructor;
+typedef JSBuiltinConstructor<JSReadableStreamController> JSBuiltinReadableStreamControllerPrivateConstructor;
+
+STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(JSBuiltinReadableStreamReaderPrivateConstructor);
+STATIC_ASSERT_IS_TRIVIALLY_DESTRUCTIBLE(JSBuiltinReadableStreamControllerPrivateConstructor);
+
+template<> const ClassInfo JSBuiltinReadableStreamReaderPrivateConstructor::s_info = { "ReadableStreamReaderPrivateConstructor", &Base::s_info, 0, CREATE_METHOD_TABLE(JSBuiltinReadableStreamReaderPrivateConstructor) };
+template<> const ClassInfo JSBuiltinReadableStreamControllerPrivateConstructor::s_info = { "ReadableStreamControllerPrivateConstructor", &Base::s_info, 0, CREATE_METHOD_TABLE(JSBuiltinReadableStreamControllerPrivateConstructor) };
+
+template<> JSObject* JSBuiltinReadableStreamReaderPrivateConstructor::createJSObject()
+{
+    return JSReadableStreamReader::create(getDOMStructure<JSReadableStreamReader>(globalObject()->vm(), globalObject()), globalObject(), ReadableStreamReader::create());
+}
+
+template<> JSObject* JSBuiltinReadableStreamControllerPrivateConstructor::createJSObject()
+{
+    return JSReadableStreamController::create(getDOMStructure<JSReadableStreamController>(globalObject()->vm(), globalObject()), globalObject(), ReadableStreamController::create());
+}
+
+template<> JSFunction* JSBuiltinReadableStreamReaderPrivateConstructor::createInitializeFunction(JSC::VM& vm, JSC::JSGlobalObject& globalObject)
+{
+    return JSFunction::createBuiltinFunction(vm, readableStreamInternalsPrivateInitializeReadableStreamReaderCodeGenerator(vm), &globalObject);
+}
+
+template<> JSFunction* JSBuiltinReadableStreamControllerPrivateConstructor::createInitializeFunction(JSC::VM& vm, JSC::JSGlobalObject& globalObject)
+{
+    return JSFunction::createBuiltinFunction(vm, readableStreamInternalsPrivateInitializeReadableStreamControllerCodeGenerator(vm), &globalObject);
+}
+
+JSValue createReadableStreamReaderPrivateConstructor(VM& vm, JSDOMGlobalObject& globalObject)
+{
+    return JSBuiltinReadableStreamReaderPrivateConstructor::create(vm, JSBuiltinReadableStreamReaderPrivateConstructor::createStructure(vm, globalObject, globalObject.objectPrototype()), globalObject);
+}
+
+JSValue createReadableStreamControllerPrivateConstructor(VM& vm, JSDOMGlobalObject& globalObject)
+{
+    return JSBuiltinReadableStreamControllerPrivateConstructor::create(vm, JSBuiltinReadableStreamControllerPrivateConstructor::createStructure(vm, globalObject, globalObject.objectPrototype()), globalObject);
+}
+
+} // namespace WebCore
+
+#endif
diff --git a/Source/WebCore/bindings/js/JSReadableStreamPrivateConstructors.h b/Source/WebCore/bindings/js/JSReadableStreamPrivateConstructors.h
new file mode 100644 (file)
index 0000000..74000a4
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ *  Copyright (C) 2015 Canon Inc. All rights reserved.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef JSReadableStreamPrivateConstructors_h
+#define JSReadableStreamPrivateConstructors_h
+
+#if ENABLE(STREAMS_API)
+
+#include <runtime/JSCJSValue.h>
+
+namespace WebCore {
+
+class JSDOMGlobalObject;
+
+JSC::JSValue createReadableStreamControllerPrivateConstructor(JSC::VM&, JSDOMGlobalObject&);
+JSC::JSValue createReadableStreamReaderPrivateConstructor(JSC::VM&, JSDOMGlobalObject&);
+
+} // namespace WebCore
+
+#endif
+
+#endif // ReadableStreamConstructors_h
diff --git a/Source/WebCore/bindings/js/JSReadableStreamReaderCustom.cpp b/Source/WebCore/bindings/js/JSReadableStreamReaderCustom.cpp
deleted file mode 100644 (file)
index 54b1697..0000000
+++ /dev/null
@@ -1,77 +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.
- */
-
-#include "config.h"
-
-#if ENABLE(STREAMS_API)
-#include "JSReadableStreamReader.h"
-
-#include "ExceptionCode.h"
-#include "JSDOMPromise.h"
-#include "JSReadableStream.h"
-#include "ReadableJSStream.h"
-#include <runtime/Error.h>
-#include <runtime/IteratorOperations.h>
-#include <wtf/NeverDestroyed.h>
-
-using namespace JSC;
-
-namespace WebCore {
-
-JSValue JSReadableStreamReader::closed(ExecState& state) const
-{
-    if (!m_closed) {
-        JSPromiseDeferred* closedPromise = JSPromiseDeferred::create(&state, globalObject());
-        m_closed.set(state.vm(), this, closedPromise->promise());
-        impl().closed(DeferredWrapper(&state, globalObject(), closedPromise));
-    }
-    return m_closed.get();
-}
-
-EncodedJSValue JSC_HOST_CALL constructJSReadableStreamReader(ExecState* exec)
-{
-    if (!exec->argumentCount())
-        return throwVMError(exec, createTypeError(exec, ASCIILiteral("ReadableStreamReader constructor takes a ReadableStream as parameter")));
-
-    JSReadableStream* stream = jsDynamicCast<JSReadableStream*>(exec->argument(0));
-    if (!stream)
-        return throwVMError(exec, createTypeError(exec, ASCIILiteral("ReadableStreamReader constructor parameter is not a ReadableStream")));
-
-    if (stream->impl().locked())
-        return throwVMError(exec, createTypeError(exec, ASCIILiteral("ReadableStreamReader constructor parameter is a locked ReadableStream")));
-
-    ExceptionCode ec = 0;
-    EncodedJSValue value = JSValue::encode(toJS(exec, stream->globalObject(), stream->impl().getReader(ec)));
-    ASSERT(!ec);
-    return value;
-}
-
-} // namespace WebCore
-
-#endif
diff --git a/Source/WebCore/bindings/js/ReadableJSStream.cpp b/Source/WebCore/bindings/js/ReadableJSStream.cpp
deleted file mode 100644 (file)
index dcc77fe..0000000
+++ /dev/null
@@ -1,374 +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.
- */
-
-#include "config.h"
-#include "ReadableJSStream.h"
-
-#if ENABLE(STREAMS_API)
-
-#include "DOMWrapperWorld.h"
-#include "Dictionary.h"
-#include "ExceptionCode.h"
-#include "JSDOMPromise.h"
-#include "JSReadableStream.h"
-#include "JSReadableStreamController.h"
-#include "ScriptExecutionContext.h"
-#include "ScriptState.h"
-#include <runtime/Error.h>
-#include <runtime/Exception.h>
-#include <runtime/JSCJSValueInlines.h>
-#include <runtime/JSNativeStdFunction.h>
-#include <runtime/JSPromise.h>
-#include <runtime/JSString.h>
-#include <runtime/StructureInlines.h>
-
-using namespace JSC;
-
-namespace WebCore {
-
-static inline JSValue callFunction(ExecState& exec, JSValue jsFunction, JSValue thisValue, const ArgList& arguments)
-{
-    CallData callData;
-    CallType callType = getCallData(jsFunction, callData);
-    return call(&exec, jsFunction, callType, callData, thisValue, arguments);
-}
-
-JSPromise* ReadableJSStream::invoke(ExecState& state, const char* propertyName, JSValue parameter)
-{
-    JSValue function = getPropertyFromObject(state, *m_source.get(), propertyName);
-    if (state.hadException())
-        return nullptr;
-
-    if (!function.isFunction()) {
-        if (!function.isUndefined())
-            throwVMError(&state, createTypeError(&state, ASCIILiteral("ReadableStream trying to call a property that is not callable")));
-        return nullptr;
-    }
-
-    MarkedArgumentBuffer arguments;
-    arguments.append(parameter);
-
-    JSPromise* promise = jsDynamicCast<JSPromise*>(callFunction(state, function, m_source.get(), arguments));
-
-    ASSERT(!(promise && state.hadException()));
-    return promise;
-}
-
-static void thenPromise(ExecState& state, JSPromise* deferredPromise, JSValue fullfilFunction, JSValue rejectFunction)
-{
-    JSValue thenValue = deferredPromise->get(&state, state.vm().propertyNames->then);
-    if (state.hadException())
-        return;
-
-    MarkedArgumentBuffer arguments;
-    arguments.append(fullfilFunction);
-    arguments.append(rejectFunction);
-
-    callFunction(state, thenValue, deferredPromise, arguments);
-}
-
-JSDOMGlobalObject* ReadableJSStream::globalObject()
-{
-    return jsDynamicCast<JSDOMGlobalObject*>(m_source->globalObject());
-}
-
-static inline JSFunction* createGenericErrorRejectedFunction(ExecState& state, ReadableJSStream& readableStream)
-{
-    RefPtr<ReadableJSStream> stream = &readableStream;
-    return JSNativeStdFunction::create(state.vm(), state.callee()->globalObject(), 1, String(), [stream](ExecState* state) {
-        stream->storeError(*state, state->argument(0));
-        return JSValue::encode(jsUndefined());
-    });
-}
-
-static inline JSFunction* createStartResultFulfilledFunction(ExecState& state, ReadableStream& readableStream)
-{
-    RefPtr<ReadableStream> stream = &readableStream;
-    return JSNativeStdFunction::create(state.vm(), state.callee()->globalObject(), 1, String(), [stream](ExecState*) {
-        stream->start();
-        return JSValue::encode(jsUndefined());
-    });
-}
-
-static inline void startReadableStreamAsync(ReadableStream& stream)
-{
-    RefPtr<ReadableStream> protectedStream = &stream;
-    stream.scriptExecutionContext()->postTask([protectedStream](ScriptExecutionContext&) {
-        protectedStream->start();
-    });
-}
-
-JSC::JSValue ReadableEnqueuingStream<ReadableJSStreamValue>::read()
-{
-    ReadableJSStreamValue chunk = m_queue.takeFirst();
-    m_totalQueueSize -= chunk.size;
-    return chunk.value.get();
-}
-
-void ReadableEnqueuingStream<ReadableJSStreamValue>::enqueueChunk(ReadableJSStreamValue&& chunk)
-{
-    m_totalQueueSize += chunk.size;
-    m_queue.append(WTF::move(chunk));
-}
-
-void ReadableJSStream::doStart(ExecState& exec)
-{
-    JSLockHolder lock(&exec);
-
-    JSPromise* promise = invoke(exec, "start", jsController(exec, globalObject()));
-
-    if (exec.hadException())
-        return;
-
-    if (!promise) {
-        startReadableStreamAsync(*this);
-        return;
-    }
-
-    thenPromise(exec, promise, createStartResultFulfilledFunction(exec, *this), createGenericErrorRejectedFunction(exec, *this));
-}
-
-static inline JSFunction* createPullResultFulfilledFunction(ExecState& exec, ReadableStream& stream)
-{
-    RefPtr<ReadableStream> protectedStream = &stream;
-    return JSNativeStdFunction::create(exec.vm(), exec.callee()->globalObject(), 0, String(), [protectedStream](ExecState*) {
-        protectedStream->finishPulling();
-        return JSValue::encode(jsUndefined());
-    });
-}
-
-bool ReadableJSStream::doPull()
-{
-    ExecState& state = *globalObject()->globalExec();
-    JSLockHolder lock(&state);
-
-    JSPromise* promise = invoke(state, "pull", jsController(state, globalObject()));
-
-    if (promise)
-        thenPromise(state, promise, createPullResultFulfilledFunction(state, *this), createGenericErrorRejectedFunction(state, *this));
-
-    if (state.hadException()) {
-        storeException(state);
-        ASSERT(!state.hadException());
-        return true;
-    }
-
-    return !promise;
-}
-
-static JSFunction* createCancelResultFulfilledFunction(ExecState& exec, ReadableStream& stream)
-{
-    RefPtr<ReadableStream> protectedStream = &stream;
-    return JSNativeStdFunction::create(exec.vm(), exec.callee()->globalObject(), 1, String(), [protectedStream](ExecState*) {
-        protectedStream->notifyCancelSucceeded();
-        return JSValue::encode(jsUndefined());
-    });
-}
-
-static JSFunction* createCancelResultRejectedFunction(ExecState& exec, ReadableJSStream& stream)
-{
-    RefPtr<ReadableJSStream> protectedStream = &stream;
-    return JSNativeStdFunction::create(exec.vm(), exec.callee()->globalObject(), 1, String(), [protectedStream](ExecState* exec) {
-        protectedStream->storeError(*exec, exec->argument(0));
-        protectedStream->notifyCancelFailed();
-        return JSValue::encode(jsUndefined());
-    });
-}
-
-bool ReadableJSStream::doCancel(JSValue reason)
-{
-    ExecState& exec = *globalObject()->globalExec();
-    JSLockHolder lock(&exec);
-
-    JSPromise* promise = invoke(exec, "cancel", reason);
-
-    if (promise)
-        thenPromise(exec, promise, createCancelResultFulfilledFunction(exec, *this), createCancelResultRejectedFunction(exec, *this));
-
-    if (exec.hadException()) {
-        storeException(exec);
-        ASSERT(!exec.hadException());
-        return true;
-    }
-    return !promise;
-}
-
-RefPtr<ReadableJSStream> ReadableJSStream::create(JSC::ExecState& state, JSC::JSValue source, const Dictionary& strategy)
-{
-    JSObject* jsSource;
-    if (source.isObject())
-        jsSource = source.getObject();
-    else if (!source.isUndefined()) {
-        throwVMTypeError(&state, "Argument 1 of ReadableStream constructor must be an object");
-        return nullptr;
-    } else
-        jsSource = JSFinalObject::create(state.vm(), JSFinalObject::createStructure(state.vm(), state.callee()->globalObject(), jsNull(), 1));
-
-    double highWaterMark = 1;
-    JSFunction* sizeFunction = nullptr;
-    if (!strategy.isUndefinedOrNull()) {
-        if (strategy.get("highWaterMark", highWaterMark)) {
-            if (std::isnan(highWaterMark)) {
-                throwVMTypeError(&state, "'highWaterMark' of Argument 2 of ReadableStream constructor cannot be NaN");
-                return nullptr;
-            }
-            if (highWaterMark < 0) {
-                throwVMRangeError(&state, "'highWaterMark' of Argument 2 of ReadableStream constructor cannot be negative");
-                return nullptr;
-            }
-
-        } else if (state.hadException())
-            return nullptr;
-
-        if (strategy.get("size", sizeFunction)) {
-            if (!sizeFunction) {
-                throwVMTypeError(&state, "'size' of Argument 2 of ReadableStream constructor must be a function");
-                return nullptr;
-            }
-        } else if (state.hadException())
-            return nullptr;
-    }
-
-    RefPtr<ReadableJSStream> readableStream = adoptRef(*new ReadableJSStream(state, jsSource, highWaterMark, sizeFunction));
-    readableStream->doStart(state);
-
-    if (state.hadException())
-        return nullptr;
-
-    return readableStream;
-}
-
-ReadableJSStream::ReadableJSStream(ExecState& state, JSObject* source, double highWaterMark, JSFunction* sizeFunction)
-    : ReadableEnqueuingStream<ReadableJSStreamValue>(*scriptExecutionContextFromExecState(&state), highWaterMark)
-{
-    m_source.set(state.vm(), source);
-    if (sizeFunction)
-        m_sizeFunction.set(state.vm(), sizeFunction);
-}
-
-JSValue ReadableJSStream::jsController(ExecState& exec, JSDOMGlobalObject* globalObject)
-{
-    if (!m_controller)
-        m_controller = std::make_unique<ReadableStreamController>(*this);
-    return toJS(&exec, globalObject, m_controller.get());
-}
-
-void ReadableJSStream::close(ExceptionCode& ec)
-{
-    if (isCloseRequested() || isErrored()) {
-        ec = TypeError;
-        return;
-    }
-    changeStateToClosed();
-}
-
-void ReadableJSStream::error(JSC::ExecState& state, JSC::JSValue value, ExceptionCode& ec)
-{
-    if (!isReadable()) {
-        ec = TypeError;
-        return;
-    }
-    storeError(state, value);
-}
-
-void ReadableJSStream::storeException(JSC::ExecState& state)
-{
-    JSValue exception = state.exception()->value();
-    state.clearException();
-    storeError(state, exception);
-}
-
-void ReadableJSStream::storeError(JSC::ExecState& exec, JSValue error)
-{
-    if (m_error)
-        return;
-    m_error.set(exec.vm(), error);
-
-    changeStateToErrored();
-}
-
-void ReadableJSStream::enqueue(JSC::ExecState& state, JSC::JSValue chunk)
-{
-    if (isErrored()) {
-        throwVMError(&state, error());
-        return;
-    }
-    if (isCloseRequested()) {
-        throwVMError(&state, createDOMException(&state, TypeError));
-        return;
-    }
-    if (!isReadable())
-        return;
-
-    if (resolveReadCallback(chunk)) {
-        pull();
-        return;
-    }
-
-    double size = retrieveChunkSize(state, chunk);
-    if (state.hadException())
-        return;
-
-    enqueueChunk({ JSC::Strong<JSC::Unknown>(state.vm(), chunk), size });
-
-    pull();
-}
-
-double ReadableJSStream::retrieveChunkSize(ExecState& state, JSValue chunk)
-{
-    if (!m_sizeFunction)
-        return 1;
-
-    MarkedArgumentBuffer arguments;
-    arguments.append(chunk);
-
-    JSValue sizeValue = callFunction(state, m_sizeFunction.get(), jsUndefined(), arguments);
-    if (state.hadException()) {
-        storeError(state, state.exception()->value());
-        return 0;
-    }
-
-    double size = sizeValue.toNumber(&state);
-    if (state.hadException()) {
-        storeError(state, state.exception()->value());
-        return 0;
-    }
-
-    if (!std::isfinite(size) || size < 0) {
-        storeError(state, createDOMException(&state, RangeError));
-        throwVMError(&state, error());
-        return 0;
-    }
-
-    return size;
-}
-
-} // namespace WebCore
-
-#endif
diff --git a/Source/WebCore/bindings/js/ReadableJSStream.h b/Source/WebCore/bindings/js/ReadableJSStream.h
deleted file mode 100644 (file)
index f831b89..0000000
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * Copyright (C) 2O15 Canon Inc. 2015
- * Copyright (C) 2015 Igalia S.L. 2015
- *
- * 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 ReadableJSStream_h
-#define ReadableJSStream_h
-
-#if ENABLE(STREAMS_API)
-
-#include "ReadableStream.h"
-#include <heap/Strong.h>
-#include <heap/StrongInlines.h>
-#include <runtime/JSCJSValue.h>
-#include <runtime/PrivateName.h>
-#include <wtf/Deque.h>
-#include <wtf/Ref.h>
-
-namespace JSC {
-class JSFunction;
-class JSPromise;
-}
-    
-namespace WebCore {
-
-class JSDOMGlobalObject;
-class ReadableStreamController;
-
-typedef int ExceptionCode;
-
-struct ReadableJSStreamValue {
-    JSC::Strong<JSC::Unknown> value;
-    double size;
-};
-
-template<> class ReadableEnqueuingStream<ReadableJSStreamValue> : public ReadableStream {
-public:
-    double desiredSize() const { return m_highWaterMark - m_totalQueueSize; }
-
-protected:
-    ReadableEnqueuingStream(ScriptExecutionContext& context, double highWaterMark)
-        : ReadableStream(context)
-        , m_highWaterMark(highWaterMark) { }
-
-    void enqueueChunk(ReadableJSStreamValue&&);
-
-private:
-    virtual void clearValues() override { m_queue.clear(); }
-    virtual bool hasEnoughValues() const override { return desiredSize() <= 0; }
-    virtual bool hasValue() const override { return m_queue.size(); }
-    virtual JSC::JSValue read() override;
-
-    Deque<ReadableJSStreamValue> m_queue;
-    double m_totalQueueSize { 0 };
-    double m_highWaterMark;
-};
-
-class ReadableJSStream final : public ReadableEnqueuingStream<ReadableJSStreamValue> {
-public:
-    static RefPtr<ReadableJSStream> create(JSC::ExecState&, JSC::JSValue, const Dictionary&);
-
-    JSC::JSValue jsController(JSC::ExecState&, JSDOMGlobalObject*);
-    void close(ExceptionCode&);
-
-    void storeError(JSC::ExecState&, JSC::JSValue);
-    JSC::JSValue error() override { return m_error.get(); }
-
-    void enqueue(JSC::ExecState&, JSC::JSValue);
-    void error(JSC::ExecState&, JSC::JSValue, ExceptionCode&);
-
-private:
-    ReadableJSStream(JSC::ExecState&, JSC::JSObject*, double, JSC::JSFunction*);
-
-    void doStart(JSC::ExecState&);
-
-    JSC::JSPromise* invoke(JSC::ExecState&, const char*, JSC::JSValue parameter);
-    void storeException(JSC::ExecState&);
-
-    virtual bool doPull() override;
-    virtual bool doCancel(JSC::JSValue) override;
-
-    JSDOMGlobalObject* globalObject();
-
-    double retrieveChunkSize(JSC::ExecState&, JSC::JSValue);
-
-    std::unique_ptr<ReadableStreamController> m_controller;
-    // FIXME: we should consider not using JSC::Strong, see https://bugs.webkit.org/show_bug.cgi?id=146278
-    JSC::Strong<JSC::Unknown> m_error;
-
-    JSC::Strong<JSC::JSObject> m_source;
-    JSC::Strong<JSC::JSFunction> m_sizeFunction;
-};
-
-} // namespace WebCore
-
-#endif // ENABLE(STREAMS_API)
-
-#endif // ReadableJSStream_h
diff --git a/Source/WebCore/bindings/js/WebCoreBuiltinNames.h b/Source/WebCore/bindings/js/WebCoreBuiltinNames.h
new file mode 100644 (file)
index 0000000..e99e069
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ *  Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
+ *  Copyright (C) 2003, 2004, 2005, 2006, 2008, 2009 Apple Inc. All rights reserved.
+ *  Copyright (C) 2007 Samuel Weinig <sam@webkit.org>
+ *  Copyright (C) 2009 Google, Inc. All rights reserved.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef WebCoreBuiltinNames_h
+#define WebCoreBuiltinNames_h
+
+#include <builtins/BuiltinUtils.h>
+
+namespace WebCore {
+
+#define WEBCORE_COMMON_PRIVATE_IDENTIFIERS_EACH_PROPERTY_NAME(macro)\
+    macro(state) \
+    macro(underlyingSource) \
+    macro(queue) \
+    macro(queueSize) \
+    macro(started) \
+    macro(closeRequested) \
+    macro(pullAgain) \
+    macro(pulling) \
+    macro(reader) \
+    macro(storedError) \
+    macro(controller) \
+    macro(strategySize) \
+    macro(highWaterMark) \
+    macro(readRequests) \
+    macro(ownerReadableStream) \
+    macro(closedPromise) \
+    macro(closedPromiseResolve) \
+    macro(closedPromiseReject) \
+    macro(controlledReadableStream) \
+    macro(readableStreamClosed) \
+    macro(readableStreamReadable) \
+    macro(readableStreamErrored) \
+    macro(ReadableStreamReader) \
+    macro(ReadableStreamController) \
+
+class WebCoreBuiltinNames {
+public:
+    explicit WebCoreBuiltinNames(JSC::VM* vm)
+        : m_vm(*vm)
+        WEBCORE_COMMON_PRIVATE_IDENTIFIERS_EACH_PROPERTY_NAME(INITIALIZE_BUILTIN_NAMES)
+    {
+#define EXPORT_NAME(name) m_vm.propertyNames->appendExternalName(name##PublicName(), name##PrivateName());
+        WEBCORE_COMMON_PRIVATE_IDENTIFIERS_EACH_PROPERTY_NAME(EXPORT_NAME)
+#undef EXPORT_NAME
+    }
+
+    WEBCORE_COMMON_PRIVATE_IDENTIFIERS_EACH_PROPERTY_NAME(DECLARE_BUILTIN_IDENTIFIER_ACCESSOR)
+
+private:
+    JSC::VM& m_vm;
+    WEBCORE_COMMON_PRIVATE_IDENTIFIERS_EACH_PROPERTY_NAME(DECLARE_BUILTIN_NAMES)
+};
+
+} // namespace WebCore
+
+#endif // WebCoreBuiltinNames_h
index 0ccb411..96c7e0e 100644 (file)
@@ -29,5 +29,7 @@
 #include "ByteLengthQueuingStrategyBuiltins.cpp"
 #include "CountQueuingStrategyBuiltins.cpp"
 #include "ReadableStreamBuiltins.cpp"
+#include "ReadableStreamControllerBuiltins.cpp"
 #include "ReadableStreamInternalsBuiltins.cpp"
+#include "ReadableStreamReaderBuiltins.cpp"
 #endif
index 03dc641..870dd81 100644 (file)
@@ -23,6 +23,7 @@
 #define WebCoreJSClientData_h
 
 #include "DOMWrapperWorld.h"
+#include "WebCoreBuiltinNames.h"
 #include "WebCoreTypedArrayController.h"
 #include <wtf/HashSet.h>
 #include <wtf/RefPtr.h>
@@ -31,7 +32,9 @@
 #include "ByteLengthQueuingStrategyBuiltinsWrapper.h"
 #include "CountQueuingStrategyBuiltinsWrapper.h"
 #include "ReadableStreamBuiltinsWrapper.h"
+#include "ReadableStreamControllerBuiltinsWrapper.h"
 #include "ReadableStreamInternalsBuiltinsWrapper.h"
+#include "ReadableStreamReaderBuiltinsWrapper.h"
 #endif
 
 namespace WebCore {
@@ -42,14 +45,15 @@ class WebCoreJSClientData : public JSC::VM::ClientData {
     friend void initNormalWorldClientData(JSC::VM*);
 
 public:
-#if ENABLE(STREAMS_API)
     explicit WebCoreJSClientData(JSC::VM& vm)
-        : m_readableStreamBuiltins(&vm)
+        : m_builtinNames(&vm)
+#if ENABLE(STREAMS_API)
+        , m_readableStreamBuiltins(&vm)
+        , m_readableStreamControllerBuiltins(&vm)
         , m_readableStreamInternalsBuiltins(&vm)
+        , m_readableStreamReaderBuiltins(&vm)
         , m_byteLengthQueuingStrategyBuiltins(&vm)
         , m_countQueuingStrategyBuiltins(&vm)
-#else
-    WebCoreJSClientData(JSC::VM&)
 #endif
     {
 #if ENABLE(STREAMS_API)
@@ -89,9 +93,13 @@ public:
         m_worldSet.remove(&world);
     }
 
+    WebCoreBuiltinNames& builtinNames() { return m_builtinNames; }
+
 #if ENABLE(STREAMS_API)
     ReadableStreamBuiltinsWrapper& readableStreamBuiltins() { return m_readableStreamBuiltins; }
+    ReadableStreamControllerBuiltinsWrapper& readableStreamControllerBuiltins() { return m_readableStreamControllerBuiltins; }
     ReadableStreamInternalsBuiltinsWrapper& readableStreamInternalsBuiltins() { return m_readableStreamInternalsBuiltins; }
+    ReadableStreamReaderBuiltinsWrapper& readableStreamReaderBuiltins() { return m_readableStreamReaderBuiltins; }
     ByteLengthQueuingStrategyBuiltinsWrapper& byteLengthQueuingStrategyBuiltins() { return m_byteLengthQueuingStrategyBuiltins; }
     CountQueuingStrategyBuiltinsWrapper& countQueuingStrategyBuiltins() { return m_countQueuingStrategyBuiltins; }
 #endif
@@ -100,9 +108,13 @@ private:
     HashSet<DOMWrapperWorld*> m_worldSet;
     RefPtr<DOMWrapperWorld> m_normalWorld;
 
+    WebCoreBuiltinNames m_builtinNames;
+
 #if ENABLE(STREAMS_API)
     ReadableStreamBuiltinsWrapper m_readableStreamBuiltins;
+    ReadableStreamControllerBuiltinsWrapper m_readableStreamControllerBuiltins;
     ReadableStreamInternalsBuiltinsWrapper m_readableStreamInternalsBuiltins;
+    ReadableStreamReaderBuiltinsWrapper m_readableStreamReaderBuiltins;
     ByteLengthQueuingStrategyBuiltinsWrapper m_byteLengthQueuingStrategyBuiltins;
     CountQueuingStrategyBuiltinsWrapper m_countQueuingStrategyBuiltins;
 #endif