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 "modules/fetch/Headers.h" | 5 #include "modules/fetch/Headers.h" |
| 6 | 6 |
| 7 #include "bindings/core/v8/Dictionary.h" | 7 #include "bindings/core/v8/Dictionary.h" |
| 8 #include "bindings/core/v8/ExceptionState.h" | 8 #include "bindings/core/v8/ExceptionState.h" |
| 9 #include "bindings/core/v8/V8IteratorResultValue.h" | 9 #include "bindings/core/v8/V8IteratorResultValue.h" |
| 10 #include "core/dom/Iterator.h" | 10 #include "core/dom/Iterator.h" |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 // "5. Otherwise, if guard is |response| and |name| is a forbidden response | 243 // "5. Otherwise, if guard is |response| and |name| is a forbidden response |
| 244 // header name, return." | 244 // header name, return." |
| 245 if (m_guard == ResponseGuard && | 245 if (m_guard == ResponseGuard && |
| 246 FetchUtils::isForbiddenResponseHeaderName(name)) | 246 FetchUtils::isForbiddenResponseHeaderName(name)) |
| 247 return; | 247 return; |
| 248 // "6. Set |name|/|value| in header list." | 248 // "6. Set |name|/|value| in header list." |
| 249 m_headerList->set(name, value); | 249 m_headerList->set(name, value); |
| 250 } | 250 } |
| 251 | 251 |
| 252 void Headers::fillWith(const Headers* object, ExceptionState& exceptionState) { | 252 void Headers::fillWith(const Headers* object, ExceptionState& exceptionState) { |
| 253 ASSERT(m_headerList->size() == 0); | 253 DCHECK(m_headerList->size() == 0); |
|
tkent
2017/04/08 02:29:54
Use DCHECK_EQ.
| |
| 254 // "To fill a Headers object (|this|) with a given object (|object|), run | 254 // "To fill a Headers object (|this|) with a given object (|object|), run |
| 255 // these steps:" | 255 // these steps:" |
| 256 // "1. If |object| is a Headers object, copy its header list as | 256 // "1. If |object| is a Headers object, copy its header list as |
| 257 // |headerListCopy| and then for each |header| in |headerListCopy|, | 257 // |headerListCopy| and then for each |header| in |headerListCopy|, |
| 258 // retaining order, append header's |name|/|header|'s value to | 258 // retaining order, append header's |name|/|header|'s value to |
| 259 // |headers|. Rethrow any exception." | 259 // |headers|. Rethrow any exception." |
| 260 for (size_t i = 0; i < object->m_headerList->list().size(); ++i) { | 260 for (size_t i = 0; i < object->m_headerList->list().size(); ++i) { |
| 261 append(object->m_headerList->list()[i]->first, | 261 append(object->m_headerList->list()[i]->first, |
| 262 object->m_headerList->list()[i]->second, exceptionState); | 262 object->m_headerList->list()[i]->second, exceptionState); |
| 263 if (exceptionState.hadException()) | 263 if (exceptionState.hadException()) |
| 264 return; | 264 return; |
| 265 } | 265 } |
| 266 } | 266 } |
| 267 | 267 |
| 268 void Headers::fillWith(const Vector<Vector<String>>& object, | 268 void Headers::fillWith(const Vector<Vector<String>>& object, |
| 269 ExceptionState& exceptionState) { | 269 ExceptionState& exceptionState) { |
| 270 ASSERT(!m_headerList->size()); | 270 DCHECK(!m_headerList->size()); |
| 271 // "2. Otherwise, if |object| is a sequence, then for each |header| in | 271 // "2. Otherwise, if |object| is a sequence, then for each |header| in |
| 272 // |object|, run these substeps: | 272 // |object|, run these substeps: |
| 273 // 1. If |header| does not contain exactly two items, throw a | 273 // 1. If |header| does not contain exactly two items, throw a |
| 274 // TypeError. | 274 // TypeError. |
| 275 // 2. Append |header|'s first item/|header|'s second item to | 275 // 2. Append |header|'s first item/|header|'s second item to |
| 276 // |headers|. Rethrow any exception." | 276 // |headers|. Rethrow any exception." |
| 277 for (size_t i = 0; i < object.size(); ++i) { | 277 for (size_t i = 0; i < object.size(); ++i) { |
| 278 if (object[i].size() != 2) { | 278 if (object[i].size() != 2) { |
| 279 exceptionState.throwTypeError("Invalid value"); | 279 exceptionState.throwTypeError("Invalid value"); |
| 280 return; | 280 return; |
| 281 } | 281 } |
| 282 append(object[i][0], object[i][1], exceptionState); | 282 append(object[i][0], object[i][1], exceptionState); |
| 283 if (exceptionState.hadException()) | 283 if (exceptionState.hadException()) |
| 284 return; | 284 return; |
| 285 } | 285 } |
| 286 } | 286 } |
| 287 | 287 |
| 288 void Headers::fillWith(const Dictionary& object, | 288 void Headers::fillWith(const Dictionary& object, |
| 289 ExceptionState& exceptionState) { | 289 ExceptionState& exceptionState) { |
| 290 ASSERT(!m_headerList->size()); | 290 DCHECK(!m_headerList->size()); |
| 291 const Vector<String>& keys = object.getPropertyNames(exceptionState); | 291 const Vector<String>& keys = object.getPropertyNames(exceptionState); |
| 292 if (exceptionState.hadException() || !keys.size()) | 292 if (exceptionState.hadException() || !keys.size()) |
| 293 return; | 293 return; |
| 294 | 294 |
| 295 // "3. Otherwise, if |object| is an open-ended dictionary, then for each | 295 // "3. Otherwise, if |object| is an open-ended dictionary, then for each |
| 296 // |header| in object, run these substeps: | 296 // |header| in object, run these substeps: |
| 297 // 1. Set |header|'s key to |header|'s key, converted to ByteString. | 297 // 1. Set |header|'s key to |header|'s key, converted to ByteString. |
| 298 // Rethrow any exception. | 298 // Rethrow any exception. |
| 299 // 2. Append |header|'s key/|header|'s value to |headers|. Rethrow any | 299 // 2. Append |header|'s key/|header|'s value to |headers|. Rethrow any |
| 300 // exception." | 300 // exception." |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 321 visitor->trace(m_headerList); | 321 visitor->trace(m_headerList); |
| 322 } | 322 } |
| 323 | 323 |
| 324 PairIterable<String, String>::IterationSource* Headers::startIteration( | 324 PairIterable<String, String>::IterationSource* Headers::startIteration( |
| 325 ScriptState*, | 325 ScriptState*, |
| 326 ExceptionState&) { | 326 ExceptionState&) { |
| 327 return new HeadersIterationSource(m_headerList); | 327 return new HeadersIterationSource(m_headerList); |
| 328 } | 328 } |
| 329 | 329 |
| 330 } // namespace blink | 330 } // namespace blink |
| OLD | NEW |