Fix 'Invalid field ID' error when serializing Type objects

refs #10387
This commit is contained in:
Gunnar Beutner 2015-11-05 10:52:25 +01:00
parent 701961b73b
commit 783b58536f
2 changed files with 22 additions and 7 deletions

View File

@ -46,17 +46,32 @@ int PrimitiveType::GetAttributes(void) const
int PrimitiveType::GetFieldId(const String& name) const int PrimitiveType::GetFieldId(const String& name) const
{ {
return -1; Type::Ptr base = GetBaseType();
if (base)
return base->GetFieldId(name);
else
return -1;
} }
Field PrimitiveType::GetFieldInfo(int id) const Field PrimitiveType::GetFieldInfo(int id) const
{ {
throw std::runtime_error("Invalid field ID."); Type::Ptr base = GetBaseType();
if (base)
return base->GetFieldInfo(id);
else
throw std::runtime_error("Invalid field ID.");
} }
int PrimitiveType::GetFieldCount(void) const int PrimitiveType::GetFieldCount(void) const
{ {
return 0; Type::Ptr base = GetBaseType();
if (base)
return Object::TypeInstance->GetFieldCount();
else
return 0;
} }
ObjectFactory PrimitiveType::GetFactory(void) const ObjectFactory PrimitiveType::GetFactory(void) const

View File

@ -121,7 +121,7 @@ Value Type::GetField(int id) const
else if (id == 2) else if (id == 2)
return GetBaseType(); return GetBaseType();
return Object::GetField(id); return Object::GetField(id - 3);
} }
std::vector<String> Type::GetLoadDependencies(void) const std::vector<String> Type::GetLoadDependencies(void) const
@ -169,11 +169,11 @@ Field TypeType::GetFieldInfo(int id) const
if (real_id < 0) if (real_id < 0)
return GetBaseType()->GetFieldInfo(id); return GetBaseType()->GetFieldInfo(id);
if (id == 0) if (real_id == 0)
return Field(0, "String", "name", "", NULL, 0, 0); return Field(0, "String", "name", "", NULL, 0, 0);
else if (id == 1) else if (real_id == 1)
return Field(1, "Object", "prototype", "", NULL, 0, 0); return Field(1, "Object", "prototype", "", NULL, 0, 0);
else if (id == 2) else if (real_id == 2)
return Field(2, "Type", "base", "", NULL, 0, 0); return Field(2, "Type", "base", "", NULL, 0, 0);
throw std::runtime_error("Invalid field ID."); throw std::runtime_error("Invalid field ID.");