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

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

Issue 2730943002: XMLHttpRequest: return null upon failing responseArrayBuffer allocation. (Closed)
Patch Set: mirror updated spec, and return |null| for failed allocs 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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 m_eventDispatchRecursionLevel(0), 244 m_eventDispatchRecursionLevel(0),
245 m_async(true), 245 m_async(true),
246 m_includeCredentials(false), 246 m_includeCredentials(false),
247 m_parsedResponse(false), 247 m_parsedResponse(false),
248 m_error(false), 248 m_error(false),
249 m_uploadEventsAllowed(true), 249 m_uploadEventsAllowed(true),
250 m_uploadComplete(false), 250 m_uploadComplete(false),
251 m_sameOriginRequest(true), 251 m_sameOriginRequest(true),
252 m_downloadingToFile(false), 252 m_downloadingToFile(false),
253 m_responseTextOverflow(false), 253 m_responseTextOverflow(false),
254 m_sendFlag(false) {} 254 m_sendFlag(false),
255 m_responseArrayBufferFailure(false) {}
255 256
256 XMLHttpRequest::~XMLHttpRequest() {} 257 XMLHttpRequest::~XMLHttpRequest() {}
257 258
258 Document* XMLHttpRequest::document() const { 259 Document* XMLHttpRequest::document() const {
259 DCHECK(getExecutionContext()->isDocument()); 260 DCHECK(getExecutionContext()->isDocument());
260 return toDocument(getExecutionContext()); 261 return toDocument(getExecutionContext());
261 } 262 }
262 263
263 SecurityOrigin* XMLHttpRequest::getSecurityOrigin() const { 264 SecurityOrigin* XMLHttpRequest::getSecurityOrigin() const {
264 return m_isolatedWorldSecurityOrigin 265 return m_isolatedWorldSecurityOrigin
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 380
380 return m_responseBlob; 381 return m_responseBlob;
381 } 382 }
382 383
383 DOMArrayBuffer* XMLHttpRequest::responseArrayBuffer() { 384 DOMArrayBuffer* XMLHttpRequest::responseArrayBuffer() {
384 DCHECK_EQ(m_responseTypeCode, ResponseTypeArrayBuffer); 385 DCHECK_EQ(m_responseTypeCode, ResponseTypeArrayBuffer);
385 386
386 if (m_error || m_state != kDone) 387 if (m_error || m_state != kDone)
387 return nullptr; 388 return nullptr;
388 389
389 if (!m_responseArrayBuffer) { 390 if (!m_responseArrayBuffer && !m_responseArrayBufferFailure) {
390 if (m_binaryResponseBuilder && m_binaryResponseBuilder->size()) { 391 if (m_binaryResponseBuilder && m_binaryResponseBuilder->size()) {
391 DOMArrayBuffer* buffer = DOMArrayBuffer::createUninitialized( 392 DOMArrayBuffer* buffer = DOMArrayBuffer::createUninitializedOrNull(
392 m_binaryResponseBuilder->size(), 1); 393 m_binaryResponseBuilder->size(), 1);
393 m_binaryResponseBuilder->getAsBytes( 394 if (buffer) {
394 buffer->data(), static_cast<size_t>(buffer->byteLength())); 395 m_binaryResponseBuilder->getAsBytes(
395 m_responseArrayBuffer = buffer; 396 buffer->data(), static_cast<size_t>(buffer->byteLength()));
397 m_responseArrayBuffer = buffer;
398 }
399 // https://xhr.spec.whatwg.org/#arraybuffer-response allows clearing
400 // of the 'received bytes' payload when the response buffer allocation
401 // fails.
396 m_binaryResponseBuilder.clear(); 402 m_binaryResponseBuilder.clear();
403 // Mark allocation as failed; subsequent calls to the accessor must
404 // continue to report |null|.
405 //
406 m_responseArrayBufferFailure = !buffer;
397 } else { 407 } else {
398 m_responseArrayBuffer = DOMArrayBuffer::create(nullptr, 0); 408 m_responseArrayBuffer = DOMArrayBuffer::create(nullptr, 0);
399 } 409 }
400 } 410 }
401 411
402 return m_responseArrayBuffer; 412 return m_responseArrayBuffer;
403 } 413 }
404 414
405 void XMLHttpRequest::setTimeout(unsigned timeout, 415 void XMLHttpRequest::setTimeout(unsigned timeout,
406 ExceptionState& exceptionState) { 416 ExceptionState& exceptionState) {
(...skipping 780 matching lines...) Expand 10 before | Expand all | Expand 10 after
1187 1197
1188 m_responseBlob = nullptr; 1198 m_responseBlob = nullptr;
1189 1199
1190 m_downloadingToFile = false; 1200 m_downloadingToFile = false;
1191 m_lengthDownloadedToFile = 0; 1201 m_lengthDownloadedToFile = 0;
1192 1202
1193 // These variables may referred by the response accessors. So, we can clear 1203 // These variables may referred by the response accessors. So, we can clear
1194 // this only when we clear the response holder variables above. 1204 // this only when we clear the response holder variables above.
1195 m_binaryResponseBuilder.clear(); 1205 m_binaryResponseBuilder.clear();
1196 m_responseArrayBuffer.clear(); 1206 m_responseArrayBuffer.clear();
1207 m_responseArrayBufferFailure = false;
1197 } 1208 }
1198 1209
1199 void XMLHttpRequest::clearRequest() { 1210 void XMLHttpRequest::clearRequest() {
1200 m_requestHeaders.clear(); 1211 m_requestHeaders.clear();
1201 } 1212 }
1202 1213
1203 void XMLHttpRequest::dispatchProgressEvent(const AtomicString& type, 1214 void XMLHttpRequest::dispatchProgressEvent(const AtomicString& type,
1204 long long receivedLength, 1215 long long receivedLength,
1205 long long expectedLength) { 1216 long long expectedLength) {
1206 bool lengthComputable = 1217 bool lengthComputable =
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
1889 visitor->traceWrappers(m_responseDocument); 1900 visitor->traceWrappers(m_responseDocument);
1890 visitor->traceWrappers(m_responseArrayBuffer); 1901 visitor->traceWrappers(m_responseArrayBuffer);
1891 XMLHttpRequestEventTarget::traceWrappers(visitor); 1902 XMLHttpRequestEventTarget::traceWrappers(visitor);
1892 } 1903 }
1893 1904
1894 std::ostream& operator<<(std::ostream& ostream, const XMLHttpRequest* xhr) { 1905 std::ostream& operator<<(std::ostream& ostream, const XMLHttpRequest* xhr) {
1895 return ostream << "XMLHttpRequest " << static_cast<const void*>(xhr); 1906 return ostream << "XMLHttpRequest " << static_cast<const void*>(xhr);
1896 } 1907 }
1897 1908
1898 } // namespace blink 1909 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698