Diff
Modified: trunk/LayoutTests/imported/w3c/ChangeLog (200234 => 200235)
--- trunk/LayoutTests/imported/w3c/ChangeLog 2016-04-29 08:09:36 UTC (rev 200234)
+++ trunk/LayoutTests/imported/w3c/ChangeLog 2016-04-29 08:15:10 UTC (rev 200235)
@@ -1,3 +1,12 @@
+2016-04-29 Youenn Fablet <[email protected]>
+
+ FetchResponse should return a ReadableStream even if disturbed
+ https://bugs.webkit.org/show_bug.cgi?id=156911
+
+ Reviewed by Darin Adler.
+
+ * web-platform-tests/fetch/api/response/response-stream-disturbed-5-expected.txt: Rebasing test.
+
2016-04-29 Ryosuke Niwa <[email protected]>
Import W3C CSS WG tests for shadow DOM
Modified: trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-stream-disturbed-5-expected.txt (200234 => 200235)
--- trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-stream-disturbed-5-expected.txt 2016-04-29 08:09:36 UTC (rev 200234)
+++ trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-stream-disturbed-5-expected.txt 2016-04-29 08:15:10 UTC (rev 200235)
@@ -1,6 +1,6 @@
-FAIL Getting a body reader after consuming as blob assert_not_equals: got disallowed value null
-FAIL Getting a body reader after consuming as text assert_not_equals: got disallowed value null
-FAIL Getting a body reader after consuming as json assert_not_equals: got disallowed value null
-FAIL Getting a body reader after consuming as arrayBuffer assert_not_equals: got disallowed value null
+PASS Getting a body reader after consuming as blob
+PASS Getting a body reader after consuming as text
+PASS Getting a body reader after consuming as json
+PASS Getting a body reader after consuming as arrayBuffer
Modified: trunk/Source/WebCore/ChangeLog (200234 => 200235)
--- trunk/Source/WebCore/ChangeLog 2016-04-29 08:09:36 UTC (rev 200234)
+++ trunk/Source/WebCore/ChangeLog 2016-04-29 08:15:10 UTC (rev 200235)
@@ -1,3 +1,21 @@
+2016-04-29 Youenn Fablet <[email protected]>
+
+ FetchResponse should return a ReadableStream even if disturbed
+ https://bugs.webkit.org/show_bug.cgi?id=156911
+
+ Reviewed by Darin Adler.
+
+ Covered by rebased test.
+
+ * Modules/fetch/FetchResponse.cpp:
+ (WebCore::FetchResponse::createReadableStreamSource): Asserting in case response is disturbed.
+ * bindings/js/JSFetchResponseCustom.cpp:
+ (WebCore::JSFetchResponse::body): Creating a locked empty readable stream if response is disturbed.
+ * bindings/js/ReadableStreamController.cpp:
+ (WebCore::createReadableStream): Constructing a readable stream even if source is null.
+ (WebCore::getReadableStreamReader): Retrieving the reader from a readable stream. Stream must not be locked.
+ * bindings/js/ReadableStreamController.h:
+
2016-04-29 Yoav Weiss <[email protected]>
Move ResourceTiming behind a runtime flag
Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp (200234 => 200235)
--- trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp 2016-04-29 08:09:36 UTC (rev 200234)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp 2016-04-29 08:15:10 UTC (rev 200235)
@@ -293,7 +293,9 @@
ReadableStreamSource* FetchResponse::createReadableStreamSource()
{
ASSERT(!m_readableStreamSource);
- if (body().isEmpty() || isDisturbed())
+ ASSERT(!isDisturbed());
+
+ if (body().isEmpty())
return nullptr;
m_readableStreamSource = adoptRef(*new FetchResponseSource(*this));
Modified: trunk/Source/WebCore/bindings/js/JSFetchResponseCustom.cpp (200234 => 200235)
--- trunk/Source/WebCore/bindings/js/JSFetchResponseCustom.cpp 2016-04-29 08:09:36 UTC (rev 200234)
+++ trunk/Source/WebCore/bindings/js/JSFetchResponseCustom.cpp 2016-04-29 08:15:10 UTC (rev 200235)
@@ -38,8 +38,18 @@
JSC::JSValue JSFetchResponse::body(JSC::ExecState& state) const
{
#if ENABLE(STREAMS_API)
- if (!m_body)
- m_body.set(state.vm(), this, createReadableStream(state, globalObject(), wrapped().createReadableStreamSource()));
+ if (!m_body) {
+ JSC::JSValue readableStream;
+ if (wrapped().isDisturbed()) {
+ readableStream = createReadableStream(state, globalObject(), nullptr);
+ // Let's get the reader to lock it.
+ getReadableStreamReader(state, readableStream);
+ } else {
+ ReadableStreamSource* source = wrapped().createReadableStreamSource();
+ readableStream = source ? createReadableStream(state, globalObject(), source) : JSC::jsNull();
+ }
+ m_body.set(state.vm(), this, readableStream);
+ }
return m_body.get();
#else
UNUSED_PARAM(state);
Modified: trunk/Source/WebCore/bindings/js/ReadableStreamController.cpp (200234 => 200235)
--- trunk/Source/WebCore/bindings/js/ReadableStreamController.cpp 2016-04-29 08:09:36 UTC (rev 200234)
+++ trunk/Source/WebCore/bindings/js/ReadableStreamController.cpp 2016-04-29 08:15:10 UTC (rev 200235)
@@ -86,12 +86,9 @@
JSC::JSValue createReadableStream(JSC::ExecState& state, JSDOMGlobalObject* globalObject, ReadableStreamSource* source)
{
- if (!source)
- return JSC::jsNull();
-
JSC::JSLockHolder lock(&state);
- JSC::JSValue jsSource = toJS(&state, globalObject, source);
+ JSC::JSValue jsSource = source ? toJS(&state, globalObject, source) : JSC::jsUndefined();
JSC::Strong<JSC::Unknown> protect(state.vm(), jsSource);
JSC::MarkedArgumentBuffer arguments;
@@ -106,6 +103,19 @@
return JSC::construct(&state, constructor, constructType, constructData, arguments);
}
+JSC::JSValue getReadableStreamReader(JSC::ExecState& state, JSC::JSValue readableStream)
+{
+ ASSERT(readableStream.isObject());
+
+ JSC::JSValue getReader = readableStream.getObject()->get(&state, JSC::Identifier::fromString(&state, "getReader"));
+ ASSERT(!state.hadException());
+
+ JSC::JSValue reader = callFunction(state, getReader, readableStream, JSC::MarkedArgumentBuffer());
+ ASSERT(!state.hadException());
+
+ return reader;
+}
+
} // namespace WebCore
#endif // ENABLE(STREAMS_API)
Modified: trunk/Source/WebCore/bindings/js/ReadableStreamController.h (200234 => 200235)
--- trunk/Source/WebCore/bindings/js/ReadableStreamController.h 2016-04-29 08:09:36 UTC (rev 200234)
+++ trunk/Source/WebCore/bindings/js/ReadableStreamController.h 2016-04-29 08:15:10 UTC (rev 200235)
@@ -67,6 +67,7 @@
};
JSC::JSValue createReadableStream(JSC::ExecState&, JSDOMGlobalObject*, ReadableStreamSource*);
+JSC::JSValue getReadableStreamReader(JSC::ExecState&, JSC::JSValue);
inline JSDOMGlobalObject* ReadableStreamController::globalObject() const
{