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

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

Issue 1767883002: DevTools: generate string16-based handlers for v8_inspector. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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/Decimal.h" 7 #include "platform/inspector_protocol/String16.h"
8 #include "platform/inspector_protocol/Values.h" 8 #include "platform/inspector_protocol/Values.h"
9 #include "wtf/text/StringBuilder.h"
10 #include "wtf/text/UTF8.h"
11 9
12 namespace blink { 10 namespace blink {
13 namespace protocol { 11 namespace protocol {
14 12
15 namespace { 13 namespace {
16 14
17 const int stackLimit = 1000; 15 const int stackLimit = 1000;
18 16
19 enum Token { 17 enum Token {
20 ObjectBegin, 18 ObjectBegin,
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 return c - '0'; 290 return c - '0';
293 if ('A' <= c && c <= 'F') 291 if ('A' <= c && c <= 'F')
294 return c - 'A' + 10; 292 return c - 'A' + 10;
295 if ('a' <= c && c <= 'f') 293 if ('a' <= c && c <= 'f')
296 return c - 'a' + 10; 294 return c - 'a' + 10;
297 ASSERT_NOT_REACHED(); 295 ASSERT_NOT_REACHED();
298 return 0; 296 return 0;
299 } 297 }
300 298
301 template<typename CharType> 299 template<typename CharType>
302 bool decodeUTF8(const CharType* start, const CharType* end, const CharType** utf 8charEnd, StringBuilder* output) 300 bool decodeUTF8(const CharType* start, const CharType* end, const CharType** utf 8charEnd, String16Builder* output)
303 { 301 {
304 UChar utf16[4] = {0}; 302 UChar utf16[4] = {0};
305 char utf8[6] = {0}; 303 char utf8[6] = {0};
306 size_t utf8count = 0; 304 size_t utf8count = 0;
307 305
308 while (start < end) { 306 while (start < end) {
309 if (start + 1 >= end || *start != '\\' || *(start + 1) != 'x') 307 if (start + 1 >= end || *start != '\\' || *(start + 1) != 'x')
310 return false; 308 return false;
311 start += 2; 309 start += 2;
312 310
(...skipping 23 matching lines...) Expand all
336 334
337 // Keep accumulating utf8 characters up to buffer length (6 should be en ough). 335 // Keep accumulating utf8 characters up to buffer length (6 should be en ough).
338 if (utf8count >= WTF_ARRAY_LENGTH(utf8)) 336 if (utf8count >= WTF_ARRAY_LENGTH(utf8))
339 return false; 337 return false;
340 } 338 }
341 339
342 return false; 340 return false;
343 } 341 }
344 342
345 template<typename CharType> 343 template<typename CharType>
346 bool decodeString(const CharType* start, const CharType* end, StringBuilder* out put) 344 bool decodeString(const CharType* start, const CharType* end, String16Builder* o utput)
347 { 345 {
348 while (start < end) { 346 while (start < end) {
349 UChar c = *start++; 347 UChar c = *start++;
350 if ('\\' != c) { 348 if ('\\' != c) {
351 output->append(c); 349 output->append(c);
352 continue; 350 continue;
353 } 351 }
354 c = *start++; 352 c = *start++;
355 353
356 if (c == 'x') { 354 if (c == 'x') {
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 398
401 template<typename CharType> 399 template<typename CharType>
402 bool decodeString(const CharType* start, const CharType* end, String* output) 400 bool decodeString(const CharType* start, const CharType* end, String* output)
403 { 401 {
404 if (start == end) { 402 if (start == end) {
405 *output = ""; 403 *output = "";
406 return true; 404 return true;
407 } 405 }
408 if (start > end) 406 if (start > end)
409 return false; 407 return false;
410 StringBuilder buffer; 408 String16Builder buffer;
411 buffer.reserveCapacity(end - start); 409 buffer.reserveCapacity(end - start);
412 if (!decodeString(start, end, &buffer)) 410 if (!decodeString(start, end, &buffer))
413 return false; 411 return false;
414 *output = buffer.toString(); 412 *output = buffer.toString();
415 // Validate constructed utf16 string. 413 // Validate constructed utf16 string.
416 if (output->utf8(StrictUTF8Conversion).isNull()) 414 if (output->utf8(StrictUTF8Conversion).isNull())
417 return false; 415 return false;
418 return true; 416 return true;
419 } 417 }
420 418
(...skipping 14 matching lines...) Expand all
435 result = Value::null(); 433 result = Value::null();
436 break; 434 break;
437 case BoolTrue: 435 case BoolTrue:
438 result = FundamentalValue::create(true); 436 result = FundamentalValue::create(true);
439 break; 437 break;
440 case BoolFalse: 438 case BoolFalse:
441 result = FundamentalValue::create(false); 439 result = FundamentalValue::create(false);
442 break; 440 break;
443 case Number: { 441 case Number: {
444 bool ok; 442 bool ok;
445 double value = charactersToDouble(tokenStart, tokenEnd - tokenStart, &ok ); 443 double value = String16::charactersToDouble(tokenStart, tokenEnd - token Start, &ok);
446 if (Decimal::fromDouble(value).isInfinity())
447 ok = false;
448 if (!ok) 444 if (!ok)
449 return nullptr; 445 return nullptr;
450 result = FundamentalValue::create(value); 446 result = FundamentalValue::create(value);
451 break; 447 break;
452 } 448 }
453 case StringLiteral: { 449 case StringLiteral: {
454 String value; 450 String value;
455 bool ok = decodeString(tokenStart + 1, tokenEnd - 1, &value); 451 bool ok = decodeString(tokenStart + 1, tokenEnd - 1, &value);
456 if (!ok) 452 if (!ok)
457 return nullptr; 453 return nullptr;
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 const CharType* end = start + length; 539 const CharType* end = start + length;
544 const CharType *tokenEnd; 540 const CharType *tokenEnd;
545 OwnPtr<Value> value = buildValue(start, end, &tokenEnd, 0); 541 OwnPtr<Value> value = buildValue(start, end, &tokenEnd, 0);
546 if (!value || tokenEnd != end) 542 if (!value || tokenEnd != end)
547 return nullptr; 543 return nullptr;
548 return value.release(); 544 return value.release();
549 } 545 }
550 546
551 } // anonymous namespace 547 } // anonymous namespace
552 548
553 PassOwnPtr<Value> parseJSON(const String& json) 549 PassOwnPtr<Value> parseJSON(const String16& json)
554 { 550 {
555 if (json.isEmpty()) 551 if (json.isEmpty())
556 return nullptr; 552 return nullptr;
557 if (json.is8Bit()) 553 if (json.is8Bit())
558 return parseJSONInternal(json.characters8(), json.length()); 554 return parseJSONInternal(json.characters8(), json.length());
559 return parseJSONInternal(json.characters16(), json.length()); 555 return parseJSONInternal(json.characters16(), json.length());
560 } 556 }
561 557
562 } // namespace protocol 558 } // namespace protocol
563 } // namespace blink 559 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698