Chromium Code Reviews| Index: third_party/WebKit/Source/modules/fetch/Headers.cpp |
| diff --git a/third_party/WebKit/Source/modules/fetch/Headers.cpp b/third_party/WebKit/Source/modules/fetch/Headers.cpp |
| index 09b928f27b13ae7acc106fe11c37bd3b5e1052f6..364a51b1cefcc25325d415bd5a664f0c025ed3c5 100644 |
| --- a/third_party/WebKit/Source/modules/fetch/Headers.cpp |
| +++ b/third_party/WebKit/Source/modules/fetch/Headers.cpp |
| @@ -7,6 +7,7 @@ |
| #include "bindings/core/v8/Dictionary.h" |
|
yhirano
2017/04/11 03:32:41
Do we still need this?
Raphael Kubo da Costa (rakuco)
2017/04/11 08:02:21
Nope; removed in patch v6.
|
| #include "bindings/core/v8/ExceptionState.h" |
| #include "bindings/core/v8/V8IteratorResultValue.h" |
| +#include "bindings/modules/v8/ByteStringSequenceSequenceOrByteStringByteStringRecordOrHeaders.h" |
| #include "core/dom/Iterator.h" |
| #include "platform/loader/fetch/FetchUtils.h" |
| #include "wtf/NotFound.h" |
| @@ -54,39 +55,27 @@ class HeadersIterationSource final |
| } // namespace |
| -Headers* Headers::Create() { |
| - return new Headers; |
| -} |
| - |
| Headers* Headers::Create(ExceptionState&) { |
| - return Create(); |
| -} |
| - |
| -Headers* Headers::Create(const Headers* init, ExceptionState& exception_state) { |
| - // "The Headers(|init|) constructor, when invoked, must run these steps:" |
| - // "1. Let |headers| be a new Headers object." |
| - Headers* headers = Create(); |
| - // "2. If |init| is given, fill headers with |init|. Rethrow any exception." |
| - headers->FillWith(init, exception_state); |
| - // "3. Return |headers|." |
| - return headers; |
| -} |
| - |
| -Headers* Headers::Create(const Vector<Vector<String>>& init, |
| - ExceptionState& exception_state) { |
| - // The same steps as above. |
| - Headers* headers = Create(); |
| - headers->FillWith(init, exception_state); |
| - return headers; |
| + return new Headers; |
| } |
| -Headers* Headers::Create(const Dictionary& init, |
| - ExceptionState& exception_state) { |
| +Headers* Headers::Create( |
| + const ByteStringSequenceSequenceOrByteStringByteStringRecordOrHeaders& init, |
| + ExceptionState& exception_state) { |
| // "The Headers(|init|) constructor, when invoked, must run these steps:" |
| - // "1. Let |headers| be a new Headers object." |
| - Headers* headers = Create(); |
| + // "1. Let |headers| be a new Headers object whose guard is "none". |
| + Headers* headers = Create(exception_state); |
| // "2. If |init| is given, fill headers with |init|. Rethrow any exception." |
| - headers->FillWith(init, exception_state); |
| + if (init.isByteStringSequenceSequence()) { |
| + headers->FillWith(init.getAsByteStringSequenceSequence(), exception_state); |
| + } else if (init.isByteStringByteStringRecord()) { |
| + headers->FillWith(init.getAsByteStringByteStringRecord(), exception_state); |
| + } else if (init.isHeaders()) { |
| + // This branch will not be necessary once http://crbug.com/690428 is fixed. |
| + headers->FillWith(init.getAsHeaders(), exception_state); |
| + } else { |
| + NOTREACHED(); |
| + } |
| // "3. Return |headers|." |
| return headers; |
| } |
| @@ -251,12 +240,9 @@ void Headers::set(const String& name, |
| void Headers::FillWith(const Headers* object, ExceptionState& exception_state) { |
| ASSERT(header_list_->size() == 0); |
| - // "To fill a Headers object (|this|) with a given object (|object|), run |
| - // these steps:" |
| - // "1. If |object| is a Headers object, copy its header list as |
| - // |headerListCopy| and then for each |header| in |headerListCopy|, |
| - // retaining order, append header's |name|/|header|'s value to |
| - // |headers|. Rethrow any exception." |
| + // There used to be specific steps describing filling a Headers object with |
| + // another Headers object, but it has since been removed because it should be |
| + // handled like a sequence (http://crbug.com/690428). |
| for (size_t i = 0; i < object->header_list_->List().size(); ++i) { |
| append(object->header_list_->List()[i]->first, |
| object->header_list_->List()[i]->second, exception_state); |
| @@ -268,12 +254,12 @@ void Headers::FillWith(const Headers* object, ExceptionState& exception_state) { |
| void Headers::FillWith(const Vector<Vector<String>>& object, |
| ExceptionState& exception_state) { |
| ASSERT(!header_list_->size()); |
| - // "2. Otherwise, if |object| is a sequence, then for each |header| in |
| - // |object|, run these substeps: |
| - // 1. If |header| does not contain exactly two items, throw a |
| - // TypeError. |
| - // 2. Append |header|'s first item/|header|'s second item to |
| - // |headers|. Rethrow any exception." |
| + // "1. If |object| is a sequence, then for each |header| in |object|, run |
| + // these substeps: |
| + // 1. If |header| does not contain exactly two items, then throw a |
| + // TypeError. |
| + // 2. Append |header|’s first item/|header|’s second item to |headers|. |
| + // Rethrow any exception." |
| for (size_t i = 0; i < object.size(); ++i) { |
| if (object[i].size() != 2) { |
| exception_state.ThrowTypeError("Invalid value"); |
| @@ -285,27 +271,12 @@ void Headers::FillWith(const Vector<Vector<String>>& object, |
| } |
| } |
| -void Headers::FillWith(const Dictionary& object, |
| +void Headers::FillWith(const Vector<std::pair<String, String>>& object, |
| ExceptionState& exception_state) { |
| ASSERT(!header_list_->size()); |
| - const Vector<String>& keys = object.GetPropertyNames(exception_state); |
| - if (exception_state.HadException() || !keys.size()) |
| - return; |
| - // "3. Otherwise, if |object| is an open-ended dictionary, then for each |
| - // |header| in object, run these substeps: |
| - // 1. Set |header|'s key to |header|'s key, converted to ByteString. |
| - // Rethrow any exception. |
| - // 2. Append |header|'s key/|header|'s value to |headers|. Rethrow any |
| - // exception." |
| - // FIXME: Support OpenEndedDictionary<ByteString>. |
| - for (size_t i = 0; i < keys.size(); ++i) { |
| - String value; |
| - if (!DictionaryHelper::Get(object, keys[i], value)) { |
| - exception_state.ThrowTypeError("Invalid value"); |
| - return; |
| - } |
| - append(keys[i], value, exception_state); |
| + for (const auto& item : object) { |
| + append(item.first, item.second, exception_state); |
| if (exception_state.HadException()) |
| return; |
| } |