Implement the 'name' field for types

refs #9076
This commit is contained in:
Gunnar Beutner 2015-08-26 13:05:09 +02:00
parent b09dccb294
commit 3afe9a35d8

View File

@ -103,7 +103,7 @@ void Type::SetPrototype(const Object::Ptr& object)
void Type::SetField(int id, const Value& value, bool suppress_events, const Value& cookie) void Type::SetField(int id, const Value& value, bool suppress_events, const Value& cookie)
{ {
if (id == 0) { if (id == 1) {
SetPrototype(value); SetPrototype(value);
return; return;
} }
@ -114,8 +114,10 @@ void Type::SetField(int id, const Value& value, bool suppress_events, const Valu
Value Type::GetField(int id) const Value Type::GetField(int id) const
{ {
if (id == 0) if (id == 0)
return GetPrototype(); return GetName();
else if (id == 1) else if (id == 1)
return GetPrototype();
else if (id == 2)
return GetBaseType(); return GetBaseType();
return Object::GetField(id); return Object::GetField(id);
@ -148,10 +150,14 @@ int TypeType::GetAttributes(void) const
int TypeType::GetFieldId(const String& name) const int TypeType::GetFieldId(const String& name) const
{ {
if (name == "prototype") int base_field_count = GetBaseType()->GetFieldCount();
return GetBaseType()->GetFieldCount() + 0;
if (name == "name")
return base_field_count + 0;
else if (name == "prototype")
return base_field_count + 1;
else if (name == "base") else if (name == "base")
return GetBaseType()->GetFieldCount() + 1; return base_field_count + 2;
return GetBaseType()->GetFieldId(name); return GetBaseType()->GetFieldId(name);
} }
@ -163,16 +169,18 @@ Field TypeType::GetFieldInfo(int id) const
return GetBaseType()->GetFieldInfo(id); return GetBaseType()->GetFieldInfo(id);
if (id == 0) if (id == 0)
return Field(0, "Object", "prototype", NULL, 0, 0); return Field(0, "String", "name", NULL, 0, 0);
else if (id == 1) else if (id == 1)
return Field(1, "Type", "base", NULL, 0, 0); return Field(1, "Object", "prototype", NULL, 0, 0);
else if (id == 2)
return Field(2, "Type", "base", NULL, 0, 0);
throw std::runtime_error("Invalid field ID."); throw std::runtime_error("Invalid field ID.");
} }
int TypeType::GetFieldCount(void) const int TypeType::GetFieldCount(void) const
{ {
return GetBaseType()->GetFieldCount() + 2; return GetBaseType()->GetFieldCount() + 3;
} }
ObjectFactory TypeType::GetFactory(void) const ObjectFactory TypeType::GetFactory(void) const