| OLD | NEW |
| 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 4503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4514 int dest_position = 0; | 4514 int dest_position = 0; |
| 4515 for (int i = 0; i < length; dest_position++) { | 4515 for (int i = 0; i < length; dest_position++) { |
| 4516 int step; | 4516 int step; |
| 4517 destination->Set(dest_position, Unescape(source, i, length, &step)); | 4517 destination->Set(dest_position, Unescape(source, i, length, &step)); |
| 4518 i += step; | 4518 i += step; |
| 4519 } | 4519 } |
| 4520 return destination; | 4520 return destination; |
| 4521 } | 4521 } |
| 4522 | 4522 |
| 4523 | 4523 |
| 4524 static const char* const JsonQuotes[128] = { | 4524 static const unsigned int kQuoteTableLength = 128u; |
| 4525 |
| 4526 static const char* const JsonQuotes[kQuoteTableLength] = { |
| 4525 "\\u0000", "\\u0001", "\\u0002", "\\u0003", | 4527 "\\u0000", "\\u0001", "\\u0002", "\\u0003", |
| 4526 "\\u0004", "\\u0005", "\\u0006", "\\u0007", | 4528 "\\u0004", "\\u0005", "\\u0006", "\\u0007", |
| 4527 "\\b", "\\t", "\\n", "\\u000b", | 4529 "\\b", "\\t", "\\n", "\\u000b", |
| 4528 "\\f", "\\r", "\\u000e", "\\u000f", | 4530 "\\f", "\\r", "\\u000e", "\\u000f", |
| 4529 "\\u0010", "\\u0011", "\\u0012", "\\u0013", | 4531 "\\u0010", "\\u0011", "\\u0012", "\\u0013", |
| 4530 "\\u0014", "\\u0015", "\\u0016", "\\u0017", | 4532 "\\u0014", "\\u0015", "\\u0016", "\\u0017", |
| 4531 "\\u0018", "\\u0019", "\\u001a", "\\u001b", | 4533 "\\u0018", "\\u0019", "\\u001a", "\\u001b", |
| 4532 "\\u001c", "\\u001d", "\\u001e", "\\u001f", | 4534 "\\u001c", "\\u001d", "\\u001e", "\\u001f", |
| 4533 NULL, NULL, "\\\"", NULL, | 4535 NULL, NULL, "\\\"", NULL, |
| 4534 NULL, NULL, NULL, NULL, | 4536 NULL, NULL, NULL, NULL, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 4550 NULL, NULL, NULL, NULL, | 4552 NULL, NULL, NULL, NULL, |
| 4551 NULL, NULL, NULL, NULL, | 4553 NULL, NULL, NULL, NULL, |
| 4552 NULL, NULL, NULL, NULL, | 4554 NULL, NULL, NULL, NULL, |
| 4553 NULL, NULL, NULL, NULL, | 4555 NULL, NULL, NULL, NULL, |
| 4554 NULL, NULL, NULL, NULL, | 4556 NULL, NULL, NULL, NULL, |
| 4555 NULL, NULL, NULL, NULL, | 4557 NULL, NULL, NULL, NULL, |
| 4556 NULL, NULL, NULL, NULL, | 4558 NULL, NULL, NULL, NULL, |
| 4557 }; | 4559 }; |
| 4558 | 4560 |
| 4559 | 4561 |
| 4560 static const byte JsonQuoteLengths[128] = { | 4562 static const byte JsonQuoteLengths[kQuoteTableLength] = { |
| 4561 6, 6, 6, 6, 6, 6, 6, 6, | 4563 6, 6, 6, 6, 6, 6, 6, 6, |
| 4562 2, 2, 2, 6, 2, 2, 6, 6, | 4564 2, 2, 2, 6, 2, 2, 6, 6, |
| 4563 6, 6, 6, 6, 6, 6, 6, 6, | 4565 6, 6, 6, 6, 6, 6, 6, 6, |
| 4564 6, 6, 6, 6, 6, 6, 6, 6, | 4566 6, 6, 6, 6, 6, 6, 6, 6, |
| 4565 1, 1, 2, 1, 1, 1, 1, 1, | 4567 1, 1, 2, 1, 1, 1, 1, 1, |
| 4566 1, 1, 1, 1, 1, 1, 1, 1, | 4568 1, 1, 1, 1, 1, 1, 1, 1, |
| 4567 1, 1, 1, 1, 1, 1, 1, 1, | 4569 1, 1, 1, 1, 1, 1, 1, 1, |
| 4568 1, 1, 1, 1, 1, 1, 1, 1, | 4570 1, 1, 1, 1, 1, 1, 1, 1, |
| 4569 1, 1, 1, 1, 1, 1, 1, 1, | 4571 1, 1, 1, 1, 1, 1, 1, 1, |
| 4570 1, 1, 1, 1, 1, 1, 1, 1, | 4572 1, 1, 1, 1, 1, 1, 1, 1, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 4599 } | 4601 } |
| 4600 | 4602 |
| 4601 | 4603 |
| 4602 template <> | 4604 template <> |
| 4603 MaybeObject* AllocateRawString<SeqAsciiString>(int length) { | 4605 MaybeObject* AllocateRawString<SeqAsciiString>(int length) { |
| 4604 return Heap::AllocateRawAsciiString(length); | 4606 return Heap::AllocateRawAsciiString(length); |
| 4605 } | 4607 } |
| 4606 | 4608 |
| 4607 | 4609 |
| 4608 template <typename Char, typename StringType> | 4610 template <typename Char, typename StringType> |
| 4609 static MaybeObject* QuoteJsonString(String* original, | 4611 static MaybeObject* QuoteJsonString(Vector<const Char> characters) { |
| 4610 Vector<const Char> characters) { | |
| 4611 int length = characters.length(); | 4612 int length = characters.length(); |
| 4612 int quoted_length = 0; | 4613 int quoted_length = 0; |
| 4613 for (int i = 0; i < length; i++) { | 4614 for (int i = 0; i < length; i++) { |
| 4614 unsigned int c = characters[i]; | 4615 unsigned int c = characters[i]; |
| 4615 if (sizeof(Char) > 1u) { | 4616 if (sizeof(Char) > 1u) { |
| 4616 quoted_length += | 4617 quoted_length += (c >= kQuoteTableLength) ? 1 : JsonQuoteLengths[c]; |
| 4617 (c >= sizeof(JsonQuoteLengths)) ? 1 : JsonQuoteLengths[c]; | |
| 4618 } else { | 4618 } else { |
| 4619 quoted_length += JsonQuoteLengths[c]; | 4619 quoted_length += JsonQuoteLengths[c]; |
| 4620 } | 4620 } |
| 4621 } | 4621 } |
| 4622 if (quoted_length == length) { | 4622 if (quoted_length == length) { |
| 4623 return Heap::undefined_value(); | 4623 return Heap::undefined_value(); |
| 4624 } | 4624 } |
| 4625 Counters::quote_json_char_count.Increment(length); | 4625 Counters::quote_json_char_count.Increment(length); |
| 4626 | 4626 |
| 4627 // Add space for quotes. | 4627 // Add space for quotes. |
| 4628 quoted_length += 2; | 4628 quoted_length += 2; |
| 4629 | 4629 |
| 4630 MaybeObject* new_alloc = AllocateRawString<StringType>(quoted_length); | 4630 MaybeObject* new_alloc = AllocateRawString<StringType>(quoted_length); |
| 4631 Object* new_object; | 4631 Object* new_object; |
| 4632 if (!new_alloc->ToObject(&new_object)) { | 4632 if (!new_alloc->ToObject(&new_object)) { |
| 4633 Counters::quote_json_char_recount.Increment(length); | 4633 Counters::quote_json_char_recount.Increment(length); |
| 4634 return new_alloc; | 4634 return new_alloc; |
| 4635 } | 4635 } |
| 4636 StringType* new_string = StringType::cast(new_object); | 4636 StringType* new_string = StringType::cast(new_object); |
| 4637 | 4637 |
| 4638 | 4638 |
| 4639 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqAsciiString::kHeaderSize); | 4639 STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqAsciiString::kHeaderSize); |
| 4640 Char* write_cursor = reinterpret_cast<Char*>( | 4640 Char* write_cursor = reinterpret_cast<Char*>( |
| 4641 new_string->address() + SeqAsciiString::kHeaderSize); | 4641 new_string->address() + SeqAsciiString::kHeaderSize); |
| 4642 *(write_cursor++) = '"'; | 4642 *(write_cursor++) = '"'; |
| 4643 const Char* read_cursor = characters.start(); | 4643 const Char* read_cursor = characters.start(); |
| 4644 const Char* end = read_cursor + length; | 4644 const Char* end = read_cursor + length; |
| 4645 while (read_cursor < end) { | 4645 while (read_cursor < end) { |
| 4646 Char c = *(read_cursor++); | 4646 Char c = *(read_cursor++); |
| 4647 if (sizeof(Char) > 1u && static_cast<unsigned>(c) >= sizeof(JsonQuotes)) { | 4647 if (sizeof(Char) > 1u && static_cast<unsigned>(c) >= kQuoteTableLength) { |
| 4648 *(write_cursor++) = c; | 4648 *(write_cursor++) = c; |
| 4649 } else { | 4649 } else { |
| 4650 const char* replacement = JsonQuotes[static_cast<unsigned>(c)]; | 4650 const char* replacement = JsonQuotes[static_cast<unsigned>(c)]; |
| 4651 if (!replacement) { | 4651 if (!replacement) { |
| 4652 *(write_cursor++) = c; | 4652 *(write_cursor++) = c; |
| 4653 } else { | 4653 } else { |
| 4654 write_cursor = WriteString(write_cursor, replacement); | 4654 write_cursor = WriteString(write_cursor, replacement); |
| 4655 } | 4655 } |
| 4656 } | 4656 } |
| 4657 } | 4657 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 4668 if (!str->IsFlat()) { | 4668 if (!str->IsFlat()) { |
| 4669 MaybeObject* try_flatten = str->TryFlatten(); | 4669 MaybeObject* try_flatten = str->TryFlatten(); |
| 4670 Object* flat; | 4670 Object* flat; |
| 4671 if (!try_flatten->ToObject(&flat)) { | 4671 if (!try_flatten->ToObject(&flat)) { |
| 4672 return try_flatten; | 4672 return try_flatten; |
| 4673 } | 4673 } |
| 4674 str = String::cast(flat); | 4674 str = String::cast(flat); |
| 4675 ASSERT(str->IsFlat()); | 4675 ASSERT(str->IsFlat()); |
| 4676 } | 4676 } |
| 4677 if (str->IsTwoByteRepresentation()) { | 4677 if (str->IsTwoByteRepresentation()) { |
| 4678 return QuoteJsonString<uc16, SeqTwoByteString>(str, str->ToUC16Vector()); | 4678 return QuoteJsonString<uc16, SeqTwoByteString>(str->ToUC16Vector()); |
| 4679 } else { | 4679 } else { |
| 4680 return QuoteJsonString<char, SeqAsciiString>(str, str->ToAsciiVector()); | 4680 return QuoteJsonString<char, SeqAsciiString>(str->ToAsciiVector()); |
| 4681 } | 4681 } |
| 4682 } | 4682 } |
| 4683 | 4683 |
| 4684 | 4684 |
| 4685 static MaybeObject* Runtime_StringParseInt(Arguments args) { | 4685 static MaybeObject* Runtime_StringParseInt(Arguments args) { |
| 4686 NoHandleAllocation ha; | 4686 NoHandleAllocation ha; |
| 4687 | 4687 |
| 4688 CONVERT_CHECKED(String, s, args[0]); | 4688 CONVERT_CHECKED(String, s, args[0]); |
| 4689 CONVERT_SMI_CHECKED(radix, args[1]); | 4689 CONVERT_SMI_CHECKED(radix, args[1]); |
| 4690 | 4690 |
| (...skipping 5792 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10483 } else { | 10483 } else { |
| 10484 // Handle last resort GC and make sure to allow future allocations | 10484 // Handle last resort GC and make sure to allow future allocations |
| 10485 // to grow the heap without causing GCs (if possible). | 10485 // to grow the heap without causing GCs (if possible). |
| 10486 Counters::gc_last_resort_from_js.Increment(); | 10486 Counters::gc_last_resort_from_js.Increment(); |
| 10487 Heap::CollectAllGarbage(false); | 10487 Heap::CollectAllGarbage(false); |
| 10488 } | 10488 } |
| 10489 } | 10489 } |
| 10490 | 10490 |
| 10491 | 10491 |
| 10492 } } // namespace v8::internal | 10492 } } // namespace v8::internal |
| OLD | NEW |