Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "modules/fetch/Response.h" | 6 #include "modules/fetch/Response.h" |
| 7 | 7 |
| 8 #include "bindings/core/v8/Dictionary.h" | 8 #include "bindings/core/v8/Dictionary.h" |
| 9 #include "bindings/core/v8/ExceptionState.h" | 9 #include "bindings/core/v8/ExceptionState.h" |
| 10 #include "core/dom/DOMArrayBuffer.h" | 10 #include "core/dom/DOMArrayBuffer.h" |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 146 const long long length = blobData->length(); | 146 const long long length = blobData->length(); |
| 147 Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), len gth)); | 147 Blob* blob = Blob::create(BlobDataHandle::create(blobData.release(), len gth)); |
| 148 return create(context, blob, ResponseInit(responseInit, exceptionState), exceptionState); | 148 return create(context, blob, ResponseInit(responseInit, exceptionState), exceptionState); |
| 149 } | 149 } |
| 150 ASSERT_NOT_REACHED(); | 150 ASSERT_NOT_REACHED(); |
| 151 return nullptr; | 151 return nullptr; |
| 152 } | 152 } |
| 153 | 153 |
| 154 Response* Response::create(ExecutionContext* context, Blob* body, const Response Init& responseInit, ExceptionState& exceptionState) | 154 Response* Response::create(ExecutionContext* context, Blob* body, const Response Init& responseInit, ExceptionState& exceptionState) |
| 155 { | 155 { |
| 156 unsigned short status = responseInit.status; | |
| 157 | |
| 156 // "1. If |init|'s status member is not in the range 200 to 599, throw a | 158 // "1. If |init|'s status member is not in the range 200 to 599, throw a |
| 157 // RangeError." | 159 // RangeError." |
| 158 if (responseInit.status < 200 || 599 < responseInit.status) { | 160 if (status < 200 || 599 < status) { |
| 159 exceptionState.throwRangeError("Invalid status"); | 161 exceptionState.throwRangeError("Invalid status"); |
|
philipj_slow
2015/07/27 11:36:08
ExceptionMessages::indexOutsideRange("status", sta
shiva.jm
2015/07/28 09:17:27
Done.
| |
| 160 return 0; | 162 return 0; |
| 161 } | 163 } |
| 162 | 164 |
| 163 // "2. If |init|'s statusText member does not match the Reason-Phrase | 165 // "2. If init's status member is a null body status and body is non-null, |
| 166 // throw a TypeError. | |
| 167 if ((status == 101 || status == 204 || status == 205 || status == 304) && bo dy) { | |
|
philipj_slow
2015/07/27 11:36:08
A helper for this would make it more obvious, as o
shiva.jm
2015/07/27 11:56:11
Done.
shiva.jm
2015/07/27 11:56:11
Done.
| |
| 168 exceptionState.throwTypeError("Invalid status"); | |
|
tyoshino (SeeGerritForStatus)
2015/07/27 11:26:52
Let's make this distinguishable with an error in t
hiroshige
2015/07/27 11:30:47
I'd like to make the message here more informative
shiva.jm
2015/07/27 11:56:11
Done.
shiva.jm
2015/07/27 11:56:11
Done.
shiva.jm
2015/07/27 11:56:11
Done.
| |
| 169 return 0; | |
| 170 } | |
| 171 | |
| 172 // "3. If |init|'s statusText member does not match the Reason-Phrase | |
| 164 // token production, throw a TypeError." | 173 // token production, throw a TypeError." |
| 165 if (!isValidReasonPhrase(responseInit.statusText)) { | 174 if (!isValidReasonPhrase(responseInit.statusText)) { |
| 166 exceptionState.throwTypeError("Invalid statusText"); | 175 exceptionState.throwTypeError("Invalid statusText"); |
| 167 return 0; | 176 return 0; |
| 168 } | 177 } |
| 169 | 178 |
| 170 // "3. Let |r| be a new Response object, associated with a new response, | 179 // "3. Let |r| be a new Response object, associated with a new response, |
|
tyoshino (SeeGerritForStatus)
2015/07/27 11:26:52
please update or remove the step numbers than only
shiva.jm
2015/07/27 11:56:11
Done.
| |
| 171 // Headers object, and Body object." | 180 // Headers object, and Body object." |
| 172 Response* r = new Response(context); | 181 Response* r = new Response(context); |
| 173 r->suspendIfNeeded(); | 182 r->suspendIfNeeded(); |
| 174 | 183 |
| 175 // "4. Set |r|'s response's status to |init|'s status member." | 184 // "4. Set |r|'s response's status to |init|'s status member." |
| 176 r->m_response->setStatus(responseInit.status); | 185 r->m_response->setStatus(responseInit.status); |
| 177 | 186 |
| 178 // "5. Set |r|'s response's status message to |init|'s statusText member." | 187 // "5. Set |r|'s response's status message to |init|'s statusText member." |
| 179 r->m_response->setStatusMessage(AtomicString(responseInit.statusText)); | 188 r->m_response->setStatusMessage(AtomicString(responseInit.statusText)); |
| 180 | 189 |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 434 } | 443 } |
| 435 | 444 |
| 436 DEFINE_TRACE(Response) | 445 DEFINE_TRACE(Response) |
| 437 { | 446 { |
| 438 Body::trace(visitor); | 447 Body::trace(visitor); |
| 439 visitor->trace(m_response); | 448 visitor->trace(m_response); |
| 440 visitor->trace(m_headers); | 449 visitor->trace(m_headers); |
| 441 } | 450 } |
| 442 | 451 |
| 443 } // namespace blink | 452 } // namespace blink |
| OLD | NEW |