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/object.h" | 5 #include "vm/object.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
10 #include "vm/cpu.h" | 10 #include "vm/cpu.h" |
(...skipping 20025 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20036 | 20036 |
20037 void Array::PrintJSONImpl(JSONStream* stream, bool ref) const { | 20037 void Array::PrintJSONImpl(JSONStream* stream, bool ref) const { |
20038 JSONObject jsobj(stream); | 20038 JSONObject jsobj(stream); |
20039 PrintSharedInstanceJSON(&jsobj, ref); | 20039 PrintSharedInstanceJSON(&jsobj, ref); |
20040 jsobj.AddProperty("kind", "List"); | 20040 jsobj.AddProperty("kind", "List"); |
20041 jsobj.AddServiceId(*this); | 20041 jsobj.AddServiceId(*this); |
20042 jsobj.AddProperty("length", Length()); | 20042 jsobj.AddProperty("length", Length()); |
20043 if (ref) { | 20043 if (ref) { |
20044 return; | 20044 return; |
20045 } | 20045 } |
| 20046 intptr_t offset; |
| 20047 intptr_t count; |
| 20048 stream->ComputeOffsetAndCount(Length(), &offset, &count); |
| 20049 if (offset > 0) { |
| 20050 jsobj.AddProperty("offset", offset); |
| 20051 } |
| 20052 if (count < Length()) { |
| 20053 jsobj.AddProperty("count", count); |
| 20054 } |
| 20055 intptr_t limit = offset + count; |
| 20056 ASSERT(limit <= Length()); |
20046 { | 20057 { |
20047 JSONArray jsarr(&jsobj, "elements"); | 20058 JSONArray jsarr(&jsobj, "elements"); |
20048 Object& element = Object::Handle(); | 20059 Object& element = Object::Handle(); |
20049 for (intptr_t index = 0; index < Length(); index++) { | 20060 for (intptr_t index = offset; index < limit; index++) { |
20050 element = At(index); | 20061 element = At(index); |
20051 jsarr.AddValue(element); | 20062 jsarr.AddValue(element); |
20052 } | 20063 } |
20053 } | 20064 } |
20054 } | 20065 } |
20055 | 20066 |
20056 | 20067 |
20057 RawArray* Array::Grow(const Array& source, | 20068 RawArray* Array::Grow(const Array& source, |
20058 intptr_t new_length, | 20069 intptr_t new_length, |
20059 Heap::Space space) { | 20070 Heap::Space space) { |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20274 void GrowableObjectArray::PrintJSONImpl(JSONStream* stream, | 20285 void GrowableObjectArray::PrintJSONImpl(JSONStream* stream, |
20275 bool ref) const { | 20286 bool ref) const { |
20276 JSONObject jsobj(stream); | 20287 JSONObject jsobj(stream); |
20277 PrintSharedInstanceJSON(&jsobj, ref); | 20288 PrintSharedInstanceJSON(&jsobj, ref); |
20278 jsobj.AddProperty("kind", "List"); | 20289 jsobj.AddProperty("kind", "List"); |
20279 jsobj.AddServiceId(*this); | 20290 jsobj.AddServiceId(*this); |
20280 jsobj.AddProperty("length", Length()); | 20291 jsobj.AddProperty("length", Length()); |
20281 if (ref) { | 20292 if (ref) { |
20282 return; | 20293 return; |
20283 } | 20294 } |
| 20295 intptr_t offset; |
| 20296 intptr_t count; |
| 20297 stream->ComputeOffsetAndCount(Length(), &offset, &count); |
| 20298 if (offset > 0) { |
| 20299 jsobj.AddProperty("offset", offset); |
| 20300 } |
| 20301 if (count < Length()) { |
| 20302 jsobj.AddProperty("count", count); |
| 20303 } |
| 20304 intptr_t limit = offset + count; |
| 20305 ASSERT(limit <= Length()); |
20284 { | 20306 { |
20285 JSONArray jsarr(&jsobj, "elements"); | 20307 JSONArray jsarr(&jsobj, "elements"); |
20286 Object& element = Object::Handle(); | 20308 Object& element = Object::Handle(); |
20287 for (intptr_t index = 0; index < Length(); index++) { | 20309 for (intptr_t index = offset; index < limit; index++) { |
20288 element = At(index); | 20310 element = At(index); |
20289 jsarr.AddValue(element); | 20311 jsarr.AddValue(element); |
20290 } | 20312 } |
20291 } | 20313 } |
20292 } | 20314 } |
20293 | 20315 |
20294 | 20316 |
20295 // Equivalent to Dart's operator "==" and hashCode. | 20317 // Equivalent to Dart's operator "==" and hashCode. |
20296 class DefaultHashTraits { | 20318 class DefaultHashTraits { |
20297 public: | 20319 public: |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20380 | 20402 |
20381 void LinkedHashMap::PrintJSONImpl(JSONStream* stream, bool ref) const { | 20403 void LinkedHashMap::PrintJSONImpl(JSONStream* stream, bool ref) const { |
20382 JSONObject jsobj(stream); | 20404 JSONObject jsobj(stream); |
20383 PrintSharedInstanceJSON(&jsobj, ref); | 20405 PrintSharedInstanceJSON(&jsobj, ref); |
20384 jsobj.AddProperty("kind", "Map"); | 20406 jsobj.AddProperty("kind", "Map"); |
20385 jsobj.AddServiceId(*this); | 20407 jsobj.AddServiceId(*this); |
20386 jsobj.AddProperty("length", Length()); | 20408 jsobj.AddProperty("length", Length()); |
20387 if (ref) { | 20409 if (ref) { |
20388 return; | 20410 return; |
20389 } | 20411 } |
| 20412 intptr_t offset; |
| 20413 intptr_t count; |
| 20414 stream->ComputeOffsetAndCount(Length(), &offset, &count); |
| 20415 if (offset > 0) { |
| 20416 jsobj.AddProperty("offset", offset); |
| 20417 } |
| 20418 if (count < Length()) { |
| 20419 jsobj.AddProperty("count", count); |
| 20420 } |
| 20421 intptr_t limit = offset + count; |
| 20422 ASSERT(limit <= Length()); |
20390 { | 20423 { |
20391 JSONArray jsarr(&jsobj, "associations"); | 20424 JSONArray jsarr(&jsobj, "associations"); |
20392 Object& object = Object::Handle(); | 20425 Object& object = Object::Handle(); |
20393 LinkedHashMap::Iterator iterator(*this); | 20426 LinkedHashMap::Iterator iterator(*this); |
20394 while (iterator.MoveNext()) { | 20427 int i = 0; |
20395 JSONObject jsassoc(&jsarr); | 20428 while (iterator.MoveNext() && i < limit) { |
20396 object = iterator.CurrentKey(); | 20429 if (i >= offset) { |
20397 jsassoc.AddProperty("key", object); | 20430 JSONObject jsassoc(&jsarr); |
20398 object = iterator.CurrentValue(); | 20431 object = iterator.CurrentKey(); |
20399 jsassoc.AddProperty("value", object); | 20432 jsassoc.AddProperty("key", object); |
| 20433 object = iterator.CurrentValue(); |
| 20434 jsassoc.AddProperty("value", object); |
| 20435 } |
| 20436 i++; |
20400 } | 20437 } |
20401 } | 20438 } |
20402 } | 20439 } |
20403 | 20440 |
20404 | 20441 |
20405 RawFloat32x4* Float32x4::New(float v0, float v1, float v2, float v3, | 20442 RawFloat32x4* Float32x4::New(float v0, float v1, float v2, float v3, |
20406 Heap::Space space) { | 20443 Heap::Space space) { |
20407 ASSERT(Isolate::Current()->object_store()->float32x4_class() != | 20444 ASSERT(Isolate::Current()->object_store()->float32x4_class() != |
20408 Class::null()); | 20445 Class::null()); |
20409 Float32x4& result = Float32x4::Handle(); | 20446 Float32x4& result = Float32x4::Handle(); |
(...skipping 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
20781 JSONObject jsobj(stream); | 20818 JSONObject jsobj(stream); |
20782 PrintSharedInstanceJSON(&jsobj, ref); | 20819 PrintSharedInstanceJSON(&jsobj, ref); |
20783 const Class& cls = Class::Handle(clazz()); | 20820 const Class& cls = Class::Handle(clazz()); |
20784 const String& kind = String::Handle(cls.UserVisibleName()); | 20821 const String& kind = String::Handle(cls.UserVisibleName()); |
20785 jsobj.AddProperty("kind", kind.ToCString()); | 20822 jsobj.AddProperty("kind", kind.ToCString()); |
20786 jsobj.AddServiceId(*this); | 20823 jsobj.AddServiceId(*this); |
20787 jsobj.AddProperty("length", Length()); | 20824 jsobj.AddProperty("length", Length()); |
20788 if (ref) { | 20825 if (ref) { |
20789 return; | 20826 return; |
20790 } | 20827 } |
20791 | 20828 intptr_t offset; |
20792 { | 20829 intptr_t count; |
| 20830 stream->ComputeOffsetAndCount(Length(), &offset, &count); |
| 20831 if (offset > 0) { |
| 20832 jsobj.AddProperty("offset", offset); |
| 20833 } |
| 20834 if (count < Length()) { |
| 20835 jsobj.AddProperty("count", count); |
| 20836 } |
| 20837 if (count == 0) { |
| 20838 jsobj.AddProperty("bytes", ""); |
| 20839 } else { |
20793 NoSafepointScope no_safepoint; | 20840 NoSafepointScope no_safepoint; |
20794 jsobj.AddPropertyBase64("bytes", | 20841 jsobj.AddPropertyBase64("bytes", |
20795 reinterpret_cast<const uint8_t*>(DataAddr(0)), | 20842 reinterpret_cast<const uint8_t*>( |
20796 LengthInBytes()); | 20843 DataAddr(offset * ElementSizeInBytes())), |
| 20844 count * ElementSizeInBytes()); |
20797 } | 20845 } |
20798 } | 20846 } |
20799 | 20847 |
20800 | 20848 |
20801 FinalizablePersistentHandle* ExternalTypedData::AddFinalizer( | 20849 FinalizablePersistentHandle* ExternalTypedData::AddFinalizer( |
20802 void* peer, Dart_WeakPersistentHandleFinalizer callback) const { | 20850 void* peer, Dart_WeakPersistentHandleFinalizer callback) const { |
20803 return dart::AddFinalizer(*this, peer, callback); | 20851 return dart::AddFinalizer(*this, peer, callback); |
20804 } | 20852 } |
20805 | 20853 |
20806 | 20854 |
(...skipping 25 matching lines...) Expand all Loading... |
20832 JSONObject jsobj(stream); | 20880 JSONObject jsobj(stream); |
20833 PrintSharedInstanceJSON(&jsobj, ref); | 20881 PrintSharedInstanceJSON(&jsobj, ref); |
20834 const Class& cls = Class::Handle(clazz()); | 20882 const Class& cls = Class::Handle(clazz()); |
20835 const String& kind = String::Handle(cls.UserVisibleName()); | 20883 const String& kind = String::Handle(cls.UserVisibleName()); |
20836 jsobj.AddProperty("kind", kind.ToCString()); | 20884 jsobj.AddProperty("kind", kind.ToCString()); |
20837 jsobj.AddServiceId(*this); | 20885 jsobj.AddServiceId(*this); |
20838 jsobj.AddProperty("length", Length()); | 20886 jsobj.AddProperty("length", Length()); |
20839 if (ref) { | 20887 if (ref) { |
20840 return; | 20888 return; |
20841 } | 20889 } |
20842 | 20890 intptr_t offset; |
20843 { | 20891 intptr_t count; |
| 20892 stream->ComputeOffsetAndCount(Length(), &offset, &count); |
| 20893 if (offset > 0) { |
| 20894 jsobj.AddProperty("offset", offset); |
| 20895 } |
| 20896 if (count < Length()) { |
| 20897 jsobj.AddProperty("count", count); |
| 20898 } |
| 20899 if (count == 0) { |
| 20900 jsobj.AddProperty("bytes", ""); |
| 20901 } else { |
20844 NoSafepointScope no_safepoint; | 20902 NoSafepointScope no_safepoint; |
20845 jsobj.AddPropertyBase64("bytes", | 20903 jsobj.AddPropertyBase64("bytes", |
20846 reinterpret_cast<const uint8_t*>(DataAddr(0)), | 20904 reinterpret_cast<const uint8_t*>( |
20847 LengthInBytes()); | 20905 DataAddr(offset * ElementSizeInBytes())), |
| 20906 count * ElementSizeInBytes()); |
20848 } | 20907 } |
20849 } | 20908 } |
20850 | 20909 |
20851 | 20910 |
20852 RawCapability* Capability::New(uint64_t id, Heap::Space space) { | 20911 RawCapability* Capability::New(uint64_t id, Heap::Space space) { |
20853 Capability& result = Capability::Handle(); | 20912 Capability& result = Capability::Handle(); |
20854 { | 20913 { |
20855 RawObject* raw = Object::Allocate(Capability::kClassId, | 20914 RawObject* raw = Object::Allocate(Capability::kClassId, |
20856 Capability::InstanceSize(), | 20915 Capability::InstanceSize(), |
20857 space); | 20916 space); |
(...skipping 666 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
21524 return tag_label.ToCString(); | 21583 return tag_label.ToCString(); |
21525 } | 21584 } |
21526 | 21585 |
21527 | 21586 |
21528 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 21587 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
21529 Instance::PrintJSONImpl(stream, ref); | 21588 Instance::PrintJSONImpl(stream, ref); |
21530 } | 21589 } |
21531 | 21590 |
21532 | 21591 |
21533 } // namespace dart | 21592 } // namespace dart |
OLD | NEW |