| 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 11449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11460 | 11460 |
| 11461 | 11461 |
| 11462 const char* Error::ToCString() const { | 11462 const char* Error::ToCString() const { |
| 11463 // Error is an abstract class. We should never reach here. | 11463 // Error is an abstract class. We should never reach here. |
| 11464 UNREACHABLE(); | 11464 UNREACHABLE(); |
| 11465 return "Error"; | 11465 return "Error"; |
| 11466 } | 11466 } |
| 11467 | 11467 |
| 11468 | 11468 |
| 11469 void Error::PrintToJSONStream(JSONStream* stream, bool ref) const { | 11469 void Error::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 11470 JSONObject jsobj(stream); | 11470 UNREACHABLE(); |
| 11471 jsobj.AddProperty("type", JSONType(false)); | |
| 11472 jsobj.AddProperty("error_msg", ToErrorCString()); | |
| 11473 } | 11471 } |
| 11474 | 11472 |
| 11475 | 11473 |
| 11476 RawApiError* ApiError::New() { | 11474 RawApiError* ApiError::New() { |
| 11477 ASSERT(Object::api_error_class() != Class::null()); | 11475 ASSERT(Object::api_error_class() != Class::null()); |
| 11478 RawObject* raw = Object::Allocate(ApiError::kClassId, | 11476 RawObject* raw = Object::Allocate(ApiError::kClassId, |
| 11479 ApiError::InstanceSize(), | 11477 ApiError::InstanceSize(), |
| 11480 Heap::kOld); | 11478 Heap::kOld); |
| 11481 return reinterpret_cast<RawApiError*>(raw); | 11479 return reinterpret_cast<RawApiError*>(raw); |
| 11482 } | 11480 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 11508 } | 11506 } |
| 11509 | 11507 |
| 11510 | 11508 |
| 11511 const char* ApiError::ToCString() const { | 11509 const char* ApiError::ToCString() const { |
| 11512 return "ApiError"; | 11510 return "ApiError"; |
| 11513 } | 11511 } |
| 11514 | 11512 |
| 11515 | 11513 |
| 11516 void ApiError::PrintToJSONStream(JSONStream* stream, bool ref) const { | 11514 void ApiError::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 11517 JSONObject jsobj(stream); | 11515 JSONObject jsobj(stream); |
| 11518 jsobj.AddProperty("type", JSONType(false)); | 11516 jsobj.AddProperty("type", "Error"); |
| 11519 jsobj.AddProperty("error_msg", ToErrorCString()); | 11517 jsobj.AddProperty("id", ""); |
| 11518 jsobj.AddProperty("kind", JSONType(false)); |
| 11519 jsobj.AddProperty("message", ToErrorCString()); |
| 11520 } | 11520 } |
| 11521 | 11521 |
| 11522 | 11522 |
| 11523 RawLanguageError* LanguageError::New() { | 11523 RawLanguageError* LanguageError::New() { |
| 11524 ASSERT(Object::language_error_class() != Class::null()); | 11524 ASSERT(Object::language_error_class() != Class::null()); |
| 11525 RawObject* raw = Object::Allocate(LanguageError::kClassId, | 11525 RawObject* raw = Object::Allocate(LanguageError::kClassId, |
| 11526 LanguageError::InstanceSize(), | 11526 LanguageError::InstanceSize(), |
| 11527 Heap::kOld); | 11527 Heap::kOld); |
| 11528 return reinterpret_cast<RawLanguageError*>(raw); | 11528 return reinterpret_cast<RawLanguageError*>(raw); |
| 11529 } | 11529 } |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11694 } | 11694 } |
| 11695 | 11695 |
| 11696 | 11696 |
| 11697 const char* LanguageError::ToCString() const { | 11697 const char* LanguageError::ToCString() const { |
| 11698 return "LanguageError"; | 11698 return "LanguageError"; |
| 11699 } | 11699 } |
| 11700 | 11700 |
| 11701 | 11701 |
| 11702 void LanguageError::PrintToJSONStream(JSONStream* stream, bool ref) const { | 11702 void LanguageError::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 11703 JSONObject jsobj(stream); | 11703 JSONObject jsobj(stream); |
| 11704 jsobj.AddProperty("type", JSONType(false)); | 11704 jsobj.AddProperty("type", "Error"); |
| 11705 jsobj.AddProperty("error_msg", ToErrorCString()); | 11705 jsobj.AddProperty("id", ""); |
| 11706 jsobj.AddProperty("kind", JSONType(false)); |
| 11707 jsobj.AddProperty("message", ToErrorCString()); |
| 11706 } | 11708 } |
| 11707 | 11709 |
| 11708 | 11710 |
| 11709 RawUnhandledException* UnhandledException::New(const Instance& exception, | 11711 RawUnhandledException* UnhandledException::New(const Instance& exception, |
| 11710 const Instance& stacktrace, | 11712 const Instance& stacktrace, |
| 11711 Heap::Space space) { | 11713 Heap::Space space) { |
| 11712 ASSERT(Object::unhandled_exception_class() != Class::null()); | 11714 ASSERT(Object::unhandled_exception_class() != Class::null()); |
| 11713 UnhandledException& result = UnhandledException::Handle(); | 11715 UnhandledException& result = UnhandledException::Handle(); |
| 11714 { | 11716 { |
| 11715 RawObject* raw = Object::Allocate(UnhandledException::kClassId, | 11717 RawObject* raw = Object::Allocate(UnhandledException::kClassId, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11767 OS::SNPrint(chars, len, format, exc_str, stack_str); | 11769 OS::SNPrint(chars, len, format, exc_str, stack_str); |
| 11768 return chars; | 11770 return chars; |
| 11769 } | 11771 } |
| 11770 | 11772 |
| 11771 | 11773 |
| 11772 const char* UnhandledException::ToCString() const { | 11774 const char* UnhandledException::ToCString() const { |
| 11773 return "UnhandledException"; | 11775 return "UnhandledException"; |
| 11774 } | 11776 } |
| 11775 | 11777 |
| 11776 | 11778 |
| 11779 |
| 11777 void UnhandledException::PrintToJSONStream(JSONStream* stream, | 11780 void UnhandledException::PrintToJSONStream(JSONStream* stream, |
| 11778 bool ref) const { | 11781 bool ref) const { |
| 11779 JSONObject jsobj(stream); | 11782 JSONObject jsobj(stream); |
| 11780 jsobj.AddProperty("type", JSONType(false)); | 11783 jsobj.AddProperty("type", "Error"); |
| 11781 jsobj.AddProperty("error_msg", ToErrorCString()); | 11784 jsobj.AddProperty("id", ""); |
| 11785 jsobj.AddProperty("kind", JSONType(false)); |
| 11786 jsobj.AddProperty("message", ToErrorCString()); |
| 11787 |
| 11788 Instance& instance = Instance::Handle(); |
| 11789 instance = exception(); |
| 11790 jsobj.AddProperty("exception", instance); |
| 11791 instance = stacktrace(); |
| 11792 jsobj.AddProperty("stacktrace", instance); |
| 11782 } | 11793 } |
| 11783 | 11794 |
| 11784 | 11795 |
| 11785 RawUnwindError* UnwindError::New(const String& message, Heap::Space space) { | 11796 RawUnwindError* UnwindError::New(const String& message, Heap::Space space) { |
| 11786 ASSERT(Object::unwind_error_class() != Class::null()); | 11797 ASSERT(Object::unwind_error_class() != Class::null()); |
| 11787 UnwindError& result = UnwindError::Handle(); | 11798 UnwindError& result = UnwindError::Handle(); |
| 11788 { | 11799 { |
| 11789 RawObject* raw = Object::Allocate(UnwindError::kClassId, | 11800 RawObject* raw = Object::Allocate(UnwindError::kClassId, |
| 11790 UnwindError::InstanceSize(), | 11801 UnwindError::InstanceSize(), |
| 11791 space); | 11802 space); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 11808 } | 11819 } |
| 11809 | 11820 |
| 11810 | 11821 |
| 11811 const char* UnwindError::ToCString() const { | 11822 const char* UnwindError::ToCString() const { |
| 11812 return "UnwindError"; | 11823 return "UnwindError"; |
| 11813 } | 11824 } |
| 11814 | 11825 |
| 11815 | 11826 |
| 11816 void UnwindError::PrintToJSONStream(JSONStream* stream, bool ref) const { | 11827 void UnwindError::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 11817 JSONObject jsobj(stream); | 11828 JSONObject jsobj(stream); |
| 11818 jsobj.AddProperty("type", JSONType(false)); | 11829 jsobj.AddProperty("type", "Error"); |
| 11819 jsobj.AddProperty("error_msg", ToErrorCString()); | 11830 jsobj.AddProperty("id", ""); |
| 11831 jsobj.AddProperty("kind", JSONType(false)); |
| 11832 jsobj.AddProperty("message", ToErrorCString()); |
| 11820 } | 11833 } |
| 11821 | 11834 |
| 11822 | 11835 |
| 11823 RawObject* Instance::Evaluate(const String& expr) const { | 11836 RawObject* Instance::Evaluate(const String& expr) const { |
| 11824 const Class& cls = Class::Handle(clazz()); | 11837 const Class& cls = Class::Handle(clazz()); |
| 11825 const PatchClass& temp_class = | 11838 const PatchClass& temp_class = |
| 11826 PatchClass::Handle(MakeTempPatchClass(cls, expr)); | 11839 PatchClass::Handle(MakeTempPatchClass(cls, expr)); |
| 11827 const String& eval_func_name = String::Handle(Symbols::New(":eval")); | 11840 const String& eval_func_name = String::Handle(Symbols::New(":eval")); |
| 11828 const Function& eval_func = | 11841 const Function& eval_func = |
| 11829 Function::Handle(Function::New(eval_func_name, | 11842 Function::Handle(Function::New(eval_func_name, |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12200 return "<being initialized>"; | 12213 return "<being initialized>"; |
| 12201 } else { | 12214 } else { |
| 12202 return ToCString(); | 12215 return ToCString(); |
| 12203 } | 12216 } |
| 12204 } | 12217 } |
| 12205 | 12218 |
| 12206 | 12219 |
| 12207 void Instance::PrintToJSONStream(JSONStream* stream, bool ref) const { | 12220 void Instance::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 12208 JSONObject jsobj(stream); | 12221 JSONObject jsobj(stream); |
| 12209 Class& cls = Class::Handle(this->clazz()); | 12222 Class& cls = Class::Handle(this->clazz()); |
| 12210 jsobj.AddProperty("preview", ToUserCString(40)); | |
| 12211 | 12223 |
| 12212 // TODO(turnidge): Handle <optimized out> like other null-like values. | 12224 // TODO(turnidge): Handle <optimized out> like other null-like values. |
| 12213 if (IsNull()) { | 12225 if (IsNull()) { |
| 12214 jsobj.AddProperty("type", ref ? "@Null" : "Null"); | 12226 jsobj.AddProperty("type", ref ? "@Null" : "Null"); |
| 12215 jsobj.AddProperty("id", "objects/null"); | 12227 jsobj.AddProperty("id", "objects/null"); |
| 12228 jsobj.AddProperty("preview", "null"); |
| 12216 return; | 12229 return; |
| 12217 } else if (raw() == Object::sentinel().raw()) { | 12230 } else if (raw() == Object::sentinel().raw()) { |
| 12218 jsobj.AddProperty("type", ref ? "@Null" : "Null"); | 12231 jsobj.AddProperty("type", ref ? "@Null" : "Null"); |
| 12219 jsobj.AddProperty("id", "objects/not-initialized"); | 12232 jsobj.AddProperty("id", "objects/not-initialized"); |
| 12233 jsobj.AddProperty("preview", "<not initialized>"); |
| 12220 return; | 12234 return; |
| 12221 } else if (raw() == Object::transition_sentinel().raw()) { | 12235 } else if (raw() == Object::transition_sentinel().raw()) { |
| 12222 jsobj.AddProperty("type", ref ? "@Null" : "Null"); | 12236 jsobj.AddProperty("type", ref ? "@Null" : "Null"); |
| 12223 jsobj.AddProperty("id", "objects/being-initialized"); | 12237 jsobj.AddProperty("id", "objects/being-initialized"); |
| 12238 jsobj.AddProperty("preview", "<being initialized>"); |
| 12224 return; | 12239 return; |
| 12225 } else if (raw() == Symbols::OptimizedOut().raw()) { | 12240 } else if (raw() == Symbols::OptimizedOut().raw()) { |
| 12226 // TODO(turnidge): This is a hack. The user could have this | 12241 // TODO(turnidge): This is a hack. The user could have this |
| 12227 // special string in their program. Fixing this involves updating | 12242 // special string in their program. Fixing this involves updating |
| 12228 // the debugging api a bit. | 12243 // the debugging api a bit. |
| 12229 jsobj.AddProperty("type", ref ? "@Null" : "Null"); | 12244 jsobj.AddProperty("type", ref ? "@Null" : "Null"); |
| 12230 jsobj.AddProperty("id", "objects/optimized-out"); | 12245 jsobj.AddProperty("id", "objects/optimized-out"); |
| 12231 jsobj.AddProperty("preview", "<optimized out>"); | 12246 jsobj.AddProperty("preview", "<optimized out>"); |
| 12232 return; | 12247 return; |
| 12233 } else { | 12248 } else { |
| 12234 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); | 12249 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); |
| 12235 intptr_t id = ring->GetIdForObject(raw()); | 12250 intptr_t id = ring->GetIdForObject(raw()); |
| 12236 if (IsClosure()) { | 12251 if (IsClosure()) { |
| 12237 const Function& closureFunc = Function::Handle(Closure::function(*this)); | 12252 const Function& closureFunc = Function::Handle(Closure::function(*this)); |
| 12238 jsobj.AddProperty("closureFunc", closureFunc); | 12253 jsobj.AddProperty("closureFunc", closureFunc); |
| 12239 jsobj.AddProperty("type", ref ? "@Closure" : "Closure"); | 12254 jsobj.AddProperty("type", ref ? "@Closure" : "Closure"); |
| 12240 } else { | 12255 } else { |
| 12241 jsobj.AddProperty("type", JSONType(ref)); | 12256 jsobj.AddProperty("type", JSONType(ref)); |
| 12242 } | 12257 } |
| 12243 jsobj.AddPropertyF("id", "objects/%" Pd "", id); | 12258 jsobj.AddPropertyF("id", "objects/%" Pd "", id); |
| 12244 jsobj.AddProperty("class", cls); | 12259 jsobj.AddProperty("class", cls); |
| 12260 jsobj.AddProperty("preview", ToUserCString(40)); |
| 12245 } | 12261 } |
| 12246 if (ref) { | 12262 if (ref) { |
| 12247 return; | 12263 return; |
| 12248 } | 12264 } |
| 12249 | 12265 |
| 12250 // Walk the superclass chain, adding all instance fields. | 12266 // Walk the superclass chain, adding all instance fields. |
| 12251 { | 12267 { |
| 12252 Instance& fieldValue = Instance::Handle(); | 12268 Instance& fieldValue = Instance::Handle(); |
| 12253 JSONArray jsarr(&jsobj, "fields"); | 12269 JSONArray jsarr(&jsobj, "fields"); |
| 12254 while (!cls.IsNull()) { | 12270 while (!cls.IsNull()) { |
| 12255 const Array& field_array = Array::Handle(cls.fields()); | 12271 const Array& field_array = Array::Handle(cls.fields()); |
| 12256 Field& field = Field::Handle(); | 12272 Field& field = Field::Handle(); |
| 12257 if (!field_array.IsNull()) { | 12273 if (!field_array.IsNull()) { |
| 12258 for (intptr_t i = 0; i < field_array.Length(); i++) { | 12274 for (intptr_t i = 0; i < field_array.Length(); i++) { |
| 12259 field ^= field_array.At(i); | 12275 field ^= field_array.At(i); |
| 12260 if (!field.is_static()) { | 12276 if (!field.is_static()) { |
| 12261 fieldValue ^= GetField(field); | 12277 fieldValue ^= GetField(field); |
| 12262 JSONObject jsfield(&jsarr); | 12278 JSONObject jsfield(&jsarr); |
| 12263 jsfield.AddProperty("decl", field); | 12279 jsfield.AddProperty("decl", field); |
| 12264 jsfield.AddProperty("value", fieldValue); | 12280 jsfield.AddProperty("value", fieldValue); |
| 12265 } | 12281 } |
| 12266 } | 12282 } |
| 12267 } | 12283 } |
| 12268 cls = cls.SuperClass(); | 12284 cls = cls.SuperClass(); |
| 12269 } | 12285 } |
| 12270 } | 12286 } |
| 12287 |
| 12288 if (NumNativeFields() > 0) { |
| 12289 JSONArray jsarr(&jsobj, "nativeFields"); |
| 12290 for (intptr_t i = 0; i < NumNativeFields(); i++) { |
| 12291 intptr_t value = GetNativeField(i); |
| 12292 JSONObject jsfield(&jsarr); |
| 12293 jsfield.AddProperty("index", i); |
| 12294 jsfield.AddProperty("value", value); |
| 12295 } |
| 12296 } |
| 12297 |
| 12298 jsobj.AddProperty("size", raw()->Size()); |
| 12271 } | 12299 } |
| 12272 | 12300 |
| 12273 | 12301 |
| 12274 bool AbstractType::IsResolved() const { | 12302 bool AbstractType::IsResolved() const { |
| 12275 // AbstractType is an abstract class. | 12303 // AbstractType is an abstract class. |
| 12276 UNREACHABLE(); | 12304 UNREACHABLE(); |
| 12277 return false; | 12305 return false; |
| 12278 } | 12306 } |
| 12279 | 12307 |
| 12280 | 12308 |
| (...skipping 1978 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14259 intptr_t len = OS::SNPrint(NULL, 0, kFormat, Value()) + 1; | 14287 intptr_t len = OS::SNPrint(NULL, 0, kFormat, Value()) + 1; |
| 14260 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 14288 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
| 14261 OS::SNPrint(chars, len, kFormat, Value()); | 14289 OS::SNPrint(chars, len, kFormat, Value()); |
| 14262 return chars; | 14290 return chars; |
| 14263 } | 14291 } |
| 14264 | 14292 |
| 14265 | 14293 |
| 14266 void Smi::PrintToJSONStream(JSONStream* stream, bool ref) const { | 14294 void Smi::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 14267 JSONObject jsobj(stream); | 14295 JSONObject jsobj(stream); |
| 14268 jsobj.AddProperty("type", JSONType(ref)); | 14296 jsobj.AddProperty("type", JSONType(ref)); |
| 14269 jsobj.AddPropertyF("id", "objects/int/%" Pd "", Value()); | 14297 jsobj.AddPropertyF("id", "objects/int-%" Pd "", Value()); |
| 14270 class Class& cls = Class::Handle(this->clazz()); | 14298 class Class& cls = Class::Handle(this->clazz()); |
| 14271 jsobj.AddProperty("class", cls); | 14299 jsobj.AddProperty("class", cls); |
| 14272 jsobj.AddPropertyF("preview", "%" Pd "", Value()); | 14300 jsobj.AddPropertyF("preview", "%" Pd "", Value()); |
| 14273 } | 14301 } |
| 14274 | 14302 |
| 14275 | 14303 |
| 14276 RawClass* Smi::Class() { | 14304 RawClass* Smi::Class() { |
| 14277 return Isolate::Current()->object_store()->smi_class(); | 14305 return Isolate::Current()->object_store()->smi_class(); |
| 14278 } | 14306 } |
| 14279 | 14307 |
| (...skipping 2019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16299 | 16327 |
| 16300 const char* Bool::ToCString() const { | 16328 const char* Bool::ToCString() const { |
| 16301 return value() ? "true" : "false"; | 16329 return value() ? "true" : "false"; |
| 16302 } | 16330 } |
| 16303 | 16331 |
| 16304 | 16332 |
| 16305 void Bool::PrintToJSONStream(JSONStream* stream, bool ref) const { | 16333 void Bool::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 16306 const char* str = ToCString(); | 16334 const char* str = ToCString(); |
| 16307 JSONObject jsobj(stream); | 16335 JSONObject jsobj(stream); |
| 16308 jsobj.AddProperty("type", JSONType(ref)); | 16336 jsobj.AddProperty("type", JSONType(ref)); |
| 16309 jsobj.AddPropertyF("id", "objects/bool/%s", str); | 16337 jsobj.AddPropertyF("id", "objects/bool-%s", str); |
| 16310 class Class& cls = Class::Handle(this->clazz()); | 16338 class Class& cls = Class::Handle(this->clazz()); |
| 16311 jsobj.AddProperty("class", cls); | 16339 jsobj.AddProperty("class", cls); |
| 16312 jsobj.AddPropertyF("preview", "%s", str); | 16340 jsobj.AddPropertyF("preview", "%s", str); |
| 16313 } | 16341 } |
| 16314 | 16342 |
| 16315 | 16343 |
| 16316 bool Array::Equals(const Instance& other) const { | 16344 bool Array::Equals(const Instance& other) const { |
| 16317 if (this->raw() == other.raw()) { | 16345 if (this->raw() == other.raw()) { |
| 16318 // Both handles point to the same raw instance. | 16346 // Both handles point to the same raw instance. |
| 16319 return true; | 16347 return true; |
| (...skipping 1287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17607 return "_MirrorReference"; | 17635 return "_MirrorReference"; |
| 17608 } | 17636 } |
| 17609 | 17637 |
| 17610 | 17638 |
| 17611 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 17639 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 17612 Instance::PrintToJSONStream(stream, ref); | 17640 Instance::PrintToJSONStream(stream, ref); |
| 17613 } | 17641 } |
| 17614 | 17642 |
| 17615 | 17643 |
| 17616 } // namespace dart | 17644 } // namespace dart |
| OLD | NEW |