| OLD | NEW | 
|---|
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. | 
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without | 
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are | 
| 4 // met: | 4 // met: | 
| 5 // | 5 // | 
| 6 //     * Redistributions of source code must retain the above copyright | 6 //     * Redistributions of source code must retain the above copyright | 
| 7 //       notice, this list of conditions and the following disclaimer. | 7 //       notice, this list of conditions and the following disclaimer. | 
| 8 //     * Redistributions in binary form must reproduce the above | 8 //     * Redistributions in binary form must reproduce the above | 
| 9 //       copyright notice, this list of conditions and the following | 9 //       copyright notice, this list of conditions and the following | 
| 10 //       disclaimer in the documentation and/or other materials provided | 10 //       disclaimer in the documentation and/or other materials provided | 
| (...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 519       // We need to create a longer sequential string for the result. | 519       // We need to create a longer sequential string for the result. | 
| 520       return SlowScanJsonString<StringType, SinkChar>(seq_str, 0, count); | 520       return SlowScanJsonString<StringType, SinkChar>(seq_str, 0, count); | 
| 521     } | 521     } | 
| 522     if (c0_ != '\\') { | 522     if (c0_ != '\\') { | 
| 523       // If the sink can contain UC16 characters, or source_ contains only | 523       // If the sink can contain UC16 characters, or source_ contains only | 
| 524       // ASCII characters, there's no need to test whether we can store the | 524       // ASCII characters, there's no need to test whether we can store the | 
| 525       // character. Otherwise check whether the UC16 source character can fit | 525       // character. Otherwise check whether the UC16 source character can fit | 
| 526       // in the ASCII sink. | 526       // in the ASCII sink. | 
| 527       if (sizeof(SinkChar) == kUC16Size || | 527       if (sizeof(SinkChar) == kUC16Size || | 
| 528           seq_ascii || | 528           seq_ascii || | 
| 529           c0_ <= kMaxAsciiCharCode) { | 529           c0_ <= String::kMaxOneByteCharCode) { | 
| 530         SeqStringSet(seq_str, count++, c0_); | 530         SeqStringSet(seq_str, count++, c0_); | 
| 531         Advance(); | 531         Advance(); | 
| 532       } else { | 532       } else { | 
| 533         // StringType is SeqOneByteString and we just read a non-ASCII char. | 533         // StringType is SeqOneByteString and we just read a non-ASCII char. | 
| 534         return SlowScanJsonString<SeqTwoByteString, uc16>(seq_str, 0, count); | 534         return SlowScanJsonString<SeqTwoByteString, uc16>(seq_str, 0, count); | 
| 535       } | 535       } | 
| 536     } else { | 536     } else { | 
| 537       Advance();  // Advance past the \. | 537       Advance();  // Advance past the \. | 
| 538       switch (c0_) { | 538       switch (c0_) { | 
| 539         case '"': | 539         case '"': | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
| 559         case 'u': { | 559         case 'u': { | 
| 560           uc32 value = 0; | 560           uc32 value = 0; | 
| 561           for (int i = 0; i < 4; i++) { | 561           for (int i = 0; i < 4; i++) { | 
| 562             Advance(); | 562             Advance(); | 
| 563             int digit = HexValue(c0_); | 563             int digit = HexValue(c0_); | 
| 564             if (digit < 0) { | 564             if (digit < 0) { | 
| 565               return Handle<String>::null(); | 565               return Handle<String>::null(); | 
| 566             } | 566             } | 
| 567             value = value * 16 + digit; | 567             value = value * 16 + digit; | 
| 568           } | 568           } | 
| 569           if (sizeof(SinkChar) == kUC16Size || value <= kMaxAsciiCharCode) { | 569           if (sizeof(SinkChar) == kUC16Size || | 
|  | 570               value <= String::kMaxOneByteCharCode) { | 
| 570             SeqStringSet(seq_str, count++, value); | 571             SeqStringSet(seq_str, count++, value); | 
| 571             break; | 572             break; | 
| 572           } else { | 573           } else { | 
| 573             // StringType is SeqOneByteString and we just read a non-ASCII char. | 574             // StringType is SeqOneByteString and we just read a non-ASCII char. | 
| 574             position_ -= 6;  // Rewind position_ to \ in \uxxxx. | 575             position_ -= 6;  // Rewind position_ to \ in \uxxxx. | 
| 575             Advance(); | 576             Advance(); | 
| 576             return SlowScanJsonString<SeqTwoByteString, uc16>(seq_str, | 577             return SlowScanJsonString<SeqTwoByteString, uc16>(seq_str, | 
| 577                                                               0, | 578                                                               0, | 
| 578                                                               count); | 579                                                               count); | 
| 579           } | 580           } | 
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 642       } else { | 643       } else { | 
| 643         running_hash = StringHasher::AddCharacterCore(running_hash, c0); | 644         running_hash = StringHasher::AddCharacterCore(running_hash, c0); | 
| 644       } | 645       } | 
| 645       position++; | 646       position++; | 
| 646       if (position >= source_length_) return Handle<String>::null(); | 647       if (position >= source_length_) return Handle<String>::null(); | 
| 647       c0 = seq_source_->SeqOneByteStringGet(position); | 648       c0 = seq_source_->SeqOneByteStringGet(position); | 
| 648     } while (c0 != '"'); | 649     } while (c0 != '"'); | 
| 649     int length = position - position_; | 650     int length = position - position_; | 
| 650     uint32_t hash = (length <= String::kMaxHashCalcLength) | 651     uint32_t hash = (length <= String::kMaxHashCalcLength) | 
| 651         ? StringHasher::GetHashCore(running_hash) : length; | 652         ? StringHasher::GetHashCore(running_hash) : length; | 
| 652     Vector<const char> string_vector( | 653     Vector<const uint8_t> string_vector( | 
| 653         seq_source_->GetChars() + position_, length); | 654         seq_source_->GetCharsU() + position_, length); | 
| 654     SymbolTable* symbol_table = isolate()->heap()->symbol_table(); | 655     SymbolTable* symbol_table = isolate()->heap()->symbol_table(); | 
| 655     uint32_t capacity = symbol_table->Capacity(); | 656     uint32_t capacity = symbol_table->Capacity(); | 
| 656     uint32_t entry = SymbolTable::FirstProbe(hash, capacity); | 657     uint32_t entry = SymbolTable::FirstProbe(hash, capacity); | 
| 657     uint32_t count = 1; | 658     uint32_t count = 1; | 
| 658     while (true) { | 659     while (true) { | 
| 659       Object* element = symbol_table->KeyAt(entry); | 660       Object* element = symbol_table->KeyAt(entry); | 
| 660       if (element == isolate()->heap()->undefined_value()) { | 661       if (element == isolate()->heap()->undefined_value()) { | 
| 661         // Lookup failure. | 662         // Lookup failure. | 
| 662         break; | 663         break; | 
| 663       } | 664       } | 
| 664       if (element != isolate()->heap()->the_hole_value() && | 665       if (element != isolate()->heap()->the_hole_value() && | 
| 665           String::cast(element)->IsAsciiEqualTo(string_vector)) { | 666           String::cast(element)->IsOneByteEqualTo(string_vector)) { | 
| 666         // Lookup success, update the current position. | 667         // Lookup success, update the current position. | 
| 667         position_ = position; | 668         position_ = position; | 
| 668         // Advance past the last '"'. | 669         // Advance past the last '"'. | 
| 669         AdvanceSkipWhitespace(); | 670         AdvanceSkipWhitespace(); | 
| 670         return Handle<String>(String::cast(element), isolate()); | 671         return Handle<String>(String::cast(element), isolate()); | 
| 671       } | 672       } | 
| 672       entry = SymbolTable::NextProbe(entry, count++, capacity); | 673       entry = SymbolTable::NextProbe(entry, count++, capacity); | 
| 673     } | 674     } | 
| 674   } | 675   } | 
| 675 | 676 | 
| 676   int beg_pos = position_; | 677   int beg_pos = position_; | 
| 677   // Fast case for ASCII only without escape characters. | 678   // Fast case for ASCII only without escape characters. | 
| 678   do { | 679   do { | 
| 679     // Check for control character (0x00-0x1f) or unterminated string (<0). | 680     // Check for control character (0x00-0x1f) or unterminated string (<0). | 
| 680     if (c0_ < 0x20) return Handle<String>::null(); | 681     if (c0_ < 0x20) return Handle<String>::null(); | 
| 681     if (c0_ != '\\') { | 682     if (c0_ != '\\') { | 
| 682       if (seq_ascii || c0_ <= kMaxAsciiCharCode) { | 683       if (seq_ascii || c0_ <= String::kMaxOneByteCharCode) { | 
| 683         Advance(); | 684         Advance(); | 
| 684       } else { | 685       } else { | 
| 685         return SlowScanJsonString<SeqTwoByteString, uc16>(source_, | 686         return SlowScanJsonString<SeqTwoByteString, uc16>(source_, | 
| 686                                                           beg_pos, | 687                                                           beg_pos, | 
| 687                                                           position_); | 688                                                           position_); | 
| 688       } | 689       } | 
| 689     } else { | 690     } else { | 
| 690       return SlowScanJsonString<SeqOneByteString, char>(source_, | 691       return SlowScanJsonString<SeqOneByteString, char>(source_, | 
| 691                                                       beg_pos, | 692                                                       beg_pos, | 
| 692                                                       position_); | 693                                                       position_); | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
| 703   } | 704   } | 
| 704   ASSERT_EQ('"', c0_); | 705   ASSERT_EQ('"', c0_); | 
| 705   // Advance past the last '"'. | 706   // Advance past the last '"'. | 
| 706   AdvanceSkipWhitespace(); | 707   AdvanceSkipWhitespace(); | 
| 707   return result; | 708   return result; | 
| 708 } | 709 } | 
| 709 | 710 | 
| 710 } }  // namespace v8::internal | 711 } }  // namespace v8::internal | 
| 711 | 712 | 
| 712 #endif  // V8_JSON_PARSER_H_ | 713 #endif  // V8_JSON_PARSER_H_ | 
| OLD | NEW | 
|---|