OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "vm/dart_api_message.h" | 5 #include "vm/dart_api_message.h" |
6 #include "vm/object.h" | 6 #include "vm/object.h" |
7 #include "vm/snapshot_ids.h" | 7 #include "vm/snapshot_ids.h" |
8 #include "vm/symbols.h" | 8 #include "vm/symbols.h" |
9 #include "vm/unicode.h" | 9 #include "vm/unicode.h" |
10 | 10 |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 object->value.as_bigint.digits = digits; | 635 object->value.as_bigint.digits = digits; |
636 return object; | 636 return object; |
637 } | 637 } |
638 case kDoubleCid: { | 638 case kDoubleCid: { |
639 // Doubles are handled specially when being sent as part of message | 639 // Doubles are handled specially when being sent as part of message |
640 // snapshots. | 640 // snapshots. |
641 UNREACHABLE(); | 641 UNREACHABLE(); |
642 } | 642 } |
643 case kOneByteStringCid: { | 643 case kOneByteStringCid: { |
644 intptr_t len = ReadSmiValue(); | 644 intptr_t len = ReadSmiValue(); |
645 intptr_t hash = ReadSmiValue(); | |
646 USE(hash); | |
647 uint8_t *latin1 = | 645 uint8_t *latin1 = |
648 reinterpret_cast<uint8_t*>(allocator(len * sizeof(uint8_t))); | 646 reinterpret_cast<uint8_t*>(allocator(len * sizeof(uint8_t))); |
649 intptr_t utf8_len = 0; | 647 intptr_t utf8_len = 0; |
650 for (intptr_t i = 0; i < len; i++) { | 648 for (intptr_t i = 0; i < len; i++) { |
651 latin1[i] = Read<uint8_t>(); | 649 latin1[i] = Read<uint8_t>(); |
652 utf8_len += Utf8::Length(latin1[i]); | 650 utf8_len += Utf8::Length(latin1[i]); |
653 } | 651 } |
654 Dart_CObject* object = AllocateDartCObjectString(utf8_len); | 652 Dart_CObject* object = AllocateDartCObjectString(utf8_len); |
655 AddBackRef(object_id, object, kIsDeserialized); | 653 AddBackRef(object_id, object, kIsDeserialized); |
656 char* p = object->value.as_string; | 654 char* p = object->value.as_string; |
657 for (intptr_t i = 0; i < len; i++) { | 655 for (intptr_t i = 0; i < len; i++) { |
658 p += Utf8::Encode(latin1[i], p); | 656 p += Utf8::Encode(latin1[i], p); |
659 } | 657 } |
660 *p = '\0'; | 658 *p = '\0'; |
661 ASSERT(p == (object->value.as_string + utf8_len)); | 659 ASSERT(p == (object->value.as_string + utf8_len)); |
662 return object; | 660 return object; |
663 } | 661 } |
664 case kTwoByteStringCid: { | 662 case kTwoByteStringCid: { |
665 intptr_t len = ReadSmiValue(); | 663 intptr_t len = ReadSmiValue(); |
666 intptr_t hash = ReadSmiValue(); | |
667 USE(hash); | |
668 uint16_t *utf16 = reinterpret_cast<uint16_t*>( | 664 uint16_t *utf16 = reinterpret_cast<uint16_t*>( |
669 allocator(len * sizeof(uint16_t))); | 665 allocator(len * sizeof(uint16_t))); |
670 intptr_t utf8_len = 0; | 666 intptr_t utf8_len = 0; |
671 // Read all the UTF-16 code units. | 667 // Read all the UTF-16 code units. |
672 for (intptr_t i = 0; i < len; i++) { | 668 for (intptr_t i = 0; i < len; i++) { |
673 utf16[i] = Read<uint16_t>(); | 669 utf16[i] = Read<uint16_t>(); |
674 } | 670 } |
675 // Calculate the UTF-8 length and check if the string can be | 671 // Calculate the UTF-8 length and check if the string can be |
676 // UTF-8 encoded. | 672 // UTF-8 encoded. |
677 bool valid = true; | 673 bool valid = true; |
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1196 if (len > String::kMaxElements) { | 1192 if (len > String::kMaxElements) { |
1197 return false; | 1193 return false; |
1198 } | 1194 } |
1199 | 1195 |
1200 // Write out the serialization header value for this object. | 1196 // Write out the serialization header value for this object. |
1201 WriteInlinedHeader(object); | 1197 WriteInlinedHeader(object); |
1202 // Write out the class and tags information. | 1198 // Write out the class and tags information. |
1203 WriteIndexedObject(type == Utf8::kLatin1 ? kOneByteStringCid | 1199 WriteIndexedObject(type == Utf8::kLatin1 ? kOneByteStringCid |
1204 : kTwoByteStringCid); | 1200 : kTwoByteStringCid); |
1205 WriteTags(0); | 1201 WriteTags(0); |
1206 // Write string length, hash and content | 1202 // Write string length and content. |
1207 WriteSmi(len); | 1203 WriteSmi(len); |
1208 WriteSmi(0); // TODO(sgjesse): Hash - not written. | |
1209 if (type == Utf8::kLatin1) { | 1204 if (type == Utf8::kLatin1) { |
1210 uint8_t* latin1_str = | 1205 uint8_t* latin1_str = |
1211 reinterpret_cast<uint8_t*>(::malloc(len * sizeof(uint8_t))); | 1206 reinterpret_cast<uint8_t*>(::malloc(len * sizeof(uint8_t))); |
1212 bool success = Utf8::DecodeToLatin1(utf8_str, | 1207 bool success = Utf8::DecodeToLatin1(utf8_str, |
1213 utf8_len, | 1208 utf8_len, |
1214 latin1_str, | 1209 latin1_str, |
1215 len); | 1210 len); |
1216 ASSERT(success); | 1211 ASSERT(success); |
1217 for (intptr_t i = 0; i < len; i++) { | 1212 for (intptr_t i = 0; i < len; i++) { |
1218 Write<uint8_t>(latin1_str[i]); | 1213 Write<uint8_t>(latin1_str[i]); |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1337 if (!success) { | 1332 if (!success) { |
1338 UnmarkAllCObjects(object); | 1333 UnmarkAllCObjects(object); |
1339 return false; | 1334 return false; |
1340 } | 1335 } |
1341 } | 1336 } |
1342 UnmarkAllCObjects(object); | 1337 UnmarkAllCObjects(object); |
1343 return true; | 1338 return true; |
1344 } | 1339 } |
1345 | 1340 |
1346 } // namespace dart | 1341 } // namespace dart |
OLD | NEW |