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,16 +46,31 @@ int PrimitiveType::GetAttributes(void) const
int PrimitiveType::GetFieldId(const String& name) const
{
Type::Ptr base = GetBaseType();
if (base)
return base->GetFieldId(name);
else
return -1;
}
Field PrimitiveType::GetFieldInfo(int id) const
{
Type::Ptr base = GetBaseType();
if (base)
return base->GetFieldInfo(id);
else
throw std::runtime_error("Invalid field ID.");
}
int PrimitiveType::GetFieldCount(void) const
{
Type::Ptr base = GetBaseType();
if (base)
return Object::TypeInstance->GetFieldCount();
else
return 0;
}

View File

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