Diff
Modified: trunk/LayoutTests/ChangeLog (205250 => 205251)
--- trunk/LayoutTests/ChangeLog 2016-08-31 16:36:35 UTC (rev 205250)
+++ trunk/LayoutTests/ChangeLog 2016-08-31 16:36:57 UTC (rev 205251)
@@ -1,5 +1,18 @@
2016-08-31 Youenn Fablet <[email protected]>
+ [Fetch API] Response bodyUsed should check for its body disturbed state
+ https://bugs.webkit.org/show_bug.cgi?id=161429
+
+ Reviewed by Alex Christensen.
+
+ * http/tests/fetch/bodyUsed-expected.txt: Added.
+ * http/tests/fetch/bodyUsed-worker-expected.txt: Added.
+ * http/tests/fetch/bodyUsed-worker.html: Added.
+ * http/tests/fetch/bodyUsed.js: Added.
+ * http/tests/fetch/window/body-mixin-expected.txt:
+
+2016-08-31 Youenn Fablet <[email protected]>
+
[Fetch API] Blob type should be correctly set in case of empty body
https://bugs.webkit.org/show_bug.cgi?id=161431
Added: trunk/LayoutTests/http/tests/fetch/bodyUsed-expected.txt (0 => 205251)
--- trunk/LayoutTests/http/tests/fetch/bodyUsed-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/fetch/bodyUsed-expected.txt 2016-08-31 16:36:57 UTC (rev 205251)
@@ -0,0 +1,6 @@
+
+PASS BodyUsedShouldNotBeSetForNullBody
+PASS BodyUsedShouldBeSetForEmptyBody
+PASS BodyUsedShouldBeSetWhenRead
+PASS BodyUsedShouldBeSetWhenCancelled
+
Added: trunk/LayoutTests/http/tests/fetch/bodyUsed-worker-expected.txt (0 => 205251)
--- trunk/LayoutTests/http/tests/fetch/bodyUsed-worker-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/fetch/bodyUsed-worker-expected.txt 2016-08-31 16:36:57 UTC (rev 205251)
@@ -0,0 +1,6 @@
+
+PASS BodyUsedShouldNotBeSetForNullBody
+PASS BodyUsedShouldBeSetForEmptyBody
+PASS BodyUsedShouldBeSetWhenRead
+PASS BodyUsedShouldBeSetWhenCancelled
+
Added: trunk/LayoutTests/http/tests/fetch/bodyUsed-worker.html (0 => 205251)
--- trunk/LayoutTests/http/tests/fetch/bodyUsed-worker.html (rev 0)
+++ trunk/LayoutTests/http/tests/fetch/bodyUsed-worker.html 2016-08-31 16:36:57 UTC (rev 205251)
@@ -0,0 +1,17 @@
+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Response body used tests</title>
+ <meta name="help" href=""
+ <meta name="help" href=""
+ <script src=""
+ <script src=""
+ </head>
+ <body>
+ <script>
+ fetch_tests_from_worker(new Worker("bodyUsed.js"));
+ </script>
+ </body>
+</html>
+
Added: trunk/LayoutTests/http/tests/fetch/bodyUsed.html (0 => 205251)
--- trunk/LayoutTests/http/tests/fetch/bodyUsed.html (rev 0)
+++ trunk/LayoutTests/http/tests/fetch/bodyUsed.html 2016-08-31 16:36:57 UTC (rev 205251)
@@ -0,0 +1,14 @@
+<!doctype html>
+<html>
+ <head>
+ <meta charset="utf-8">
+ <title>Response body used tests</title>
+ <meta name="help" href=""
+ <meta name="help" href=""
+ <script src=""
+ <script src=""
+ </head>
+ <body>
+ <script src=""
+ </body>
+</html>
Added: trunk/LayoutTests/http/tests/fetch/bodyUsed.js (0 => 205251)
--- trunk/LayoutTests/http/tests/fetch/bodyUsed.js (rev 0)
+++ trunk/LayoutTests/http/tests/fetch/bodyUsed.js 2016-08-31 16:36:57 UTC (rev 205251)
@@ -0,0 +1,38 @@
+if (this.document === undefined) {
+ importScripts("/resources/testharness.js");
+}
+
+// Four following tests are taken from Chromium fetch tests, see body-mixin.js file
+test(t => {
+ var req = new Request('/');
+ assert_false(req.bodyUsed);
+ req.text();
+ assert_false(req.bodyUsed);
+}, 'BodyUsedShouldNotBeSetForNullBody');
+
+test(t => {
+ var req = new Request('/', {method: 'POST', body: ''});
+ assert_false(req.bodyUsed);
+ req.text();
+ assert_true(req.bodyUsed);
+}, 'BodyUsedShouldBeSetForEmptyBody');
+
+test(t => {
+ var res = new Response('');
+ assert_false(res.bodyUsed);
+ var reader = res.body.getReader();
+ assert_false(res.bodyUsed);
+ reader.read();
+ assert_true(res.bodyUsed);
+}, 'BodyUsedShouldBeSetWhenRead');
+
+test(t => {
+ var res = new Response('');
+ assert_false(res.bodyUsed);
+ var reader = res.body.getReader();
+ assert_false(res.bodyUsed);
+ reader.cancel();
+ assert_true(res.bodyUsed);
+}, 'BodyUsedShouldBeSetWhenCancelled');
+
+done();
Modified: trunk/Source/WebCore/ChangeLog (205250 => 205251)
--- trunk/Source/WebCore/ChangeLog 2016-08-31 16:36:35 UTC (rev 205250)
+++ trunk/Source/WebCore/ChangeLog 2016-08-31 16:36:57 UTC (rev 205251)
@@ -1,5 +1,40 @@
2016-08-31 Youenn Fablet <[email protected]>
+ [Fetch API] Response bodyUsed should check for its body disturbed state
+ https://bugs.webkit.org/show_bug.cgi?id=161429
+
+ Reviewed by Alex Christensen.
+
+ Test: http/tests/fetch/bodyUsed-worker.html
+
+ Implementing bodyUsed as a JS Builtin.
+ This allows using directly @isReadableStreamDisturbed if response has a body.
+
+ Renaming isDisturbed to isDisturbedOrLocked to better match fetch spec terminology.
+
+ * Modules/fetch/FetchBodyOwner.cpp:
+ (WebCore::FetchBodyOwner::isDisturbedOrLocked): Renaming isDisturbed to isDisturbedOrLocked.
+ (WebCore::FetchBodyOwner::arrayBuffer): Ditto.
+ (WebCore::FetchBodyOwner::blob): Ditto.
+ (WebCore::FetchBodyOwner::formData): Ditto.
+ (WebCore::FetchBodyOwner::json): Ditto.
+ (WebCore::FetchBodyOwner::text): Ditto.
+ (WebCore::FetchBodyOwner::isDisturbed): Ditto.
+ * Modules/fetch/FetchBodyOwner.h:
+ (WebCore::FetchBodyOwner::isDisturbed): Ditto.
+ * Modules/fetch/FetchRequest.cpp:
+ (WebCore::FetchRequest::initializeWith): Ditto.
+ (WebCore::FetchRequest::clone): Ditto.
+ * Modules/fetch/FetchResponse.cpp:
+ (WebCore::FetchResponse::cloneForJS): Ditto.
+ (WebCore::FetchResponse::createReadableStreamSource): Only asserting for isDisturbed.
+ * Modules/fetch/FetchResponse.idl: Marking bodyUsed as JS builtin.
+ * Modules/fetch/FetchResponse.js: Adding bodyUsed.
+ (bodyUsed):
+ (clone):
+
+2016-08-31 Youenn Fablet <[email protected]>
+
[Fetch API] Blob type should be correctly set in case of empty body
https://bugs.webkit.org/show_bug.cgi?id=161431
Modified: trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp (205250 => 205251)
--- trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp 2016-08-31 16:36:35 UTC (rev 205250)
+++ trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.cpp 2016-08-31 16:36:57 UTC (rev 205251)
@@ -58,7 +58,7 @@
ASSERT(!m_blobLoader);
}
-bool FetchBodyOwner::isDisturbed() const
+bool FetchBodyOwner::isDisturbedOrLocked() const
{
if (m_isDisturbed)
return true;
@@ -77,7 +77,7 @@
fulfillPromiseWithArrayBuffer(promise, nullptr, 0);
return;
}
- if (isDisturbed()) {
+ if (isDisturbedOrLocked()) {
promise.reject(TypeError);
return;
}
@@ -91,7 +91,7 @@
promise.resolve(Blob::create(Vector<uint8_t>(), Blob::normalizedContentType(extractMIMETypeFromMediaType(m_body.contentType()))));
return;
}
- if (isDisturbed()) {
+ if (isDisturbedOrLocked()) {
promise.reject(TypeError);
return;
}
@@ -105,7 +105,7 @@
promise.reject(0);
return;
}
- if (isDisturbed()) {
+ if (isDisturbedOrLocked()) {
promise.reject(TypeError);
return;
}
@@ -119,7 +119,7 @@
promise.reject(SYNTAX_ERR);
return;
}
- if (isDisturbed()) {
+ if (isDisturbedOrLocked()) {
promise.reject(TypeError);
return;
}
@@ -133,7 +133,7 @@
promise.resolve(String());
return;
}
- if (isDisturbed()) {
+ if (isDisturbedOrLocked()) {
promise.reject(TypeError);
return;
}
Modified: trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.h (205250 => 205251)
--- trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.h 2016-08-31 16:36:35 UTC (rev 205250)
+++ trunk/Source/WebCore/Modules/fetch/FetchBodyOwner.h 2016-08-31 16:36:57 UTC (rev 205251)
@@ -44,7 +44,7 @@
FetchBodyOwner(ScriptExecutionContext&, FetchBody&&);
// Exposed Body API
- bool isDisturbed() const;
+ bool isDisturbed() const { return m_isDisturbed; };
void arrayBuffer(DeferredWrapper&&);
void blob(DeferredWrapper&&);
@@ -52,6 +52,8 @@
void json(DeferredWrapper&&);
void text(DeferredWrapper&&);
+ bool isDisturbedOrLocked() const;
+
void loadBlob(Blob&, FetchBodyConsumer*);
bool isActive() const { return !!m_blobLoader; }
Modified: trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp (205250 => 205251)
--- trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp 2016-08-31 16:36:35 UTC (rev 205250)
+++ trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp 2016-08-31 16:36:57 UTC (rev 205251)
@@ -243,7 +243,7 @@
FetchHeaders* FetchRequest::initializeWith(FetchRequest& input, const Dictionary& init, ExceptionCode& ec)
{
- if (input.isDisturbed()) {
+ if (input.isDisturbedOrLocked()) {
ec = TypeError;
return nullptr;
}
@@ -308,7 +308,7 @@
RefPtr<FetchRequest> FetchRequest::clone(ScriptExecutionContext& context, ExceptionCode& ec)
{
- if (isDisturbed()) {
+ if (isDisturbedOrLocked()) {
ec = TypeError;
return nullptr;
}
Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp (205250 => 205251)
--- trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp 2016-08-31 16:36:35 UTC (rev 205250)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp 2016-08-31 16:36:57 UTC (rev 205251)
@@ -97,7 +97,7 @@
Ref<FetchResponse> FetchResponse::cloneForJS()
{
ASSERT(scriptExecutionContext());
- ASSERT(!isDisturbed());
+ ASSERT(!isDisturbedOrLocked());
return adoptRef(*new FetchResponse(*scriptExecutionContext(), FetchBody(m_body), FetchHeaders::create(headers()), ResourceResponse(m_response)));
}
@@ -270,7 +270,7 @@
ReadableStreamSource* FetchResponse::createReadableStreamSource()
{
ASSERT(!m_readableStreamSource);
- ASSERT(!isDisturbed());
+ ASSERT(!m_isDisturbed);
if (body().isEmpty())
return nullptr;
Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.idl (205250 => 205251)
--- trunk/Source/WebCore/Modules/fetch/FetchResponse.idl 2016-08-31 16:36:35 UTC (rev 205250)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.idl 2016-08-31 16:36:57 UTC (rev 205251)
@@ -54,7 +54,7 @@
[JSBuiltin] readonly attribute ReadableStream? body;
// Copy of FetchBody IDL as we want to implement some of these as built-ins.
- [ImplementedAs=isDisturbed] readonly attribute boolean bodyUsed;
+ [JSBuiltin] readonly attribute boolean bodyUsed;
[JSBuiltin] Promise arrayBuffer();
[JSBuiltin] Promise blob();
[JSBuiltin] Promise formData();
Modified: trunk/Source/WebCore/Modules/fetch/FetchResponse.js (205250 => 205251)
--- trunk/Source/WebCore/Modules/fetch/FetchResponse.js 2016-08-31 16:36:35 UTC (rev 205250)
+++ trunk/Source/WebCore/Modules/fetch/FetchResponse.js 2016-08-31 16:36:57 UTC (rev 205251)
@@ -60,6 +60,17 @@
return this;
}
+function bodyUsed()
+{
+ if (!(this instanceof @Response))
+ throw @makeGetterTypeError("Response", "bodyUsed");
+
+ if (this.@body)
+ return @isReadableStreamDisturbed(this.@body);
+
+ return @Response.prototype.@isDisturbed.@call(this);
+}
+
function body()
{
if (!(this instanceof @Response))
@@ -83,7 +94,7 @@
if (!(this instanceof @Response))
throw @makeThisTypeError("Response", "clone");
- if (@Response.prototype.@isDisturbed.@call(this))
+ if (@Response.prototype.@isDisturbed.@call(this) || (this.@body && @isReadableStreamLocked(this.@body)))
throw new @TypeError("Cannot clone a disturbed Response");
var cloned = @Response.prototype.@cloneForJS.@call(this);