Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(104)

Side by Side Diff: Source/modules/serviceworkers/Headers.cpp

Issue 373423002: Split Dictionary's get and convert into DictionaryHelper. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/serviceworkers/Headers.h" 6 #include "modules/serviceworkers/Headers.h"
7 7
8 #include "bindings/core/v8/Dictionary.h" 8 #include "bindings/core/v8/Dictionary.h"
9 #include "bindings/core/v8/DictionaryHelper.h"
9 #include "bindings/core/v8/ExceptionState.h" 10 #include "bindings/core/v8/ExceptionState.h"
10 #include "core/fetch/CrossOriginAccessControl.h" 11 #include "core/fetch/CrossOriginAccessControl.h"
11 #include "core/xml/XMLHttpRequest.h" 12 #include "core/xml/XMLHttpRequest.h"
12 #include "modules/serviceworkers/HeadersForEachCallback.h" 13 #include "modules/serviceworkers/HeadersForEachCallback.h"
13 #include "wtf/NotFound.h" 14 #include "wtf/NotFound.h"
14 #include "wtf/PassRefPtr.h" 15 #include "wtf/PassRefPtr.h"
15 #include "wtf/RefPtr.h" 16 #include "wtf/RefPtr.h"
16 #include "wtf/text/WTFString.h" 17 #include "wtf/text/WTFString.h"
17 18
18 namespace WebCore { 19 namespace WebCore {
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 object.getOwnPropertyNames(keys); 239 object.getOwnPropertyNames(keys);
239 if (keys.size() == 0) 240 if (keys.size() == 0)
240 return; 241 return;
241 242
242 // Because of the restrictions in IDL compiler of blink we recieve 243 // Because of the restrictions in IDL compiler of blink we recieve
243 // sequence<sequence<ByteString>> as a Dictionary, which is a type of union 244 // sequence<sequence<ByteString>> as a Dictionary, which is a type of union
244 // type of HeadersInit defined in the spec. 245 // type of HeadersInit defined in the spec.
245 // http://fetch.spec.whatwg.org/#headers-class 246 // http://fetch.spec.whatwg.org/#headers-class
246 // FIXME: Support sequence<sequence<ByteString>>. 247 // FIXME: Support sequence<sequence<ByteString>>.
247 Vector<String> keyValuePair; 248 Vector<String> keyValuePair;
248 if (object.get(keys[0], keyValuePair)) { 249 if (DictionaryHelper::get(object, keys[0], keyValuePair)) {
249 // "2. Otherwise, if |object| is a sequence, then for each |header| in 250 // "2. Otherwise, if |object| is a sequence, then for each |header| in
250 // |object|, run these substeps: 251 // |object|, run these substeps:
251 // 1. If |header| does not contain exactly two items, throw a 252 // 1. If |header| does not contain exactly two items, throw a
252 // TypeError. 253 // TypeError.
253 // 2. Append |header|'s first item/|header|'s second item to 254 // 2. Append |header|'s first item/|header|'s second item to
254 // |headers|. Rethrow any exception." 255 // |headers|. Rethrow any exception."
255 for (size_t i = 0; i < keys.size(); ++i) { 256 for (size_t i = 0; i < keys.size(); ++i) {
256 // We've already got the keyValuePair for key[0]. 257 // We've already got the keyValuePair for key[0].
257 if (i > 0) { 258 if (i > 0) {
258 if (!object.get(keys[i], keyValuePair)) { 259 if (!DictionaryHelper::get(object, keys[i], keyValuePair)) {
259 exceptionState.throwTypeError("Invalid value"); 260 exceptionState.throwTypeError("Invalid value");
260 return; 261 return;
261 } 262 }
262 } 263 }
263 if (keyValuePair.size() != 2) { 264 if (keyValuePair.size() != 2) {
264 exceptionState.throwTypeError("Invalid value"); 265 exceptionState.throwTypeError("Invalid value");
265 return; 266 return;
266 } 267 }
267 append(keyValuePair[0], keyValuePair[1], exceptionState); 268 append(keyValuePair[0], keyValuePair[1], exceptionState);
268 if (exceptionState.hadException()) 269 if (exceptionState.hadException())
269 return; 270 return;
270 keyValuePair.clear(); 271 keyValuePair.clear();
271 } 272 }
272 return; 273 return;
273 } 274 }
274 // "3. Otherwise, if |object| is an open-ended dictionary, then for each 275 // "3. Otherwise, if |object| is an open-ended dictionary, then for each
275 // |header| in object, run these substeps: 276 // |header| in object, run these substeps:
276 // 1. Set |header|'s key to |header|'s key, converted to ByteString. 277 // 1. Set |header|'s key to |header|'s key, converted to ByteString.
277 // Rethrow any exception. 278 // Rethrow any exception.
278 // 2. Append |header|'s key/|header|'s value to |headers|. Rethrow any 279 // 2. Append |header|'s key/|header|'s value to |headers|. Rethrow any
279 // exception." 280 // exception."
280 // FIXME: Support OpenEndedDictionary<ByteString>. 281 // FIXME: Support OpenEndedDictionary<ByteString>.
281 for (size_t i = 0; i < keys.size(); ++i) { 282 for (size_t i = 0; i < keys.size(); ++i) {
282 String value; 283 String value;
283 if (!object.get(keys[i], value)) { 284 if (!DictionaryHelper::get(object, keys[i], value)) {
284 exceptionState.throwTypeError("Invalid value"); 285 exceptionState.throwTypeError("Invalid value");
285 return; 286 return;
286 } 287 }
287 append(keys[i], value, exceptionState); 288 append(keys[i], value, exceptionState);
288 if (exceptionState.hadException()) 289 if (exceptionState.hadException())
289 return; 290 return;
290 } 291 }
291 } 292 }
292 293
293 Headers::Headers() 294 Headers::Headers()
(...skipping 18 matching lines...) Expand all
312 if (thisArg) 313 if (thisArg)
313 callback->handleItem(*thisArg, m_headerList->list()[i]->second, m_he aderList->list()[i]->first, this); 314 callback->handleItem(*thisArg, m_headerList->list()[i]->second, m_he aderList->list()[i]->first, this);
314 else 315 else
315 callback->handleItem(m_headerList->list()[i]->second, m_headerList-> list()[i]->first, this); 316 callback->handleItem(m_headerList->list()[i]->second, m_headerList-> list()[i]->first, this);
316 if (exceptionState.hadException()) 317 if (exceptionState.hadException())
317 break; 318 break;
318 } 319 }
319 } 320 }
320 321
321 } // namespace WebCore 322 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698