From 783b58536f268311f81e6db1f185213a1db86303 Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Thu, 5 Nov 2015 10:52:25 +0100 Subject: [PATCH] Fix 'Invalid field ID' error when serializing Type objects refs #10387 --- lib/base/primitivetype.cpp | 21 ++++++++++++++++++--- lib/base/type.cpp | 8 ++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/lib/base/primitivetype.cpp b/lib/base/primitivetype.cpp index 6da74c466..67fea4f88 100644 --- a/lib/base/primitivetype.cpp +++ b/lib/base/primitivetype.cpp @@ -46,17 +46,32 @@ int PrimitiveType::GetAttributes(void) 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 { - 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 { - return 0; + Type::Ptr base = GetBaseType(); + + if (base) + return Object::TypeInstance->GetFieldCount(); + else + return 0; } ObjectFactory PrimitiveType::GetFactory(void) const diff --git a/lib/base/type.cpp b/lib/base/type.cpp index 33f6726a1..0a8ee7924 100644 --- a/lib/base/type.cpp +++ b/lib/base/type.cpp @@ -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 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.");