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

Side by Side Diff: third_party/WebKit/Source/platform/inspector_protocol/Parser.cpp

Issue 2004313003: DevTools: migrate from OwnPtr to std::unique_ptr for inspector protocol classes. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebaselined Created 4 years, 6 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "platform/inspector_protocol/Parser.h" 5 #include "platform/inspector_protocol/Parser.h"
6 6
7 #include "platform/inspector_protocol/String16.h" 7 #include "platform/inspector_protocol/String16.h"
8 #include "platform/inspector_protocol/Values.h" 8 #include "platform/inspector_protocol/Values.h"
9 9
10 namespace blink { 10 namespace blink {
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
349 if (start > end) 349 if (start > end)
350 return false; 350 return false;
351 String16Builder buffer; 351 String16Builder buffer;
352 buffer.reserveCapacity(end - start); 352 buffer.reserveCapacity(end - start);
353 if (!decodeString(start, end, &buffer)) 353 if (!decodeString(start, end, &buffer))
354 return false; 354 return false;
355 *output = buffer.toString(); 355 *output = buffer.toString();
356 return true; 356 return true;
357 } 357 }
358 358
359 PassOwnPtr<Value> buildValue(const UChar* start, const UChar* end, const UChar** valueTokenEnd, int depth) 359 std::unique_ptr<Value> buildValue(const UChar* start, const UChar* end, const UC har** valueTokenEnd, int depth)
360 { 360 {
361 if (depth > stackLimit) 361 if (depth > stackLimit)
362 return nullptr; 362 return nullptr;
363 363
364 OwnPtr<Value> result; 364 std::unique_ptr<Value> result;
365 const UChar* tokenStart; 365 const UChar* tokenStart;
366 const UChar* tokenEnd; 366 const UChar* tokenEnd;
367 Token token = parseToken(start, end, &tokenStart, &tokenEnd); 367 Token token = parseToken(start, end, &tokenStart, &tokenEnd);
368 switch (token) { 368 switch (token) {
369 case InvalidToken: 369 case InvalidToken:
370 return nullptr; 370 return nullptr;
371 case NullToken: 371 case NullToken:
372 result = Value::null(); 372 result = Value::null();
373 break; 373 break;
374 case BoolTrue: 374 case BoolTrue:
(...skipping 12 matching lines...) Expand all
387 } 387 }
388 case StringLiteral: { 388 case StringLiteral: {
389 String16 value; 389 String16 value;
390 bool ok = decodeString(tokenStart + 1, tokenEnd - 1, &value); 390 bool ok = decodeString(tokenStart + 1, tokenEnd - 1, &value);
391 if (!ok) 391 if (!ok)
392 return nullptr; 392 return nullptr;
393 result = StringValue::create(value); 393 result = StringValue::create(value);
394 break; 394 break;
395 } 395 }
396 case ArrayBegin: { 396 case ArrayBegin: {
397 OwnPtr<ListValue> array = ListValue::create(); 397 std::unique_ptr<ListValue> array = ListValue::create();
398 start = tokenEnd; 398 start = tokenEnd;
399 token = parseToken(start, end, &tokenStart, &tokenEnd); 399 token = parseToken(start, end, &tokenStart, &tokenEnd);
400 while (token != ArrayEnd) { 400 while (token != ArrayEnd) {
401 OwnPtr<Value> arrayNode = buildValue(start, end, &tokenEnd, depth + 1); 401 std::unique_ptr<Value> arrayNode = buildValue(start, end, &tokenEnd, depth + 1);
402 if (!arrayNode) 402 if (!arrayNode)
403 return nullptr; 403 return nullptr;
404 array->pushValue(std::move(arrayNode)); 404 array->pushValue(std::move(arrayNode));
405 405
406 // After a list value, we expect a comma or the end of the list. 406 // After a list value, we expect a comma or the end of the list.
407 start = tokenEnd; 407 start = tokenEnd;
408 token = parseToken(start, end, &tokenStart, &tokenEnd); 408 token = parseToken(start, end, &tokenStart, &tokenEnd);
409 if (token == ListSeparator) { 409 if (token == ListSeparator) {
410 start = tokenEnd; 410 start = tokenEnd;
411 token = parseToken(start, end, &tokenStart, &tokenEnd); 411 token = parseToken(start, end, &tokenStart, &tokenEnd);
412 if (token == ArrayEnd) 412 if (token == ArrayEnd)
413 return nullptr; 413 return nullptr;
414 } else if (token != ArrayEnd) { 414 } else if (token != ArrayEnd) {
415 // Unexpected value after list value. Bail out. 415 // Unexpected value after list value. Bail out.
416 return nullptr; 416 return nullptr;
417 } 417 }
418 } 418 }
419 if (token != ArrayEnd) 419 if (token != ArrayEnd)
420 return nullptr; 420 return nullptr;
421 result = std::move(array); 421 result = std::move(array);
422 break; 422 break;
423 } 423 }
424 case ObjectBegin: { 424 case ObjectBegin: {
425 OwnPtr<DictionaryValue> object = DictionaryValue::create(); 425 std::unique_ptr<DictionaryValue> object = DictionaryValue::create();
426 start = tokenEnd; 426 start = tokenEnd;
427 token = parseToken(start, end, &tokenStart, &tokenEnd); 427 token = parseToken(start, end, &tokenStart, &tokenEnd);
428 while (token != ObjectEnd) { 428 while (token != ObjectEnd) {
429 if (token != StringLiteral) 429 if (token != StringLiteral)
430 return nullptr; 430 return nullptr;
431 String16 key; 431 String16 key;
432 if (!decodeString(tokenStart + 1, tokenEnd - 1, &key)) 432 if (!decodeString(tokenStart + 1, tokenEnd - 1, &key))
433 return nullptr; 433 return nullptr;
434 start = tokenEnd; 434 start = tokenEnd;
435 435
436 token = parseToken(start, end, &tokenStart, &tokenEnd); 436 token = parseToken(start, end, &tokenStart, &tokenEnd);
437 if (token != ObjectPairSeparator) 437 if (token != ObjectPairSeparator)
438 return nullptr; 438 return nullptr;
439 start = tokenEnd; 439 start = tokenEnd;
440 440
441 OwnPtr<Value> value = buildValue(start, end, &tokenEnd, depth + 1); 441 std::unique_ptr<Value> value = buildValue(start, end, &tokenEnd, dep th + 1);
442 if (!value) 442 if (!value)
443 return nullptr; 443 return nullptr;
444 object->setValue(key, std::move(value)); 444 object->setValue(key, std::move(value));
445 start = tokenEnd; 445 start = tokenEnd;
446 446
447 // After a key/value pair, we expect a comma or the end of the 447 // After a key/value pair, we expect a comma or the end of the
448 // object. 448 // object.
449 token = parseToken(start, end, &tokenStart, &tokenEnd); 449 token = parseToken(start, end, &tokenStart, &tokenEnd);
450 if (token == ListSeparator) { 450 if (token == ListSeparator) {
451 start = tokenEnd; 451 start = tokenEnd;
(...skipping 13 matching lines...) Expand all
465 465
466 default: 466 default:
467 // We got a token that's not a value. 467 // We got a token that's not a value.
468 return nullptr; 468 return nullptr;
469 } 469 }
470 470
471 skipWhitespaceAndComments(tokenEnd, end, valueTokenEnd); 471 skipWhitespaceAndComments(tokenEnd, end, valueTokenEnd);
472 return result; 472 return result;
473 } 473 }
474 474
475 PassOwnPtr<Value> parseJSONInternal(const UChar* start, unsigned length) 475 std::unique_ptr<Value> parseJSONInternal(const UChar* start, unsigned length)
476 { 476 {
477 const UChar* end = start + length; 477 const UChar* end = start + length;
478 const UChar *tokenEnd; 478 const UChar *tokenEnd;
479 OwnPtr<Value> value = buildValue(start, end, &tokenEnd, 0); 479 std::unique_ptr<Value> value = buildValue(start, end, &tokenEnd, 0);
480 if (!value || tokenEnd != end) 480 if (!value || tokenEnd != end)
481 return nullptr; 481 return nullptr;
482 return value; 482 return value;
483 } 483 }
484 484
485 } // anonymous namespace 485 } // anonymous namespace
486 486
487 PassOwnPtr<Value> parseJSON(const String16& json) 487 std::unique_ptr<Value> parseJSON(const String16& json)
488 { 488 {
489 if (json.isEmpty()) 489 if (json.isEmpty())
490 return nullptr; 490 return nullptr;
491 return parseJSONInternal(json.characters16(), json.length()); 491 return parseJSONInternal(json.characters16(), json.length());
492 } 492 }
493 493
494 } // namespace protocol 494 } // namespace protocol
495 } // namespace blink 495 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698