OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project 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 #ifndef V8_JSON_PARSER_H_ | 5 #ifndef V8_JSON_PARSER_H_ |
6 #define V8_JSON_PARSER_H_ | 6 #define V8_JSON_PARSER_H_ |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/char-predicates-inl.h" | 10 #include "src/char-predicates-inl.h" |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
307 | 307 |
308 AdvanceSkipWhitespace(); | 308 AdvanceSkipWhitespace(); |
309 if (c0_ != '}') { | 309 if (c0_ != '}') { |
310 do { | 310 do { |
311 if (c0_ != '"') return ReportUnexpectedCharacter(); | 311 if (c0_ != '"') return ReportUnexpectedCharacter(); |
312 | 312 |
313 int start_position = position_; | 313 int start_position = position_; |
314 Advance(); | 314 Advance(); |
315 | 315 |
316 uint32_t index = 0; | 316 uint32_t index = 0; |
317 if (c0_ >= '0' && c0_ <= '9') { | 317 if (IsDecimalDigit(c0_)) { |
318 // Maybe an array index, try to parse it. | 318 // Maybe an array index, try to parse it. |
319 if (c0_ == '0') { | 319 if (c0_ == '0') { |
320 // With a leading zero, the string has to be "0" only to be an index. | 320 // With a leading zero, the string has to be "0" only to be an index. |
321 Advance(); | 321 Advance(); |
322 } else { | 322 } else { |
323 do { | 323 do { |
324 int d = c0_ - '0'; | 324 int d = c0_ - '0'; |
325 if (index > 429496729U - ((d > 5) ? 1 : 0)) break; | 325 if (index > 429496729U - ((d > 5) ? 1 : 0)) break; |
326 index = (index * 10) + d; | 326 index = (index * 10) + d; |
327 Advance(); | 327 Advance(); |
328 } while (c0_ >= '0' && c0_ <= '9'); | 328 } while (IsDecimalDigit(c0_)); |
329 } | 329 } |
330 | 330 |
331 if (c0_ == '"') { | 331 if (c0_ == '"') { |
332 // Successfully parsed index, parse and store element. | 332 // Successfully parsed index, parse and store element. |
333 AdvanceSkipWhitespace(); | 333 AdvanceSkipWhitespace(); |
334 | 334 |
335 if (c0_ != ':') return ReportUnexpectedCharacter(); | 335 if (c0_ != ':') return ReportUnexpectedCharacter(); |
336 AdvanceSkipWhitespace(); | 336 AdvanceSkipWhitespace(); |
337 Handle<Object> value = ParseJsonValue(); | 337 Handle<Object> value = ParseJsonValue(); |
338 if (value.is_null()) return ReportUnexpectedCharacter(); | 338 if (value.is_null()) return ReportUnexpectedCharacter(); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 bool negative = false; | 508 bool negative = false; |
509 int beg_pos = position_; | 509 int beg_pos = position_; |
510 if (c0_ == '-') { | 510 if (c0_ == '-') { |
511 Advance(); | 511 Advance(); |
512 negative = true; | 512 negative = true; |
513 } | 513 } |
514 if (c0_ == '0') { | 514 if (c0_ == '0') { |
515 Advance(); | 515 Advance(); |
516 // Prefix zero is only allowed if it's the only digit before | 516 // Prefix zero is only allowed if it's the only digit before |
517 // a decimal point or exponent. | 517 // a decimal point or exponent. |
518 if ('0' <= c0_ && c0_ <= '9') return ReportUnexpectedCharacter(); | 518 if (IsDecimalDigit(c0_)) return ReportUnexpectedCharacter(); |
519 } else { | 519 } else { |
520 int i = 0; | 520 int i = 0; |
521 int digits = 0; | 521 int digits = 0; |
522 if (c0_ < '1' || c0_ > '9') return ReportUnexpectedCharacter(); | 522 if (c0_ < '1' || c0_ > '9') return ReportUnexpectedCharacter(); |
523 do { | 523 do { |
524 i = i * 10 + c0_ - '0'; | 524 i = i * 10 + c0_ - '0'; |
525 digits++; | 525 digits++; |
526 Advance(); | 526 Advance(); |
527 } while (c0_ >= '0' && c0_ <= '9'); | 527 } while (IsDecimalDigit(c0_)); |
528 if (c0_ != '.' && c0_ != 'e' && c0_ != 'E' && digits < 10) { | 528 if (c0_ != '.' && c0_ != 'e' && c0_ != 'E' && digits < 10) { |
529 SkipWhitespace(); | 529 SkipWhitespace(); |
530 return Handle<Smi>(Smi::FromInt((negative ? -i : i)), isolate()); | 530 return Handle<Smi>(Smi::FromInt((negative ? -i : i)), isolate()); |
531 } | 531 } |
532 } | 532 } |
533 if (c0_ == '.') { | 533 if (c0_ == '.') { |
534 Advance(); | 534 Advance(); |
535 if (c0_ < '0' || c0_ > '9') return ReportUnexpectedCharacter(); | 535 if (!IsDecimalDigit(c0_)) return ReportUnexpectedCharacter(); |
536 do { | 536 do { |
537 Advance(); | 537 Advance(); |
538 } while (c0_ >= '0' && c0_ <= '9'); | 538 } while (IsDecimalDigit(c0_)); |
539 } | 539 } |
540 if (AsciiAlphaToLower(c0_) == 'e') { | 540 if (AsciiAlphaToLower(c0_) == 'e') { |
541 Advance(); | 541 Advance(); |
542 if (c0_ == '-' || c0_ == '+') Advance(); | 542 if (c0_ == '-' || c0_ == '+') Advance(); |
543 if (c0_ < '0' || c0_ > '9') return ReportUnexpectedCharacter(); | 543 if (!IsDecimalDigit(c0_)) return ReportUnexpectedCharacter(); |
544 do { | 544 do { |
545 Advance(); | 545 Advance(); |
546 } while (c0_ >= '0' && c0_ <= '9'); | 546 } while (IsDecimalDigit(c0_)); |
547 } | 547 } |
548 int length = position_ - beg_pos; | 548 int length = position_ - beg_pos; |
549 double number; | 549 double number; |
550 if (seq_one_byte) { | 550 if (seq_one_byte) { |
551 Vector<const uint8_t> chars(seq_source_->GetChars() + beg_pos, length); | 551 Vector<const uint8_t> chars(seq_source_->GetChars() + beg_pos, length); |
552 number = StringToDouble(isolate()->unicode_cache(), chars, | 552 number = StringToDouble(isolate()->unicode_cache(), chars, |
553 NO_FLAGS, // Hex, octal or trailing junk. | 553 NO_FLAGS, // Hex, octal or trailing junk. |
554 std::numeric_limits<double>::quiet_NaN()); | 554 std::numeric_limits<double>::quiet_NaN()); |
555 } else { | 555 } else { |
556 Vector<uint8_t> buffer = Vector<uint8_t>::New(length); | 556 Vector<uint8_t> buffer = Vector<uint8_t>::New(length); |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
807 | 807 |
808 DCHECK_EQ('"', c0_); | 808 DCHECK_EQ('"', c0_); |
809 // Advance past the last '"'. | 809 // Advance past the last '"'. |
810 AdvanceSkipWhitespace(); | 810 AdvanceSkipWhitespace(); |
811 return result; | 811 return result; |
812 } | 812 } |
813 | 813 |
814 } } // namespace v8::internal | 814 } } // namespace v8::internal |
815 | 815 |
816 #endif // V8_JSON_PARSER_H_ | 816 #endif // V8_JSON_PARSER_H_ |
OLD | NEW |