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 440 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
451 int count = end - start; | 451 int count = end - start; |
452 int max_length = count + source_length_ - position_; | 452 int max_length = count + source_length_ - position_; |
453 int length = Min(max_length, Max(kInitialSpecialStringLength, 2 * count)); | 453 int length = Min(max_length, Max(kInitialSpecialStringLength, 2 * count)); |
454 Handle<StringType> seq_str = NewRawString<StringType>(isolate()->factory(), | 454 Handle<StringType> seq_str = NewRawString<StringType>(isolate()->factory(), |
455 length); | 455 length); |
456 // Copy prefix into seq_str. | 456 // Copy prefix into seq_str. |
457 SinkChar* dest = seq_str->GetChars(); | 457 SinkChar* dest = seq_str->GetChars(); |
458 String::WriteToFlat(*prefix, dest, start, end); | 458 String::WriteToFlat(*prefix, dest, start, end); |
459 | 459 |
460 while (c0_ != '"') { | 460 while (c0_ != '"') { |
| 461 // Check for control character (0x00-0x1f) or unterminated string (<0). |
| 462 if (c0_ < 0x20) return Handle<String>::null(); |
461 if (count >= length) { | 463 if (count >= length) { |
462 // We need to create a longer sequential string for the result. | 464 // We need to create a longer sequential string for the result. |
463 return SlowScanJsonString<StringType, SinkChar>(seq_str, 0, count); | 465 return SlowScanJsonString<StringType, SinkChar>(seq_str, 0, count); |
464 } | 466 } |
465 // Check for control character (0x00-0x1f) or unterminated string (<0). | |
466 if (c0_ < 0x20) return Handle<String>::null(); | |
467 if (c0_ != '\\') { | 467 if (c0_ != '\\') { |
468 // If the sink can contain UC16 characters, or source_ contains only | 468 // If the sink can contain UC16 characters, or source_ contains only |
469 // ASCII characters, there's no need to test whether we can store the | 469 // ASCII characters, there's no need to test whether we can store the |
470 // character. Otherwise check whether the UC16 source character can fit | 470 // character. Otherwise check whether the UC16 source character can fit |
471 // in the ASCII sink. | 471 // in the ASCII sink. |
472 if (sizeof(SinkChar) == kUC16Size || | 472 if (sizeof(SinkChar) == kUC16Size || |
473 seq_ascii || | 473 seq_ascii || |
474 c0_ <= kMaxAsciiCharCode) { | 474 c0_ <= kMaxAsciiCharCode) { |
475 SeqStringSet(seq_str, count++, c0_); | 475 SeqStringSet(seq_str, count++, c0_); |
476 Advance(); | 476 Advance(); |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 } | 590 } |
591 ASSERT_EQ('"', c0_); | 591 ASSERT_EQ('"', c0_); |
592 // Advance past the last '"'. | 592 // Advance past the last '"'. |
593 AdvanceSkipWhitespace(); | 593 AdvanceSkipWhitespace(); |
594 return result; | 594 return result; |
595 } | 595 } |
596 | 596 |
597 } } // namespace v8::internal | 597 } } // namespace v8::internal |
598 | 598 |
599 #endif // V8_JSON_PARSER_H_ | 599 #endif // V8_JSON_PARSER_H_ |
OLD | NEW |