| 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 11424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11435 | 11435 |
| 11436 | 11436 |
| 11437 const char* Error::ToCString() const { | 11437 const char* Error::ToCString() const { |
| 11438 // Error is an abstract class. We should never reach here. | 11438 // Error is an abstract class. We should never reach here. |
| 11439 UNREACHABLE(); | 11439 UNREACHABLE(); |
| 11440 return "Error"; | 11440 return "Error"; |
| 11441 } | 11441 } |
| 11442 | 11442 |
| 11443 | 11443 |
| 11444 void Error::PrintToJSONStream(JSONStream* stream, bool ref) const { | 11444 void Error::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 11445 JSONObject jsobj(stream); | 11445 UNREACHABLE(); |
| 11446 jsobj.AddProperty("type", JSONType(false)); | |
| 11447 jsobj.AddProperty("error_msg", ToErrorCString()); | |
| 11448 } | 11446 } |
| 11449 | 11447 |
| 11450 | 11448 |
| 11451 RawApiError* ApiError::New() { | 11449 RawApiError* ApiError::New() { |
| 11452 ASSERT(Object::api_error_class() != Class::null()); | 11450 ASSERT(Object::api_error_class() != Class::null()); |
| 11453 RawObject* raw = Object::Allocate(ApiError::kClassId, | 11451 RawObject* raw = Object::Allocate(ApiError::kClassId, |
| 11454 ApiError::InstanceSize(), | 11452 ApiError::InstanceSize(), |
| 11455 Heap::kOld); | 11453 Heap::kOld); |
| 11456 return reinterpret_cast<RawApiError*>(raw); | 11454 return reinterpret_cast<RawApiError*>(raw); |
| 11457 } | 11455 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 11483 } | 11481 } |
| 11484 | 11482 |
| 11485 | 11483 |
| 11486 const char* ApiError::ToCString() const { | 11484 const char* ApiError::ToCString() const { |
| 11487 return "ApiError"; | 11485 return "ApiError"; |
| 11488 } | 11486 } |
| 11489 | 11487 |
| 11490 | 11488 |
| 11491 void ApiError::PrintToJSONStream(JSONStream* stream, bool ref) const { | 11489 void ApiError::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 11492 JSONObject jsobj(stream); | 11490 JSONObject jsobj(stream); |
| 11493 jsobj.AddProperty("type", JSONType(false)); | 11491 jsobj.AddProperty("type", "Error"); |
| 11494 jsobj.AddProperty("error_msg", ToErrorCString()); | 11492 jsobj.AddProperty("id", ""); |
| 11493 jsobj.AddProperty("kind", JSONType(false)); |
| 11494 jsobj.AddProperty("message", ToErrorCString()); |
| 11495 } | 11495 } |
| 11496 | 11496 |
| 11497 | 11497 |
| 11498 RawLanguageError* LanguageError::New() { | 11498 RawLanguageError* LanguageError::New() { |
| 11499 ASSERT(Object::language_error_class() != Class::null()); | 11499 ASSERT(Object::language_error_class() != Class::null()); |
| 11500 RawObject* raw = Object::Allocate(LanguageError::kClassId, | 11500 RawObject* raw = Object::Allocate(LanguageError::kClassId, |
| 11501 LanguageError::InstanceSize(), | 11501 LanguageError::InstanceSize(), |
| 11502 Heap::kOld); | 11502 Heap::kOld); |
| 11503 return reinterpret_cast<RawLanguageError*>(raw); | 11503 return reinterpret_cast<RawLanguageError*>(raw); |
| 11504 } | 11504 } |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11669 } | 11669 } |
| 11670 | 11670 |
| 11671 | 11671 |
| 11672 const char* LanguageError::ToCString() const { | 11672 const char* LanguageError::ToCString() const { |
| 11673 return "LanguageError"; | 11673 return "LanguageError"; |
| 11674 } | 11674 } |
| 11675 | 11675 |
| 11676 | 11676 |
| 11677 void LanguageError::PrintToJSONStream(JSONStream* stream, bool ref) const { | 11677 void LanguageError::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 11678 JSONObject jsobj(stream); | 11678 JSONObject jsobj(stream); |
| 11679 jsobj.AddProperty("type", JSONType(false)); | 11679 jsobj.AddProperty("type", "Error"); |
| 11680 jsobj.AddProperty("error_msg", ToErrorCString()); | 11680 jsobj.AddProperty("id", ""); |
| 11681 jsobj.AddProperty("kind", JSONType(false)); |
| 11682 jsobj.AddProperty("message", ToErrorCString()); |
| 11681 } | 11683 } |
| 11682 | 11684 |
| 11683 | 11685 |
| 11684 RawUnhandledException* UnhandledException::New(const Instance& exception, | 11686 RawUnhandledException* UnhandledException::New(const Instance& exception, |
| 11685 const Instance& stacktrace, | 11687 const Instance& stacktrace, |
| 11686 Heap::Space space) { | 11688 Heap::Space space) { |
| 11687 ASSERT(Object::unhandled_exception_class() != Class::null()); | 11689 ASSERT(Object::unhandled_exception_class() != Class::null()); |
| 11688 UnhandledException& result = UnhandledException::Handle(); | 11690 UnhandledException& result = UnhandledException::Handle(); |
| 11689 { | 11691 { |
| 11690 RawObject* raw = Object::Allocate(UnhandledException::kClassId, | 11692 RawObject* raw = Object::Allocate(UnhandledException::kClassId, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11742 OS::SNPrint(chars, len, format, exc_str, stack_str); | 11744 OS::SNPrint(chars, len, format, exc_str, stack_str); |
| 11743 return chars; | 11745 return chars; |
| 11744 } | 11746 } |
| 11745 | 11747 |
| 11746 | 11748 |
| 11747 const char* UnhandledException::ToCString() const { | 11749 const char* UnhandledException::ToCString() const { |
| 11748 return "UnhandledException"; | 11750 return "UnhandledException"; |
| 11749 } | 11751 } |
| 11750 | 11752 |
| 11751 | 11753 |
| 11754 |
| 11752 void UnhandledException::PrintToJSONStream(JSONStream* stream, | 11755 void UnhandledException::PrintToJSONStream(JSONStream* stream, |
| 11753 bool ref) const { | 11756 bool ref) const { |
| 11754 JSONObject jsobj(stream); | 11757 JSONObject jsobj(stream); |
| 11755 jsobj.AddProperty("type", JSONType(false)); | 11758 jsobj.AddProperty("type", "Error"); |
| 11756 jsobj.AddProperty("error_msg", ToErrorCString()); | 11759 jsobj.AddProperty("id", ""); |
| 11760 jsobj.AddProperty("kind", JSONType(false)); |
| 11761 jsobj.AddProperty("message", ToErrorCString()); |
| 11762 |
| 11763 Instance& instance = Instance::Handle(); |
| 11764 instance = exception(); |
| 11765 jsobj.AddProperty("exception", instance); |
| 11766 instance = stacktrace(); |
| 11767 jsobj.AddProperty("stacktrace", instance); |
| 11757 } | 11768 } |
| 11758 | 11769 |
| 11759 | 11770 |
| 11760 RawUnwindError* UnwindError::New(const String& message, Heap::Space space) { | 11771 RawUnwindError* UnwindError::New(const String& message, Heap::Space space) { |
| 11761 ASSERT(Object::unwind_error_class() != Class::null()); | 11772 ASSERT(Object::unwind_error_class() != Class::null()); |
| 11762 UnwindError& result = UnwindError::Handle(); | 11773 UnwindError& result = UnwindError::Handle(); |
| 11763 { | 11774 { |
| 11764 RawObject* raw = Object::Allocate(UnwindError::kClassId, | 11775 RawObject* raw = Object::Allocate(UnwindError::kClassId, |
| 11765 UnwindError::InstanceSize(), | 11776 UnwindError::InstanceSize(), |
| 11766 space); | 11777 space); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 11783 } | 11794 } |
| 11784 | 11795 |
| 11785 | 11796 |
| 11786 const char* UnwindError::ToCString() const { | 11797 const char* UnwindError::ToCString() const { |
| 11787 return "UnwindError"; | 11798 return "UnwindError"; |
| 11788 } | 11799 } |
| 11789 | 11800 |
| 11790 | 11801 |
| 11791 void UnwindError::PrintToJSONStream(JSONStream* stream, bool ref) const { | 11802 void UnwindError::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 11792 JSONObject jsobj(stream); | 11803 JSONObject jsobj(stream); |
| 11793 jsobj.AddProperty("type", JSONType(false)); | 11804 jsobj.AddProperty("type", "Error"); |
| 11794 jsobj.AddProperty("error_msg", ToErrorCString()); | 11805 jsobj.AddProperty("id", ""); |
| 11806 jsobj.AddProperty("kind", JSONType(false)); |
| 11807 jsobj.AddProperty("message", ToErrorCString()); |
| 11795 } | 11808 } |
| 11796 | 11809 |
| 11797 | 11810 |
| 11798 RawObject* Instance::Evaluate(const String& expr) const { | 11811 RawObject* Instance::Evaluate(const String& expr) const { |
| 11799 const Class& cls = Class::Handle(clazz()); | 11812 const Class& cls = Class::Handle(clazz()); |
| 11800 const PatchClass& temp_class = | 11813 const PatchClass& temp_class = |
| 11801 PatchClass::Handle(MakeTempPatchClass(cls, expr)); | 11814 PatchClass::Handle(MakeTempPatchClass(cls, expr)); |
| 11802 const String& eval_func_name = String::Handle(Symbols::New(":eval")); | 11815 const String& eval_func_name = String::Handle(Symbols::New(":eval")); |
| 11803 const Function& eval_func = | 11816 const Function& eval_func = |
| 11804 Function::Handle(Function::New(eval_func_name, | 11817 Function::Handle(Function::New(eval_func_name, |
| (...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12172 return "<being initialized>"; | 12185 return "<being initialized>"; |
| 12173 } else { | 12186 } else { |
| 12174 return ToCString(); | 12187 return ToCString(); |
| 12175 } | 12188 } |
| 12176 } | 12189 } |
| 12177 | 12190 |
| 12178 | 12191 |
| 12179 void Instance::PrintToJSONStream(JSONStream* stream, bool ref) const { | 12192 void Instance::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 12180 JSONObject jsobj(stream); | 12193 JSONObject jsobj(stream); |
| 12181 Class& cls = Class::Handle(this->clazz()); | 12194 Class& cls = Class::Handle(this->clazz()); |
| 12182 jsobj.AddProperty("preview", ToUserCString(40)); | |
| 12183 | 12195 |
| 12184 // TODO(turnidge): Handle <optimized out> like other null-like values. | 12196 // TODO(turnidge): Handle <optimized out> like other null-like values. |
| 12185 if (IsNull()) { | 12197 if (IsNull()) { |
| 12186 jsobj.AddProperty("type", ref ? "@Null" : "Null"); | 12198 jsobj.AddProperty("type", ref ? "@Null" : "Null"); |
| 12187 jsobj.AddProperty("id", "objects/null"); | 12199 jsobj.AddProperty("id", "objects/null"); |
| 12200 jsobj.AddProperty("preview", "null"); |
| 12188 return; | 12201 return; |
| 12189 } else if (raw() == Object::sentinel().raw()) { | 12202 } else if (raw() == Object::sentinel().raw()) { |
| 12190 jsobj.AddProperty("type", ref ? "@Null" : "Null"); | 12203 jsobj.AddProperty("type", ref ? "@Null" : "Null"); |
| 12191 jsobj.AddProperty("id", "objects/not-initialized"); | 12204 jsobj.AddProperty("id", "objects/not-initialized"); |
| 12205 jsobj.AddProperty("preview", "<not initialized>"); |
| 12192 return; | 12206 return; |
| 12193 } else if (raw() == Object::transition_sentinel().raw()) { | 12207 } else if (raw() == Object::transition_sentinel().raw()) { |
| 12194 jsobj.AddProperty("type", ref ? "@Null" : "Null"); | 12208 jsobj.AddProperty("type", ref ? "@Null" : "Null"); |
| 12195 jsobj.AddProperty("id", "objects/being-initialized"); | 12209 jsobj.AddProperty("id", "objects/being-initialized"); |
| 12210 jsobj.AddProperty("preview", "<being initialized>"); |
| 12196 return; | 12211 return; |
| 12197 } else if (raw() == Symbols::OptimizedOut().raw()) { | 12212 } else if (raw() == Symbols::OptimizedOut().raw()) { |
| 12198 // TODO(turnidge): This is a hack. The user could have this | 12213 // TODO(turnidge): This is a hack. The user could have this |
| 12199 // special string in their program. Fixing this involves updating | 12214 // special string in their program. Fixing this involves updating |
| 12200 // the debugging api a bit. | 12215 // the debugging api a bit. |
| 12201 jsobj.AddProperty("type", ref ? "@Null" : "Null"); | 12216 jsobj.AddProperty("type", ref ? "@Null" : "Null"); |
| 12202 jsobj.AddProperty("id", "objects/optimized-out"); | 12217 jsobj.AddProperty("id", "objects/optimized-out"); |
| 12203 jsobj.AddProperty("preview", "<optimized out>"); | 12218 jsobj.AddProperty("preview", "<optimized out>"); |
| 12204 return; | 12219 return; |
| 12205 } else { | 12220 } else { |
| 12206 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); | 12221 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); |
| 12207 intptr_t id = ring->GetIdForObject(raw()); | 12222 intptr_t id = ring->GetIdForObject(raw()); |
| 12208 if (IsClosure()) { | 12223 if (IsClosure()) { |
| 12209 const Function& closureFunc = Function::Handle(Closure::function(*this)); | 12224 const Function& closureFunc = Function::Handle(Closure::function(*this)); |
| 12210 jsobj.AddProperty("closureFunc", closureFunc); | 12225 jsobj.AddProperty("closureFunc", closureFunc); |
| 12211 jsobj.AddProperty("type", ref ? "@Closure" : "Closure"); | 12226 jsobj.AddProperty("type", ref ? "@Closure" : "Closure"); |
| 12212 } else { | 12227 } else { |
| 12213 jsobj.AddProperty("type", JSONType(ref)); | 12228 jsobj.AddProperty("type", JSONType(ref)); |
| 12214 } | 12229 } |
| 12215 jsobj.AddPropertyF("id", "objects/%" Pd "", id); | 12230 jsobj.AddPropertyF("id", "objects/%" Pd "", id); |
| 12216 jsobj.AddProperty("class", cls); | 12231 jsobj.AddProperty("class", cls); |
| 12232 jsobj.AddProperty("preview", ToUserCString(40)); |
| 12217 } | 12233 } |
| 12218 if (ref) { | 12234 if (ref) { |
| 12219 return; | 12235 return; |
| 12220 } | 12236 } |
| 12221 | 12237 |
| 12222 // Walk the superclass chain, adding all instance fields. | 12238 // Walk the superclass chain, adding all instance fields. |
| 12223 { | 12239 { |
| 12224 Instance& fieldValue = Instance::Handle(); | 12240 Instance& fieldValue = Instance::Handle(); |
| 12225 JSONArray jsarr(&jsobj, "fields"); | 12241 JSONArray jsarr(&jsobj, "fields"); |
| 12226 while (!cls.IsNull()) { | 12242 while (!cls.IsNull()) { |
| 12227 const Array& field_array = Array::Handle(cls.fields()); | 12243 const Array& field_array = Array::Handle(cls.fields()); |
| 12228 Field& field = Field::Handle(); | 12244 Field& field = Field::Handle(); |
| 12229 if (!field_array.IsNull()) { | 12245 if (!field_array.IsNull()) { |
| 12230 for (intptr_t i = 0; i < field_array.Length(); i++) { | 12246 for (intptr_t i = 0; i < field_array.Length(); i++) { |
| 12231 field ^= field_array.At(i); | 12247 field ^= field_array.At(i); |
| 12232 if (!field.is_static()) { | 12248 if (!field.is_static()) { |
| 12233 fieldValue ^= GetField(field); | 12249 fieldValue ^= GetField(field); |
| 12234 JSONObject jsfield(&jsarr); | 12250 JSONObject jsfield(&jsarr); |
| 12235 jsfield.AddProperty("decl", field); | 12251 jsfield.AddProperty("decl", field); |
| 12236 jsfield.AddProperty("value", fieldValue); | 12252 jsfield.AddProperty("value", fieldValue); |
| 12237 } | 12253 } |
| 12238 } | 12254 } |
| 12239 } | 12255 } |
| 12240 cls = cls.SuperClass(); | 12256 cls = cls.SuperClass(); |
| 12241 } | 12257 } |
| 12242 } | 12258 } |
| 12259 |
| 12260 if (NumNativeFields() > 0) { |
| 12261 JSONArray jsarr(&jsobj, "nativeFields"); |
| 12262 for (intptr_t i = 0; i < NumNativeFields(); i++) { |
| 12263 intptr_t value = GetNativeField(i); |
| 12264 JSONObject jsfield(&jsarr); |
| 12265 jsfield.AddProperty("index", i); |
| 12266 jsfield.AddProperty("value", value); |
| 12267 } |
| 12268 } |
| 12269 |
| 12270 jsobj.AddProperty("size", raw()->Size()); |
| 12243 } | 12271 } |
| 12244 | 12272 |
| 12245 | 12273 |
| 12246 bool AbstractType::IsResolved() const { | 12274 bool AbstractType::IsResolved() const { |
| 12247 // AbstractType is an abstract class. | 12275 // AbstractType is an abstract class. |
| 12248 UNREACHABLE(); | 12276 UNREACHABLE(); |
| 12249 return false; | 12277 return false; |
| 12250 } | 12278 } |
| 12251 | 12279 |
| 12252 | 12280 |
| (...skipping 1978 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14231 intptr_t len = OS::SNPrint(NULL, 0, kFormat, Value()) + 1; | 14259 intptr_t len = OS::SNPrint(NULL, 0, kFormat, Value()) + 1; |
| 14232 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 14260 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
| 14233 OS::SNPrint(chars, len, kFormat, Value()); | 14261 OS::SNPrint(chars, len, kFormat, Value()); |
| 14234 return chars; | 14262 return chars; |
| 14235 } | 14263 } |
| 14236 | 14264 |
| 14237 | 14265 |
| 14238 void Smi::PrintToJSONStream(JSONStream* stream, bool ref) const { | 14266 void Smi::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 14239 JSONObject jsobj(stream); | 14267 JSONObject jsobj(stream); |
| 14240 jsobj.AddProperty("type", JSONType(ref)); | 14268 jsobj.AddProperty("type", JSONType(ref)); |
| 14241 jsobj.AddPropertyF("id", "objects/int/%" Pd "", Value()); | 14269 jsobj.AddPropertyF("id", "objects/int-%" Pd "", Value()); |
| 14242 class Class& cls = Class::Handle(this->clazz()); | 14270 class Class& cls = Class::Handle(this->clazz()); |
| 14243 jsobj.AddProperty("class", cls); | 14271 jsobj.AddProperty("class", cls); |
| 14244 jsobj.AddPropertyF("preview", "%" Pd "", Value()); | 14272 jsobj.AddPropertyF("preview", "%" Pd "", Value()); |
| 14245 } | 14273 } |
| 14246 | 14274 |
| 14247 | 14275 |
| 14248 RawClass* Smi::Class() { | 14276 RawClass* Smi::Class() { |
| 14249 return Isolate::Current()->object_store()->smi_class(); | 14277 return Isolate::Current()->object_store()->smi_class(); |
| 14250 } | 14278 } |
| 14251 | 14279 |
| (...skipping 2019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16271 | 16299 |
| 16272 const char* Bool::ToCString() const { | 16300 const char* Bool::ToCString() const { |
| 16273 return value() ? "true" : "false"; | 16301 return value() ? "true" : "false"; |
| 16274 } | 16302 } |
| 16275 | 16303 |
| 16276 | 16304 |
| 16277 void Bool::PrintToJSONStream(JSONStream* stream, bool ref) const { | 16305 void Bool::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 16278 const char* str = ToCString(); | 16306 const char* str = ToCString(); |
| 16279 JSONObject jsobj(stream); | 16307 JSONObject jsobj(stream); |
| 16280 jsobj.AddProperty("type", JSONType(ref)); | 16308 jsobj.AddProperty("type", JSONType(ref)); |
| 16281 jsobj.AddPropertyF("id", "objects/bool/%s", str); | 16309 jsobj.AddPropertyF("id", "objects/bool-%s", str); |
| 16282 class Class& cls = Class::Handle(this->clazz()); | 16310 class Class& cls = Class::Handle(this->clazz()); |
| 16283 jsobj.AddProperty("class", cls); | 16311 jsobj.AddProperty("class", cls); |
| 16284 jsobj.AddPropertyF("preview", "%s", str); | 16312 jsobj.AddPropertyF("preview", "%s", str); |
| 16285 } | 16313 } |
| 16286 | 16314 |
| 16287 | 16315 |
| 16288 bool Array::Equals(const Instance& other) const { | 16316 bool Array::Equals(const Instance& other) const { |
| 16289 if (this->raw() == other.raw()) { | 16317 if (this->raw() == other.raw()) { |
| 16290 // Both handles point to the same raw instance. | 16318 // Both handles point to the same raw instance. |
| 16291 return true; | 16319 return true; |
| (...skipping 1287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 17579 return "_MirrorReference"; | 17607 return "_MirrorReference"; |
| 17580 } | 17608 } |
| 17581 | 17609 |
| 17582 | 17610 |
| 17583 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 17611 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 17584 Instance::PrintToJSONStream(stream, ref); | 17612 Instance::PrintToJSONStream(stream, ref); |
| 17585 } | 17613 } |
| 17586 | 17614 |
| 17587 | 17615 |
| 17588 } // namespace dart | 17616 } // namespace dart |
| OLD | NEW |