Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: third_party/WebKit/Source/core/xmlhttprequest/XMLHttpRequest.cpp

Issue 2748933003: XMLHttpRequest: return null upon failing responseArrayBuffer allocation. (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2005-2007 Alexey Proskuryakov <ap@webkit.org> 3 * Copyright (C) 2005-2007 Alexey Proskuryakov <ap@webkit.org>
4 * Copyright (C) 2007, 2008 Julien Chaffraix <jchaffraix@webkit.org> 4 * Copyright (C) 2007, 2008 Julien Chaffraix <jchaffraix@webkit.org>
5 * Copyright (C) 2008, 2011 Google Inc. All rights reserved. 5 * Copyright (C) 2008, 2011 Google Inc. All rights reserved.
6 * Copyright (C) 2012 Intel Corporation 6 * Copyright (C) 2012 Intel Corporation
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public 9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 m_eventDispatchRecursionLevel(0), 243 m_eventDispatchRecursionLevel(0),
244 m_async(true), 244 m_async(true),
245 m_includeCredentials(false), 245 m_includeCredentials(false),
246 m_parsedResponse(false), 246 m_parsedResponse(false),
247 m_error(false), 247 m_error(false),
248 m_uploadEventsAllowed(true), 248 m_uploadEventsAllowed(true),
249 m_uploadComplete(false), 249 m_uploadComplete(false),
250 m_sameOriginRequest(true), 250 m_sameOriginRequest(true),
251 m_downloadingToFile(false), 251 m_downloadingToFile(false),
252 m_responseTextOverflow(false), 252 m_responseTextOverflow(false),
253 m_sendFlag(false) {} 253 m_sendFlag(false),
254 m_responseArrayBufferFailure(false) {}
254 255
255 XMLHttpRequest::~XMLHttpRequest() {} 256 XMLHttpRequest::~XMLHttpRequest() {}
256 257
257 Document* XMLHttpRequest::document() const { 258 Document* XMLHttpRequest::document() const {
258 DCHECK(getExecutionContext()->isDocument()); 259 DCHECK(getExecutionContext()->isDocument());
259 return toDocument(getExecutionContext()); 260 return toDocument(getExecutionContext());
260 } 261 }
261 262
262 SecurityOrigin* XMLHttpRequest::getSecurityOrigin() const { 263 SecurityOrigin* XMLHttpRequest::getSecurityOrigin() const {
263 return m_isolatedWorldSecurityOrigin 264 return m_isolatedWorldSecurityOrigin
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 379
379 return m_responseBlob; 380 return m_responseBlob;
380 } 381 }
381 382
382 DOMArrayBuffer* XMLHttpRequest::responseArrayBuffer() { 383 DOMArrayBuffer* XMLHttpRequest::responseArrayBuffer() {
383 DCHECK_EQ(m_responseTypeCode, ResponseTypeArrayBuffer); 384 DCHECK_EQ(m_responseTypeCode, ResponseTypeArrayBuffer);
384 385
385 if (m_error || m_state != kDone) 386 if (m_error || m_state != kDone)
386 return nullptr; 387 return nullptr;
387 388
388 if (!m_responseArrayBuffer) { 389 if (!m_responseArrayBuffer && !m_responseArrayBufferFailure) {
389 if (m_binaryResponseBuilder && m_binaryResponseBuilder->size()) { 390 if (m_binaryResponseBuilder && m_binaryResponseBuilder->size()) {
390 DOMArrayBuffer* buffer = DOMArrayBuffer::createUninitialized( 391 DOMArrayBuffer* buffer = DOMArrayBuffer::createUninitializedOrNull(
391 m_binaryResponseBuilder->size(), 1); 392 m_binaryResponseBuilder->size(), 1);
392 m_binaryResponseBuilder->getAsBytes( 393 if (buffer) {
393 buffer->data(), static_cast<size_t>(buffer->byteLength())); 394 m_binaryResponseBuilder->getAsBytes(
394 m_responseArrayBuffer = buffer; 395 buffer->data(), static_cast<size_t>(buffer->byteLength()));
396 m_responseArrayBuffer = buffer;
397 }
398 // https://xhr.spec.whatwg.org/#arraybuffer-response allows clearing
399 // of the 'received bytes' payload when the response buffer allocation
400 // fails.
395 m_binaryResponseBuilder.clear(); 401 m_binaryResponseBuilder.clear();
402 // Mark allocation as failed; subsequent calls to the accessor must
403 // continue to report |null|.
404 //
405 m_responseArrayBufferFailure = !buffer;
396 } else { 406 } else {
397 m_responseArrayBuffer = DOMArrayBuffer::create(nullptr, 0); 407 m_responseArrayBuffer = DOMArrayBuffer::create(nullptr, 0);
398 } 408 }
399 } 409 }
400 410
401 return m_responseArrayBuffer; 411 return m_responseArrayBuffer;
402 } 412 }
403 413
404 void XMLHttpRequest::setTimeout(unsigned timeout, 414 void XMLHttpRequest::setTimeout(unsigned timeout,
405 ExceptionState& exceptionState) { 415 ExceptionState& exceptionState) {
(...skipping 762 matching lines...) Expand 10 before | Expand all | Expand 10 after
1168 1178
1169 m_responseBlob = nullptr; 1179 m_responseBlob = nullptr;
1170 1180
1171 m_downloadingToFile = false; 1181 m_downloadingToFile = false;
1172 m_lengthDownloadedToFile = 0; 1182 m_lengthDownloadedToFile = 0;
1173 1183
1174 // These variables may referred by the response accessors. So, we can clear 1184 // These variables may referred by the response accessors. So, we can clear
1175 // this only when we clear the response holder variables above. 1185 // this only when we clear the response holder variables above.
1176 m_binaryResponseBuilder.clear(); 1186 m_binaryResponseBuilder.clear();
1177 m_responseArrayBuffer.clear(); 1187 m_responseArrayBuffer.clear();
1188 m_responseArrayBufferFailure = false;
1178 } 1189 }
1179 1190
1180 void XMLHttpRequest::clearRequest() { 1191 void XMLHttpRequest::clearRequest() {
1181 m_requestHeaders.clear(); 1192 m_requestHeaders.clear();
1182 } 1193 }
1183 1194
1184 void XMLHttpRequest::dispatchProgressEvent(const AtomicString& type, 1195 void XMLHttpRequest::dispatchProgressEvent(const AtomicString& type,
1185 long long receivedLength, 1196 long long receivedLength,
1186 long long expectedLength) { 1197 long long expectedLength) {
1187 bool lengthComputable = 1198 bool lengthComputable =
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after
1856 visitor->traceWrappers(m_responseDocument); 1867 visitor->traceWrappers(m_responseDocument);
1857 visitor->traceWrappers(m_responseArrayBuffer); 1868 visitor->traceWrappers(m_responseArrayBuffer);
1858 XMLHttpRequestEventTarget::traceWrappers(visitor); 1869 XMLHttpRequestEventTarget::traceWrappers(visitor);
1859 } 1870 }
1860 1871
1861 std::ostream& operator<<(std::ostream& ostream, const XMLHttpRequest* xhr) { 1872 std::ostream& operator<<(std::ostream& ostream, const XMLHttpRequest* xhr) {
1862 return ostream << "XMLHttpRequest " << static_cast<const void*>(xhr); 1873 return ostream << "XMLHttpRequest " << static_cast<const void*>(xhr);
1863 } 1874 }
1864 1875
1865 } // namespace blink 1876 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698