| 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/object_store.h" | 7 #include "vm/object_store.h" |
| 8 | 8 |
| 9 namespace dart { | 9 namespace dart { |
| 10 | 10 |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 | 175 |
| 176 ASSERT((class_header & kSmiTagMask) != 0); | 176 ASSERT((class_header & kSmiTagMask) != 0); |
| 177 class_id = LookupInternalClass(class_header); | 177 class_id = LookupInternalClass(class_header); |
| 178 switch (class_id) { | 178 switch (class_id) { |
| 179 case Object::kClassClass: { | 179 case Object::kClassClass: { |
| 180 return NULL; | 180 return NULL; |
| 181 } | 181 } |
| 182 case Object::kTypeArgumentsClass: { | 182 case Object::kTypeArgumentsClass: { |
| 183 // TODO(sjesse): Remove this when message serialization format is | 183 // TODO(sjesse): Remove this when message serialization format is |
| 184 // updated (currently length is leaked). | 184 // updated (currently length is leaked). |
| 185 AddBackwardReference(object_id, NULL); | 185 Dart_CObject* value = &type_arguments_marker; |
| 186 AddBackwardReference(object_id, value); |
| 186 Dart_CObject* length = ReadObject(); | 187 Dart_CObject* length = ReadObject(); |
| 187 ASSERT(length->type == Dart_CObject::kInt32); | 188 ASSERT(length->type == Dart_CObject::kInt32); |
| 188 for (int i = 0; i < length->value.as_int32; i++) { | 189 for (int i = 0; i < length->value.as_int32; i++) { |
| 189 Dart_CObject* type = ReadObject(); | 190 Dart_CObject* type = ReadObject(); |
| 190 if (type != &dynamic_type_marker) return NULL; | 191 if (type != &dynamic_type_marker) { |
| 192 return NULL; |
| 193 } |
| 191 } | 194 } |
| 192 return &type_arguments_marker; | 195 return value; |
| 193 } | 196 } |
| 194 case ObjectStore::kArrayClass: { | 197 case ObjectStore::kArrayClass: { |
| 195 intptr_t len = ReadSmiValue(); | 198 intptr_t len = ReadSmiValue(); |
| 196 Dart_CObject* value = AllocateDartCObjectArray(len); | 199 Dart_CObject* value = AllocateDartCObjectArray(len); |
| 197 AddBackwardReference(object_id, value); | 200 AddBackwardReference(object_id, value); |
| 198 // Skip type arguments. | 201 // Skip type arguments. |
| 199 // TODO(sjesse): Remove this when message serialization format is | 202 // TODO(sjesse): Remove this when message serialization format is |
| 200 // updated (currently type_arguments is leaked). | 203 // updated (currently type_arguments is leaked). |
| 201 Dart_CObject* type_arguments = ReadObject(); | 204 Dart_CObject* type_arguments = ReadObject(); |
| 202 if (type_arguments != &type_arguments_marker && | 205 if (type_arguments != &type_arguments_marker && |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 return ReadIndexedObject(header_value); | 311 return ReadIndexedObject(header_value); |
| 309 } | 312 } |
| 310 ASSERT(header_type == kInlined); | 313 ASSERT(header_type == kInlined); |
| 311 return ReadInlinedObject(header_value); | 314 return ReadInlinedObject(header_value); |
| 312 } | 315 } |
| 313 | 316 |
| 314 | 317 |
| 315 Dart_CObject* ApiMessageReader::ReadObject() { | 318 Dart_CObject* ApiMessageReader::ReadObject() { |
| 316 int64_t value = Read<int64_t>(); | 319 int64_t value = Read<int64_t>(); |
| 317 if ((value & kSmiTagMask) == 0) { | 320 if ((value & kSmiTagMask) == 0) { |
| 318 Dart_CObject* dart_value = AllocateDartCObjectInt32(value >> kSmiTagShift); | 321 int64_t untagged_value = value >> kSmiTagShift; |
| 319 return dart_value; | 322 if (kMinInt32 <= untagged_value && untagged_value <= kMaxInt32) { |
| 323 return AllocateDartCObjectInt32(untagged_value); |
| 324 } else { |
| 325 return AllocateDartCObjectInt64(untagged_value); |
| 326 } |
| 320 } | 327 } |
| 321 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin)); | 328 ASSERT((value <= kIntptrMax) && (value >= kIntptrMin)); |
| 322 return ReadObjectImpl(value); | 329 return ReadObjectImpl(value); |
| 323 } | 330 } |
| 324 | 331 |
| 325 | 332 |
| 326 void ApiMessageReader::AddBackwardReference(intptr_t id, Dart_CObject* obj) { | 333 void ApiMessageReader::AddBackwardReference(intptr_t id, Dart_CObject* obj) { |
| 327 ASSERT((id - kMaxPredefinedObjectIds) == backward_references_.length()); | 334 ASSERT((id - kMaxPredefinedObjectIds) == backward_references_.length()); |
| 328 backward_references_.Add(obj); | 335 backward_references_.Add(obj); |
| 329 } | 336 } |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 } | 541 } |
| 535 | 542 |
| 536 | 543 |
| 537 void ApiMessageWriter::WriteCMessage(Dart_CObject* object) { | 544 void ApiMessageWriter::WriteCMessage(Dart_CObject* object) { |
| 538 WriteCObject(object); | 545 WriteCObject(object); |
| 539 UnmarkAllCObjects(object); | 546 UnmarkAllCObjects(object); |
| 540 FinalizeBuffer(); | 547 FinalizeBuffer(); |
| 541 } | 548 } |
| 542 | 549 |
| 543 } // namespace dart | 550 } // namespace dart |
| OLD | NEW |