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 0b2b43392e82096c0f1a494c59ff116825db99d5..3c835ffba2928576a15ca653ff99ffe2305a2084 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" |
#include "bindings/core/v8/ExceptionState.h" |
#include "bindings/core/v8/V8IteratorResultValue.h" |
+#include "bindings/modules/v8/ByteStringSequenceSequenceOrDictionaryOrHeaders.h" |
#include "core/dom/Iterator.h" |
#include "platform/loader/fetch/FetchUtils.h" |
#include "wtf/NotFound.h" |
@@ -54,39 +55,25 @@ class HeadersIterationSource final |
} // namespace |
-Headers* Headers::create() { |
- return new Headers; |
-} |
- |
Headers* Headers::create(ExceptionState&) { |
- return create(); |
-} |
- |
-Headers* Headers::create(const Headers* init, ExceptionState& exceptionState) { |
- // "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, exceptionState); |
- // "3. Return |headers|." |
- return headers; |
-} |
- |
-Headers* Headers::create(const Vector<Vector<String>>& init, |
- ExceptionState& exceptionState) { |
- // The same steps as above. |
- Headers* headers = create(); |
- headers->fillWith(init, exceptionState); |
- return headers; |
+ return new Headers; |
} |
-Headers* Headers::create(const Dictionary& init, |
- ExceptionState& exceptionState) { |
+Headers* Headers::create( |
+ const ByteStringSequenceSequenceOrDictionaryOrHeaders& init, |
+ ExceptionState& exceptionState) { |
// "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(exceptionState); |
// "2. If |init| is given, fill headers with |init|. Rethrow any exception." |
- headers->fillWith(init, exceptionState); |
+ if (init.isByteStringSequenceSequence()) { |
+ headers->fillWith(init.getAsByteStringSequenceSequence(), exceptionState); |
+ } else if (init.isDictionary()) { |
+ headers->fillWith(init.getAsDictionary(), exceptionState); |
+ } else if (init.isHeaders()) { |
+ // This branch will not be necessary once http://crbug.com/690428 is fixed. |
+ headers->fillWith(init.getAsHeaders(), exceptionState); |
+ } |
// "3. Return |headers|." |
return headers; |
} |
@@ -251,12 +238,9 @@ void Headers::set(const String& name, |
void Headers::fillWith(const Headers* object, ExceptionState& exceptionState) { |
ASSERT(m_headerList->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->m_headerList->list().size(); ++i) { |
append(object->m_headerList->list()[i]->first, |
object->m_headerList->list()[i]->second, exceptionState); |
@@ -268,12 +252,12 @@ void Headers::fillWith(const Headers* object, ExceptionState& exceptionState) { |
void Headers::fillWith(const Vector<Vector<String>>& object, |
ExceptionState& exceptionState) { |
ASSERT(!m_headerList->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) { |
exceptionState.throwTypeError("Invalid value"); |
@@ -292,13 +276,11 @@ void Headers::fillWith(const Dictionary& object, |
if (exceptionState.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>. |
+ // "2. Otherwise, |object| is a record, then for each mapping (|key|, |
+ // |value|) in |object|, append |key|/|value| to |headers|. Rethrow any |
+ // exception." |
+ // FIXME: This method's signature must change once we support record<K,V> in |
yhirano
2017/02/13 05:56:51
TODO(rakuco):
|
+ // the WebIDL code (http://crbug.com/685754). |
for (size_t i = 0; i < keys.size(); ++i) { |
String value; |
if (!DictionaryHelper::get(object, keys[i], value)) { |