Changeset 205115 in webkit
- Timestamp:
- Aug 29, 2016 2:18:06 AM (8 years ago)
- Location:
- trunk
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/imported/w3c/ChangeLog
r205113 r205115 1 2016-08-29 Youenn Fablet <youenn@apple.com> 2 3 [Fetch API] Add support for BufferSource bodies 4 https://bugs.webkit.org/show_bug.cgi?id=161087 5 6 Reviewed by Darin Adler. 7 8 * web-platform-tests/fetch/api/basic/request-headers-expected.txt: 9 * web-platform-tests/fetch/api/basic/request-headers-worker-expected.txt: 10 * web-platform-tests/fetch/api/basic/request-headers.js: 11 (checkContentType): 12 (requestHeaders): Change the order of the header checks so that passing headers are checked first. 13 * web-platform-tests/fetch/api/request/request-consume-expected.txt: 14 * web-platform-tests/fetch/api/request/request-consume.html: 15 * web-platform-tests/fetch/api/response/response-consume-stream-expected.txt: 16 * web-platform-tests/fetch/api/response/response-consume-stream.html: 17 1 18 2016-08-29 Youenn Fablet <youenn@apple.com> 2 19 -
trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers-expected.txt
r204225 r205115 1 1 2 2 FAIL Fetch with GET assert_equals: Request should have header origin: http://localhost:8800 expected (string) "http://localhost:8800" but got (object) null 3 FAIL Fetch with HEAD assert_equals: Request should have header content-length: null expected (object) null but got (string) "0"3 FAIL Fetch with HEAD assert_equals: Request should have header origin: http://localhost:8800 expected (string) "http://localhost:8800" but got (object) null 4 4 PASS Fetch with PUT without body 5 5 PASS Fetch with PUT with body 6 6 PASS Fetch with POST without body 7 7 PASS Fetch with POST with text body 8 FAIL Fetch with POST with FormData body promise_test: Unhandled rejection with value: object "TypeError: Uploading FormData is not yet implemented" 8 PASS Fetch with POST with FormData body 9 9 FAIL Fetch with POST with Blob body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded" 10 FAIL Fetch with POST with ArrayBuffer body promise_test: Unhandled rejection with value: object "TypeError: Type error" 10 FAIL Fetch with POST with ArrayBuffer body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded" 11 FAIL Fetch with POST with Uint8Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded" 12 FAIL Fetch with POST with Int8Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded" 13 FAIL Fetch with POST with Float32Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded" 14 FAIL Fetch with POST with Float64Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded" 15 FAIL Fetch with POST with DataView body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded" 11 16 PASS Fetch with POST with Blob body with mime type 12 17 FAIL Fetch with Chicken assert_equals: Request should have header content-length: null expected (object) null but got (string) "0" -
trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers-worker-expected.txt
r204225 r205115 1 1 2 2 FAIL Fetch with GET assert_equals: Request should have header origin: http://localhost:8800 expected (string) "http://localhost:8800" but got (object) null 3 FAIL Fetch with HEAD assert_equals: Request should have header content-length: null expected (object) null but got (string) "0"3 FAIL Fetch with HEAD assert_equals: Request should have header origin: http://localhost:8800 expected (string) "http://localhost:8800" but got (object) null 4 4 PASS Fetch with PUT without body 5 5 PASS Fetch with PUT with body … … 7 7 PASS Fetch with POST with text body 8 8 FAIL Fetch with POST with Blob body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded" 9 FAIL Fetch with POST with ArrayBuffer body promise_test: Unhandled rejection with value: object "TypeError: Type error" 9 FAIL Fetch with POST with ArrayBuffer body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded" 10 FAIL Fetch with POST with Uint8Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded" 11 FAIL Fetch with POST with Int8Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded" 12 FAIL Fetch with POST with Float32Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded" 13 FAIL Fetch with POST with Float64Array body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded" 14 FAIL Fetch with POST with DataView body assert_equals: Request should have header content-type: null expected (object) null but got (string) "application/x-www-form-urlencoded" 10 15 PASS Fetch with POST with Blob body with mime type 11 16 FAIL Fetch with Chicken assert_equals: Request should have header content-length: null expected (object) null but got (string) "0" -
trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/basic/request-headers.js
r204225 r205115 12 12 13 13 var expectedContentType = "text/plain;charset=UTF-8"; 14 if(body === null || body instanceof ArrayBuffer )14 if(body === null || body instanceof ArrayBuffer || body.buffer instanceof ArrayBuffer) 15 15 expectedContentType = null; 16 16 else if (body instanceof Blob) … … 29 29 assert_equals(resp.status, 200, "HTTP status is 200"); 30 30 assert_equals(resp.type , "basic", "Response's type is basic"); 31 checkContentType(resp.headers.get("x-request-content-type"), body);32 if (expectedContentLength !== undefined)33 assert_equals(resp.headers.get("x-request-content-length") , expectedContentLength, "Request should have header content-length: " + expectedContentLength);34 31 assert_true(resp.headers.has("x-request-user-agent"), "Request has header user-agent"); 35 32 assert_false(resp.headers.has("accept-charset"), "Request has header accept-charset"); 36 33 assert_equals(resp.headers.get("x-request-origin") , expectedOrigin, "Request should have header origin: " + expectedOrigin); 34 if (expectedContentLength !== undefined) 35 assert_equals(resp.headers.get("x-request-content-length") , expectedContentLength, "Request should have header content-length: " + expectedContentLength); 36 checkContentType(resp.headers.get("x-request-content-type"), body); 37 37 }); 38 38 }, desc); … … 51 51 requestHeaders("Fetch with POST with Blob body", url, "POST", new Blob(["Test"]), location.origin, "4"); 52 52 requestHeaders("Fetch with POST with ArrayBuffer body", url, "POST", new ArrayBuffer(4), location.origin, "4"); 53 requestHeaders("Fetch with POST with Uint8Array body", url, "POST", new Uint8Array(4), location.origin, "4"); 54 requestHeaders("Fetch with POST with Int8Array body", url, "POST", new Int8Array(4), location.origin, "4"); 55 requestHeaders("Fetch with POST with Float32Array body", url, "POST", new Float32Array(1), location.origin, "4"); 56 requestHeaders("Fetch with POST with Float64Array body", url, "POST", new Float64Array(1), location.origin, "8"); 57 requestHeaders("Fetch with POST with DataView body", url, "POST", new DataView(new ArrayBuffer(8), 0, 4), location.origin, "4"); 53 58 requestHeaders("Fetch with POST with Blob body with mime type", url, "POST", new Blob(["Test"], { type: "text/maybe" }), location.origin, "4"); 54 59 requestHeaders("Fetch with Chicken", url, "Chicken", null, location.origin, null); -
trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume-expected.txt
r204171 r205115 1 1 2 PASS Consume request's body as text 3 PASS Consume request's body as blob 4 PASS Consume request's body as arrayBuffer 5 PASS Consume request's body as json 6 FAIL Consume request's body as formData promise_test: Unhandled rejection with value: undefined 2 PASS Consume String request's body as text 3 PASS Consume String request's body as blob 4 PASS Consume String request's body as arrayBuffer 5 PASS Consume String request's body as JSON 6 PASS Consume ArrayBuffer request's body as text 7 PASS Consume ArrayBuffer request's body as blob 8 PASS Consume ArrayBuffer request's body as arrayBuffer 9 PASS Consume ArrayBuffer request's body as JSON 10 PASS Consume Uint8Array request's body as text 11 PASS Consume Uint8Array request's body as blob 12 PASS Consume Uint8Array request's body as arrayBuffer 13 PASS Consume Uint8Array request's body as JSON 14 PASS Consume Int8Array request's body as text 15 PASS Consume Int8Array request's body as blob 16 PASS Consume Int8Array request's body as arrayBuffer 17 PASS Consume Int8Array request's body as JSON 18 PASS Consume Float32Array request's body as text 19 PASS Consume Float32Array request's body as blob 20 PASS Consume Float32Array request's body as arrayBuffer 21 PASS Consume Float32Array request's body as JSON 22 PASS Consume DataView request's body as text 23 PASS Consume DataView request's body as blob 24 PASS Consume DataView request's body as arrayBuffer 25 PASS Consume DataView request's body as JSON 26 FAIL Consume FormData request's body as FormData promise_test: Unhandled rejection with value: undefined 7 27 PASS Consume blob response's body as blob 8 28 PASS Consume blob response's body as text -
trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-consume.html
r205076 r205115 14 14 <script> 15 15 function checkBodyText(request, expectedBody) { 16 return request.text().then( 16 return request.text().then(function(bodyAsText) { 17 17 assert_equals(bodyAsText, expectedBody, "Retrieve and verify request's body"); 18 18 assert_true(request.bodyUsed, "body as text: bodyUsed turned true"); … … 64 64 } 65 65 66 function checkRequestBody(body, bodyType, checkFunction) {66 function checkRequestBody(body, expected, bodyType) { 67 67 promise_test(function(test) { 68 68 var request = new Request("", {"method": "POST", "body": body, "headers": [["Content-Type", "text/PLAIN"]] }); 69 69 assert_false(request.bodyUsed, "bodyUsed is false at init"); 70 return checkFunction(request, body); 71 }, "Consume request's body as " + bodyType); 70 return checkBodyText(request, expected); 71 }, "Consume " + bodyType + " request's body as text"); 72 promise_test(function(test) { 73 var request = new Request("", {"method": "POST", "body": body }); 74 assert_false(request.bodyUsed, "bodyUsed is false at init"); 75 return checkBodyBlob(request, expected); 76 }, "Consume " + bodyType + " request's body as blob"); 77 promise_test(function(test) { 78 var request = new Request("", {"method": "POST", "body": body }); 79 assert_false(request.bodyUsed, "bodyUsed is false at init"); 80 return checkBodyArrayBuffer(request, expected); 81 }, "Consume " + bodyType + " request's body as arrayBuffer"); 82 promise_test(function(test) { 83 var request = new Request("", {"method": "POST", "body": body }); 84 assert_false(request.bodyUsed, "bodyUsed is false at init"); 85 return checkBodyJSON(request, expected); 86 }, "Consume " + bodyType + " request's body as JSON"); 72 87 } 73 88 74 var formData = new FormData();75 formData.append("name", "value")76 89 var textData = JSON.stringify("This is response's body"); 77 90 var blob = new Blob([textData], { "type" : "text/plain" }); 78 91 79 checkRequestBody(textData, "text", checkBodyText); 80 checkRequestBody(textData, "blob", function(request, body) { checkBodyBlob(request, body, true); }); 81 checkRequestBody(textData, "arrayBuffer", checkBodyArrayBuffer); 82 checkRequestBody(textData, "json", checkBodyJSON); 83 checkRequestBody(formData, "formData", checkBodyFormData); 92 checkRequestBody(textData, textData, "String"); 93 94 var string = "\"123456\""; 95 function getArrayBuffer() { 96 var arrayBuffer = new ArrayBuffer(8); 97 var int8Array = new Int8Array(arrayBuffer); 98 for (var cptr = 0; cptr < 8; cptr++) 99 int8Array[cptr] = string.charCodeAt(cptr); 100 return arrayBuffer; 101 } 102 103 function getArrayBufferWithZeros() { 104 var arrayBuffer = new ArrayBuffer(10); 105 var int8Array = new Int8Array(arrayBuffer); 106 for (var cptr = 0; cptr < 8; cptr++) 107 int8Array[cptr + 1] = string.charCodeAt(cptr); 108 return arrayBuffer; 109 } 110 111 checkRequestBody(getArrayBuffer(), string, "ArrayBuffer"); 112 checkRequestBody(new Uint8Array(getArrayBuffer()), string, "Uint8Array"); 113 checkRequestBody(new Int8Array(getArrayBufferWithZeros(), 1, 8), string, "Int8Array"); 114 checkRequestBody(new Float32Array(getArrayBuffer()), string, "Float32Array"); 115 checkRequestBody(new DataView(getArrayBufferWithZeros(), 1, 8), string, "DataView"); 116 117 promise_test(function(test) { 118 var formData = new FormData(); 119 formData.append("name", "value") 120 var request = new Request("", {"method": "POST", "body": formData }); 121 assert_false(request.bodyUsed, "bodyUsed is false at init"); 122 return checkBodyFormData(request, formData); 123 }, "Consume FormData request's body as FormData"); 84 124 85 125 function checkBlobResponseBody(blobBody, blobData, bodyType, checkFunction) { -
trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-stream-expected.txt
r203408 r205115 4 4 PASS Read blob response's body as readableStream 5 5 PASS Read text response's body as readableStream 6 PASS Read array buffer response's body as readableStream 6 7 FAIL Read form data response's body as readableStream promise_test: Unhandled rejection with value: "not implemented" 7 8 PASS Getting an error Response stream -
trunk/LayoutTests/imported/w3c/web-platform-tests/fetch/api/response/response-consume-stream.html
r202471 r205115 41 41 42 42 promise_test(function(test) { 43 var arrayBuffer = new ArrayBuffer(textData.length); 44 var int8Array = new Int8Array(arrayBuffer); 45 for (var cptr = 0; cptr < textData.length; cptr++) 46 int8Array[cptr] = textData.charCodeAt(cptr); 47 48 return validateStreamFromString(new Response(arrayBuffer).body.getReader(), textData); 49 }, "Read array buffer response's body as readableStream"); 50 51 promise_test(function(test) { 43 52 var response = new Response(formData); 44 53 return validateStreamFromString(response.body.getReader(), "name=value"); -
trunk/Source/WebCore/ChangeLog
r205114 r205115 1 2016-08-29 Youenn Fablet <youenn@apple.com> 2 3 [Fetch API] Add support for BufferSource bodies 4 https://bugs.webkit.org/show_bug.cgi?id=161087 5 6 Reviewed by Darin Adler. 7 8 Covered by updated tests. 9 10 Added support for ArrayBuffer, ArrayBufferView and FormData upload. 11 Added support for consuming ArrayBufferView. 12 13 To support FormData upload, FetchBOdy is now storing a FormData computed from the DOMFormData passed to the constructor. 14 This allows setting the content-type for FormData correctly with the boundary parameter. 15 16 * Modules/fetch/FetchBody.cpp: 17 (WebCore::FetchBody::bodyForInternalRequest): Adding support for FormData upload. 18 (WebCore::FetchBody::FetchBody): Adding ArrayBuffer and ArrayBufferView constructors. 19 (WebCore::FetchBody::extract): Extracting in case of BufferSource (i.e. ArrayBuffer or ArrayBufferView) and FormData. 20 (WebCore::FetchBody::consume): Adding support to consume ArrayBufferView. 21 (WebCore::FetchBody::consumeAsStream): Adding support to consume ArrayBufferView as a stream. 22 Cloned the ArrayBuffer before enqueuing it in the stream. 23 (WebCore::FetchBody::consumeArrayBuffer): Cleaning m_data after being consumed. 24 (WebCore::FetchBody::consumeArrayBufferView): Adding support to consume ArrayBufferView. 25 (WebCore::FetchBody::consumeText): Cleaning m_text after being consumed. 26 (WebCore::FetchBody::consumeBlob): Ditto for m_blob. 27 (WebCore::FetchBody::bodyForInternalRequest): Adding support for ArrayBuffer and ArrayBufferView upload. 28 * Modules/fetch/FetchBody.h: 29 * Modules/fetch/FetchRequest.cpp: 30 (WebCore::FetchRequest::internalRequest): Passing ScriptExecutionContext as this is needed for FormData upload. 31 (WebCore::FetchRequest::setBody): Ditto. 32 * Modules/fetch/FetchResponse.cpp: 33 (WebCore::FetchResponse::initializeWith): Ditto. 34 (WebCore::FetchResponse::fetch): Removing FormData upload rejection check. 35 1 36 2016-08-26 Sergio Villar Senin <svillar@igalia.com> 2 37 -
trunk/Source/WebCore/Modules/fetch/FetchBody.cpp
r205076 r205115 43 43 #include "JSReadableStream.h" 44 44 #include "ReadableStreamSource.h" 45 #include <runtime/ArrayBufferView.h> 45 46 46 47 namespace WebCore { … … 53 54 } 54 55 55 FetchBody::FetchBody( Ref<DOMFormData>&& formData)56 FetchBody::FetchBody(DOMFormData& formData, Document& document) 56 57 : m_type(Type::FormData) 57 58 , m_contentType(ASCIILiteral("multipart/form-data")) 58 , m_formData(WTFMove(formData)) 59 { 60 // FIXME: Handle the boundary parameter of multipart/form-data MIME type.59 { 60 m_formData = FormData::createMultiPart(formData, formData.encoding(), &document); 61 m_contentType = makeString("multipart/form-data;boundary=", m_formData->boundary().data()); 61 62 } 62 63 … … 68 69 } 69 70 70 FetchBody FetchBody::extract(JSC::ExecState& state, JSC::JSValue value) 71 FetchBody::FetchBody(Ref<ArrayBuffer>&& data) 72 : m_type(Type::ArrayBuffer) 73 , m_data(WTFMove(data)) 74 { 75 } 76 77 FetchBody::FetchBody(Ref<ArrayBufferView>&& dataView) 78 : m_type(Type::ArrayBufferView) 79 , m_dataView(WTFMove(dataView)) 80 { 81 } 82 83 FetchBody FetchBody::extract(ScriptExecutionContext& context, JSC::ExecState& state, JSC::JSValue value) 71 84 { 72 85 if (value.inherits(JSBlob::info())) 73 86 return FetchBody(*JSBlob::toWrapped(value)); 74 if (value.inherits(JSDOMFormData::info())) 75 return FetchBody(*JSDOMFormData::toWrapped(value)); 87 if (value.inherits(JSDOMFormData::info())) { 88 ASSERT(!context.isWorkerGlobalScope()); 89 return FetchBody(*JSDOMFormData::toWrapped(value), static_cast<Document&>(context)); 90 } 76 91 if (value.isString()) 77 92 return FetchBody(value.toWTFString(&state)); 78 93 if (value.inherits(JSReadableStream::info())) 79 94 return { Type::ReadableStream }; 80 // FIXME: Implement BufferSource extraction. 95 if (value.inherits(JSC::JSArrayBuffer::info())) { 96 ArrayBuffer* data = toArrayBuffer(value); 97 ASSERT(data); 98 return { *data }; 99 } 100 if (value.inherits(JSC::JSArrayBufferView::info())) { 101 RefPtr<JSC::ArrayBufferView> data = toArrayBufferView(value); 102 ASSERT(data); 103 return { data.releaseNonNull() }; 104 } 81 105 return { }; 82 106 } … … 151 175 consumeArrayBuffer(promise); 152 176 return; 177 case Type::ArrayBufferView: 178 consumeArrayBufferView(promise); 179 return; 153 180 case Type::Text: 154 181 consumeText(promise); … … 163 190 m_consumer.resolve(promise); 164 191 return; 192 case Type::FormData: 193 // FIXME: Support consuming FormData. 194 promise.reject(0); 195 return; 165 196 default: 166 // FIXME: Support other types. 167 promise.reject(0); 197 ASSERT_NOT_REACHED(); 168 198 } 169 199 } … … 181 211 case Type::ArrayBuffer: 182 212 ASSERT(m_data); 183 closeStream = source.enqueue(RefPtr<JSC::ArrayBuffer>(m_data)); 184 break; 213 closeStream = source.enqueue(ArrayBuffer::tryCreate(m_data->data(), m_data->byteLength())); 214 m_data = nullptr; 215 break; 216 case Type::ArrayBufferView: { 217 ASSERT(m_dataView); 218 closeStream = source.enqueue(ArrayBuffer::tryCreate(m_dataView->baseAddress(), m_dataView->byteLength())); 219 m_dataView = nullptr; 220 break; 221 } 185 222 case Type::Text: { 186 223 Vector<uint8_t> data = extractFromText(); 187 224 closeStream = source.enqueue(ArrayBuffer::tryCreate(data.data(), data.size())); 225 m_text = { }; 188 226 break; 189 227 } … … 191 229 ASSERT(m_blob); 192 230 owner.loadBlob(*m_blob, nullptr); 231 m_blob = nullptr; 193 232 break; 194 233 case Type::None: … … 210 249 void FetchBody::consumeArrayBuffer(DeferredWrapper& promise) 211 250 { 251 ASSERT(m_data); 212 252 m_consumer.resolveWithData(promise, static_cast<const uint8_t*>(m_data->data()), m_data->byteLength()); 253 m_data = nullptr; 254 } 255 256 void FetchBody::consumeArrayBufferView(DeferredWrapper& promise) 257 { 258 ASSERT(m_dataView); 259 m_consumer.resolveWithData(promise, static_cast<const uint8_t*>(m_dataView->baseAddress()), m_dataView->byteLength()); 260 m_dataView = nullptr; 213 261 } 214 262 … … 217 265 Vector<uint8_t> data = extractFromText(); 218 266 m_consumer.resolveWithData(promise, data.data(), data.size()); 267 m_text = { }; 219 268 } 220 269 … … 225 274 m_consumePromise = WTFMove(promise); 226 275 owner.loadBlob(*m_blob, &m_consumer); 276 m_blob = nullptr; 227 277 } 228 278 … … 254 304 } 255 305 256 RefPtr<FormData> FetchBody::bodyForInternalRequest() const 257 { 258 if (m_type == Type::None) 306 RefPtr<FormData> FetchBody::bodyForInternalRequest(ScriptExecutionContext& context) const 307 { 308 switch (m_type) { 309 case Type::None: 259 310 return nullptr; 260 if (m_type == Type::Text)311 case Type::Text: 261 312 return FormData::create(UTF8Encoding().encode(m_text, EntitiesForUnencodables)); 262 if (m_type == Type::Blob) { 313 case Type::Blob: { 314 ASSERT(m_blob); 263 315 RefPtr<FormData> body = FormData::create(); 264 316 body->appendBlob(m_blob->url()); 265 317 return body; 266 318 } 267 ASSERT_NOT_REACHED(); 268 return nullptr; 319 case Type::ArrayBuffer: 320 ASSERT(m_data); 321 return FormData::create(m_data->data(), m_data->byteLength()); 322 case Type::ArrayBufferView: 323 ASSERT(m_dataView); 324 return FormData::create(m_dataView->baseAddress(), m_dataView->byteLength()); 325 case Type::FormData: { 326 ASSERT(m_formData); 327 ASSERT(!context.isWorkerGlobalScope()); 328 auto body = m_formData; 329 body->generateFiles(static_cast<Document*>(&context)); 330 return body; 331 } 332 default: 333 ASSERT_NOT_REACHED(); 334 return nullptr; 335 } 269 336 } 270 337 -
trunk/Source/WebCore/Modules/fetch/FetchBody.h
r205076 r205115 33 33 34 34 #include "Blob.h" 35 #include "DOMFormData.h"36 35 #include "FetchBodyConsumer.h" 37 36 #include "FetchLoader.h" 37 #include "FormData.h" 38 38 #include "JSDOMPromise.h" 39 39 … … 45 45 namespace WebCore { 46 46 47 class DOMFormData; 47 48 class FetchBodyOwner; 48 49 class FetchHeaders; 49 50 class FetchResponseSource; 50 class FormData;51 class ScriptExecutionContext; 51 52 52 53 class FetchBody { … … 68 69 String contentType() const { return m_contentType; } 69 70 70 static FetchBody extract( JSC::ExecState&, JSC::JSValue);71 static FetchBody extract(ScriptExecutionContext&, JSC::ExecState&, JSC::JSValue); 71 72 static FetchBody extractFromBody(FetchBody*); 72 73 static FetchBody loadingBody() { return { Type::Loading }; } … … 76 77 void loadingSucceeded(); 77 78 78 RefPtr<FormData> bodyForInternalRequest( ) const;79 RefPtr<FormData> bodyForInternalRequest(ScriptExecutionContext&) const; 79 80 80 enum class Type { None, ArrayBuffer, Blob, FormData, Text, Loading, Loaded, ReadableStream };81 enum class Type { None, ArrayBuffer, ArrayBufferView, Blob, FormData, Text, Loading, Loaded, ReadableStream }; 81 82 Type type() const { return m_type; } 82 83 … … 87 88 private: 88 89 FetchBody(Ref<Blob>&&); 89 FetchBody(Ref<DOMFormData>&&); 90 FetchBody(Ref<ArrayBuffer>&&); 91 FetchBody(Ref<ArrayBufferView>&&); 92 FetchBody(DOMFormData&, Document&); 90 93 FetchBody(String&&); 91 94 FetchBody(Type type) : m_type(type) { } … … 95 98 Vector<uint8_t> extractFromText() const; 96 99 void consumeArrayBuffer(DeferredWrapper&); 100 void consumeArrayBufferView(DeferredWrapper&); 97 101 void consumeText(DeferredWrapper&); 98 102 void consumeBlob(FetchBodyOwner&, DeferredWrapper&&); … … 101 105 String m_contentType; 102 106 103 // FIXME: Add support for BufferSource andURLSearchParams.107 // FIXME: Add support for URLSearchParams. 104 108 RefPtr<Blob> m_blob; 105 RefPtr< DOMFormData> m_formData;109 RefPtr<FormData> m_formData; 106 110 RefPtr<ArrayBuffer> m_data; 111 RefPtr<ArrayBufferView> m_dataView; 107 112 String m_text; 108 113 -
trunk/Source/WebCore/Modules/fetch/FetchRequest.cpp
r205076 r205115 258 258 { 259 259 if (!body.isNull()) { 260 m_body = FetchBody::extract(execState, body); 260 ASSERT(scriptExecutionContext()); 261 m_body = FetchBody::extract(*scriptExecutionContext(), execState, body); 261 262 if (m_body.type() == FetchBody::Type::None) { 262 263 ec = TypeError; … … 293 294 ResourceRequest FetchRequest::internalRequest() const 294 295 { 296 ASSERT(scriptExecutionContext()); 297 295 298 ResourceRequest request = m_internalRequest.request; 296 299 request.setHTTPHeaderFields(m_headers->internalHeaders()); 297 request.setHTTPBody(body().bodyForInternalRequest( ));300 request.setHTTPBody(body().bodyForInternalRequest(*scriptExecutionContext())); 298 301 299 302 // FIXME: Support no-referrer and client. Ensure this case-sensitive comparison is ok. -
trunk/Source/WebCore/Modules/fetch/FetchResponse.cpp
r205110 r205115 83 83 void FetchResponse::initializeWith(JSC::ExecState& execState, JSC::JSValue body) 84 84 { 85 m_body = FetchBody::extract(execState, body); 85 ASSERT(scriptExecutionContext()); 86 m_body = FetchBody::extract(*scriptExecutionContext(), execState, body); 86 87 m_body.updateContentType(m_headers); 87 88 } … … 105 106 auto response = adoptRef(*new FetchResponse(context, FetchBody::loadingBody(), FetchHeaders::create(FetchHeaders::Guard::Immutable), { })); 106 107 107 // FIXME: Implement form data upload.108 if (request.bodyType() == FetchBody::Type::FormData) {109 promise.reject(TypeError, "Uploading FormData is not yet implemented");110 return;111 }112 108 // Setting pending activity until BodyLoader didFail or didSucceed callback is called. 113 109 response->setPendingActivity(response.ptr());
Note: See TracChangeset
for help on using the changeset viewer.