Index: runtime/vm/object.cc |
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc |
index 394ce89c0c5faf78296ee4719e15c285e4f14c81..bbcd0572f6fb86bee239527d3bc59ff6ae170a75 100644 |
--- a/runtime/vm/object.cc |
+++ b/runtime/vm/object.cc |
@@ -1556,10 +1556,39 @@ void Object::Print() const { |
} |
+static void AddNameProperties(JSONObject* jsobj, |
+ const String& name, |
+ const String& vm_name) { |
+ jsobj->AddProperty("name", name.ToCString()); |
+ if (!name.Equals(vm_name)) { |
+ jsobj->AddProperty("_vmName", vm_name.ToCString()); |
+ } |
+} |
+ |
+ |
+static void AddTypeProperties(JSONObject* jsobj, |
+ const char* user_type, |
+ const char* vm_type, |
+ bool ref) { |
+ bool same_type = (strcmp(user_type, vm_type) == 0); |
+ if (ref) { |
+ jsobj->AddPropertyF("type", "@%s", user_type); |
+ if (!same_type) { |
+ jsobj->AddPropertyF("_vmType", "@%s", vm_type); |
+ } |
+ } else { |
+ jsobj->AddProperty("type", user_type); |
+ if (!same_type) { |
+ jsobj->AddProperty("_vmType", vm_type); |
+ } |
+ } |
+} |
+ |
+ |
void Object::PrintJSON(JSONStream* stream, bool ref) const { |
if (IsNull()) { |
JSONObject jsobj(stream); |
- jsobj.AddProperty("type", ref ? "@Null" : "Null"); |
+ AddTypeProperties(&jsobj, "null", JSONType(), ref); |
jsobj.AddProperty("id", "objects/null"); |
jsobj.AddProperty("valueAsString", "null"); |
if (!ref) { |
@@ -1573,6 +1602,15 @@ void Object::PrintJSON(JSONStream* stream, bool ref) const { |
} |
+void Object::PrintJSONImpl(JSONStream* stream, bool ref) const { |
+ JSONObject jsobj(stream); |
+ AddTypeProperties(&jsobj, "Object", JSONType(), ref); |
+ ObjectIdRing* ring = Isolate::Current()->object_id_ring(); |
+ const intptr_t id = ring->GetIdForObject(raw()); |
+ jsobj.AddPropertyF("id", "objects/%" Pd "", id); |
+} |
+ |
+ |
RawString* Object::DictionaryName() const { |
return String::null(); |
} |
@@ -4103,23 +4141,13 @@ const char* Class::ToCString() const { |
} |
-static void AddNameProperties(JSONObject* jsobj, |
- const String& name, |
- const String& vm_name) { |
- jsobj->AddProperty("name", name.ToCString()); |
- if (!name.Equals(vm_name)) { |
- jsobj->AddProperty("vmName", vm_name.ToCString()); |
- } |
-} |
- |
- |
void Class::PrintJSONImpl(JSONStream* stream, bool ref) const { |
JSONObject jsobj(stream); |
if ((raw() == Class::null()) || (id() == kFreeListElement)) { |
jsobj.AddProperty("type", "Null"); |
return; |
} |
- jsobj.AddProperty("type", JSONType(ref)); |
+ AddTypeProperties(&jsobj, "Class", JSONType(), ref); |
jsobj.AddPropertyF("id", "classes/%" Pd "", id()); |
const String& user_name = String::Handle(PrettyName()); |
const String& vm_name = String::Handle(Name()); |
@@ -4457,7 +4485,7 @@ void TypeArguments::PrintJSONImpl(JSONStream* stream, bool ref) const { |
ASSERT(table.Length() > 0); |
ObjectIdRing* ring = Isolate::Current()->object_id_ring(); |
const intptr_t id = ring->GetIdForObject(raw()); |
- jsobj.AddProperty("type", JSONType(ref)); |
+ AddTypeProperties(&jsobj, "TypeArguments", JSONType(), ref); |
jsobj.AddPropertyF("id", "objects/%" Pd "", id); |
const String& user_name = String::Handle(PrettyName()); |
const String& vm_name = String::Handle(Name()); |
@@ -6807,7 +6835,7 @@ void Function::PrintJSONImpl(JSONStream* stream, bool ref) const { |
err ^= cls.EnsureIsFinalized(Isolate::Current()); |
ASSERT(err.IsNull()); |
JSONObject jsobj(stream); |
- jsobj.AddProperty("type", JSONType(ref)); |
+ AddTypeProperties(&jsobj, "Function", JSONType(), ref); |
koda
2014/09/05 21:29:29
Might it not be useful to move the name string int
turnidge
2014/09/08 16:20:19
We will only use the function in this one location
|
jsobj.AddProperty("id", GetFunctionServiceId(*this, cls)); |
const String& user_name = String::Handle(PrettyName()); |
const String& vm_name = String::Handle(name()); |
@@ -7153,7 +7181,7 @@ void Field::PrintJSONImpl(JSONStream* stream, bool ref) const { |
intptr_t id = cls.FindFieldIndex(*this); |
ASSERT(id >= 0); |
intptr_t cid = cls.id(); |
- jsobj.AddProperty("type", JSONType(ref)); |
+ AddTypeProperties(&jsobj, "Field", JSONType(), ref); |
jsobj.AddPropertyF("id", "classes/%" Pd "/fields/%" Pd "", cid, id); |
const String& user_name = String::Handle(PrettyName()); |
const String& vm_name = String::Handle(name()); |
@@ -8473,7 +8501,7 @@ RawLibrary* Script::FindLibrary() const { |
// See also Dart_ScriptGetTokenInfo. |
void Script::PrintJSONImpl(JSONStream* stream, bool ref) const { |
JSONObject jsobj(stream); |
- jsobj.AddProperty("type", JSONType(ref)); |
+ AddTypeProperties(&jsobj, "Script", JSONType(), ref); |
const String& name = String::Handle(url()); |
ASSERT(!name.IsNull()); |
const String& encoded_url = String::Handle(String::EncodeIRI(name)); |
@@ -9766,7 +9794,7 @@ void Library::PrintJSONImpl(JSONStream* stream, bool ref) const { |
intptr_t id = index(); |
ASSERT(id >= 0); |
JSONObject jsobj(stream); |
- jsobj.AddProperty("type", JSONType(ref)); |
+ AddTypeProperties(&jsobj, "Library", JSONType(), ref); |
jsobj.AddPropertyF("id", "libraries/%" Pd "", id); |
jsobj.AddProperty("name", library_name); |
const char* library_url = String::Handle(url()).ToCString(); |
@@ -10553,7 +10581,7 @@ const char* PcDescriptors::ToCString() const { |
void PcDescriptors::PrintToJSONObject(JSONObject* jsobj) const { |
- jsobj->AddProperty("type", JSONType(false)); |
+ AddTypeProperties(jsobj, "Object", JSONType(), false); |
// TODO(johnmccutchan): Generate a valid ID. |
// PcDescriptors hang off a Code object but do not have a back reference to |
// generate an ID. Currently we only print PcDescriptors inline with a Code. |
@@ -12281,7 +12309,7 @@ RawString* Code::PrettyName() const { |
void Code::PrintJSONImpl(JSONStream* stream, bool ref) const { |
JSONObject jsobj(stream); |
- jsobj.AddProperty("type", JSONType(ref)); |
+ AddTypeProperties(&jsobj, "Code", JSONType(), ref); |
jsobj.AddPropertyF("id", "code/%" Px64"-%" Px "", compile_timestamp(), |
EntryPoint()); |
jsobj.AddPropertyF("start", "%" Px "", EntryPoint()); |
@@ -12444,7 +12472,9 @@ void Context::Dump(int indent) const { |
void Context::PrintJSONImpl(JSONStream* stream, bool ref) const { |
JSONObject jsobj(stream); |
- jsobj.AddProperty("type", JSONType(ref)); |
+ // TODO(turnidge): Should the user level type for Context be Context |
+ // or Object? |
+ AddTypeProperties(&jsobj, "Context", JSONType(), ref); |
ObjectIdRing* ring = Isolate::Current()->object_id_ring(); |
const intptr_t id = ring->GetIdForObject(raw()); |
jsobj.AddPropertyF("id", "objects/%" Pd "", id); |
@@ -12844,9 +12874,8 @@ const char* ApiError::ToCString() const { |
void ApiError::PrintJSONImpl(JSONStream* stream, bool ref) const { |
JSONObject jsobj(stream); |
- jsobj.AddProperty("type", "Error"); |
+ AddTypeProperties(&jsobj, "Error", JSONType(), ref); |
jsobj.AddProperty("id", ""); |
- jsobj.AddProperty("kind", JSONType(false)); |
jsobj.AddProperty("message", ToErrorCString()); |
} |
@@ -12983,9 +13012,8 @@ const char* LanguageError::ToCString() const { |
void LanguageError::PrintJSONImpl(JSONStream* stream, bool ref) const { |
JSONObject jsobj(stream); |
- jsobj.AddProperty("type", "Error"); |
+ AddTypeProperties(&jsobj, "Error", JSONType(), ref); |
jsobj.AddProperty("id", ""); |
- jsobj.AddProperty("kind", JSONType(false)); |
jsobj.AddProperty("message", ToErrorCString()); |
} |
@@ -13078,9 +13106,8 @@ const char* UnhandledException::ToCString() const { |
void UnhandledException::PrintJSONImpl(JSONStream* stream, |
bool ref) const { |
JSONObject jsobj(stream); |
- jsobj.AddProperty("type", "Error"); |
+ AddTypeProperties(&jsobj, "Error", JSONType(), ref); |
jsobj.AddProperty("id", ""); |
- jsobj.AddProperty("kind", JSONType(false)); |
jsobj.AddProperty("message", ToErrorCString()); |
Instance& instance = Instance::Handle(); |
@@ -13124,9 +13151,8 @@ const char* UnwindError::ToCString() const { |
void UnwindError::PrintJSONImpl(JSONStream* stream, bool ref) const { |
JSONObject jsobj(stream); |
- jsobj.AddProperty("type", "Error"); |
+ AddTypeProperties(&jsobj, "Error", JSONType(), ref); |
jsobj.AddProperty("id", ""); |
- jsobj.AddProperty("kind", JSONType(false)); |
jsobj.AddProperty("message", ToErrorCString()); |
} |
@@ -13569,8 +13595,8 @@ const char* Instance::ToCString() const { |
} |
-void Instance::PrintSharedInstanceJSON(JSONObject* jsobj, bool ref) const { |
- jsobj->AddProperty("type", JSONType(ref)); |
+void Instance::PrintSharedInstanceJSON(JSONObject* jsobj, |
+ bool ref) const { |
Class& cls = Class::Handle(this->clazz()); |
jsobj->AddProperty("class", cls); |
// TODO(turnidge): Provide the type arguments here too. |
@@ -13616,15 +13642,6 @@ void Instance::PrintSharedInstanceJSON(JSONObject* jsobj, bool ref) const { |
} |
-void Object::PrintJSONImpl(JSONStream* stream, bool ref) const { |
- JSONObject jsobj(stream); |
- jsobj.AddProperty("type", JSONType(ref)); |
- ObjectIdRing* ring = Isolate::Current()->object_id_ring(); |
- const intptr_t id = ring->GetIdForObject(raw()); |
- jsobj.AddPropertyF("id", "objects/%" Pd "", id); |
-} |
- |
- |
void Instance::PrintJSONImpl(JSONStream* stream, bool ref) const { |
JSONObject jsobj(stream); |
@@ -13641,6 +13658,7 @@ void Instance::PrintJSONImpl(JSONStream* stream, bool ref) const { |
return; |
} |
+ AddTypeProperties(&jsobj, "Instance", JSONType(), ref); |
PrintSharedInstanceJSON(&jsobj, ref); |
ObjectIdRing* ring = Isolate::Current()->object_id_ring(); |
const intptr_t id = ring->GetIdForObject(raw()); |
@@ -14708,6 +14726,7 @@ const char* Type::ToCString() const { |
void Type::PrintJSONImpl(JSONStream* stream, bool ref) const { |
JSONObject jsobj(stream); |
+ AddTypeProperties(&jsobj, "Type", JSONType(), ref); |
PrintSharedInstanceJSON(&jsobj, ref); |
if (IsCanonical()) { |
const Class& type_cls = Class::Handle(type_class()); |
@@ -14880,6 +14899,7 @@ const char* TypeRef::ToCString() const { |
void TypeRef::PrintJSONImpl(JSONStream* stream, bool ref) const { |
JSONObject jsobj(stream); |
+ AddTypeProperties(&jsobj, "TypeRef", JSONType(), ref); |
PrintSharedInstanceJSON(&jsobj, ref); |
ObjectIdRing* ring = Isolate::Current()->object_id_ring(); |
const intptr_t id = ring->GetIdForObject(raw()); |
@@ -15096,6 +15116,7 @@ const char* TypeParameter::ToCString() const { |
void TypeParameter::PrintJSONImpl(JSONStream* stream, bool ref) const { |
JSONObject jsobj(stream); |
+ AddTypeProperties(&jsobj, "TypeParameter", JSONType(), ref); |
PrintSharedInstanceJSON(&jsobj, ref); |
ObjectIdRing* ring = Isolate::Current()->object_id_ring(); |
const intptr_t id = ring->GetIdForObject(raw()); |
@@ -15299,6 +15320,7 @@ const char* BoundedType::ToCString() const { |
void BoundedType::PrintJSONImpl(JSONStream* stream, bool ref) const { |
JSONObject jsobj(stream); |
+ AddTypeProperties(&jsobj, "BoundedType", JSONType(), ref); |
PrintSharedInstanceJSON(&jsobj, ref); |
ObjectIdRing* ring = Isolate::Current()->object_id_ring(); |
const intptr_t id = ring->GetIdForObject(raw()); |
@@ -15392,12 +15414,7 @@ const char* Number::ToCString() const { |
void Number::PrintJSONImpl(JSONStream* stream, bool ref) const { |
- JSONObject jsobj(stream); |
- PrintSharedInstanceJSON(&jsobj, ref); |
- ObjectIdRing* ring = Isolate::Current()->object_id_ring(); |
- const intptr_t id = ring->GetIdForObject(raw()); |
- jsobj.AddPropertyF("id", "objects/%" Pd "", id); |
- jsobj.AddProperty("valueAsString", ToCString()); |
+ UNREACHABLE(); |
} |
@@ -15409,7 +15426,13 @@ const char* Integer::ToCString() const { |
void Integer::PrintJSONImpl(JSONStream* stream, bool ref) const { |
- Number::PrintJSONImpl(stream, ref); |
+ JSONObject jsobj(stream); |
+ AddTypeProperties(&jsobj, "int", JSONType(), ref); |
+ PrintSharedInstanceJSON(&jsobj, ref); |
+ ObjectIdRing* ring = Isolate::Current()->object_id_ring(); |
+ const intptr_t id = ring->GetIdForObject(raw()); |
+ jsobj.AddPropertyF("id", "objects/%" Pd "", id); |
+ jsobj.AddProperty("valueAsString", ToCString()); |
} |
@@ -15842,6 +15865,7 @@ const char* Smi::ToCString() const { |
void Smi::PrintJSONImpl(JSONStream* stream, bool ref) const { |
JSONObject jsobj(stream); |
+ AddTypeProperties(&jsobj, "int", JSONType(), ref); |
PrintSharedInstanceJSON(&jsobj, ref); |
jsobj.AddPropertyF("id", "objects/int-%" Pd "", Value()); |
jsobj.AddPropertyF("valueAsString", "%" Pd "", Value()); |
@@ -15968,7 +15992,7 @@ const char* Mint::ToCString() const { |
void Mint::PrintJSONImpl(JSONStream* stream, bool ref) const { |
- Number::PrintJSONImpl(stream, ref); |
+ Integer::PrintJSONImpl(stream, ref); |
} |
@@ -16100,7 +16124,15 @@ const char* Double::ToCString() const { |
void Double::PrintJSONImpl(JSONStream* stream, bool ref) const { |
- Number::PrintJSONImpl(stream, ref); |
+ JSONObject jsobj(stream); |
+ // Suppress the fact that the internal vm name for this type is |
+ // "Double". Return "double" instead. |
+ AddTypeProperties(&jsobj, "double", "double", ref); |
+ PrintSharedInstanceJSON(&jsobj, ref); |
+ ObjectIdRing* ring = Isolate::Current()->object_id_ring(); |
+ const intptr_t id = ring->GetIdForObject(raw()); |
+ jsobj.AddPropertyF("id", "objects/%" Pd "", id); |
+ jsobj.AddProperty("valueAsString", ToCString()); |
} |
@@ -16276,7 +16308,7 @@ const char* Bigint::ToCString() const { |
void Bigint::PrintJSONImpl(JSONStream* stream, bool ref) const { |
- Number::PrintJSONImpl(stream, ref); |
+ Integer::PrintJSONImpl(stream, ref); |
} |
@@ -17191,6 +17223,7 @@ void String::PrintJSONImpl(JSONStream* stream, bool ref) const { |
jsobj.AddProperty("valueAsString", "<optimized out>"); |
return; |
} |
+ AddTypeProperties(&jsobj, "String", JSONType(), ref); |
PrintSharedInstanceJSON(&jsobj, ref); |
ObjectIdRing* ring = Isolate::Current()->object_id_ring(); |
const intptr_t id = ring->GetIdForObject(raw()); |
@@ -18060,10 +18093,11 @@ const char* Bool::ToCString() const { |
void Bool::PrintJSONImpl(JSONStream* stream, bool ref) const { |
const char* str = ToCString(); |
JSONObject jsobj(stream); |
- jsobj.AddProperty("type", JSONType(ref)); |
+ // Suppress the fact that the internal vm name for this type is |
+ // "Bool". Return "bool" instead. |
+ AddTypeProperties(&jsobj, "bool", "bool", ref); |
+ PrintSharedInstanceJSON(&jsobj, ref); |
jsobj.AddPropertyF("id", "objects/bool-%s", str); |
- const Class& cls = Class::Handle(this->clazz()); |
- jsobj.AddProperty("class", cls); |
jsobj.AddPropertyF("valueAsString", "%s", str); |
} |
@@ -18181,6 +18215,7 @@ const char* Array::ToCString() const { |
void Array::PrintJSONImpl(JSONStream* stream, bool ref) const { |
JSONObject jsobj(stream); |
+ AddTypeProperties(&jsobj, "List", JSONType(), ref); |
PrintSharedInstanceJSON(&jsobj, ref); |
ObjectIdRing* ring = Isolate::Current()->object_id_ring(); |
const intptr_t id = ring->GetIdForObject(raw()); |
@@ -18425,6 +18460,7 @@ const char* GrowableObjectArray::ToCString() const { |
void GrowableObjectArray::PrintJSONImpl(JSONStream* stream, |
bool ref) const { |
JSONObject jsobj(stream); |
+ AddTypeProperties(&jsobj, "List", JSONType(), ref); |
PrintSharedInstanceJSON(&jsobj, ref); |
ObjectIdRing* ring = Isolate::Current()->object_id_ring(); |
const intptr_t id = ring->GetIdForObject(raw()); |
@@ -19484,6 +19520,7 @@ const char* WeakProperty::ToCString() const { |
void WeakProperty::PrintJSONImpl(JSONStream* stream, bool ref) const { |
JSONObject jsobj(stream); |
+ AddTypeProperties(&jsobj, "Instance", JSONType(), ref); |
PrintSharedInstanceJSON(&jsobj, ref); |
ObjectIdRing* ring = Isolate::Current()->object_id_ring(); |
const intptr_t id = ring->GetIdForObject(raw()); |
@@ -19557,6 +19594,7 @@ const char* MirrorReference::ToCString() const { |
void MirrorReference::PrintJSONImpl(JSONStream* stream, bool ref) const { |
JSONObject jsobj(stream); |
+ AddTypeProperties(&jsobj, "Instance", JSONType(), ref); |
PrintSharedInstanceJSON(&jsobj, ref); |
ObjectIdRing* ring = Isolate::Current()->object_id_ring(); |
const intptr_t id = ring->GetIdForObject(raw()); |