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 1e41606fd5cbac476887c2331ed3e2b4879d7275..a62a64039ad13f424c71cb58450623f16673d31a 100644 |
--- a/third_party/WebKit/Source/modules/fetch/Headers.cpp |
+++ b/third_party/WebKit/Source/modules/fetch/Headers.cpp |
@@ -4,9 +4,9 @@ |
#include "modules/fetch/Headers.h" |
-#include "bindings/core/v8/Dictionary.h" |
#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 "platform/wtf/NotFound.h" |
@@ -54,39 +54,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 +239,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 +253,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 +270,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; |
} |