Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Unified Diff: base/values.cc

Issue 2804263002: IsValid (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/values.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/values.cc
diff --git a/base/values.cc b/base/values.cc
index d492a474631c841442d72851ebff94ff3d163241..c2850ac4d3104244233962202d2ef4d121aed688 100644
--- a/base/values.cc
+++ b/base/values.cc
@@ -197,6 +197,32 @@ const char* Value::GetTypeName(Value::Type type) {
return kTypeNames[static_cast<size_t>(type)];
}
+bool Value::IsValid() const {
+ switch (type_) {
+ case Type::NONE:
+ case Type::BOOLEAN:
+ case Type::INTEGER:
+ case Type::DOUBLE:
+ case Type::STRING:
+ case Type::BINARY:
+ return true;
+ case Type::DICTIONARY:
+ return *dict_ptr_ &&
+ std::all_of((*dict_ptr_)->begin(), (*dict_ptr_)->end(),
+ [](const DictStorage::value_type& val) {
+ return val.second && val.second->IsValid();
+ });
+ case Type::LIST:
+ return std::all_of(list_->begin(), list_->end(),
+ [](const std::unique_ptr<Value>& val) {
+ return val && val->IsValid();
+ });
+ }
+
+ NOTREACHED();
+ return false;
+}
+
bool Value::GetBool() const {
CHECK(is_bool());
return bool_value_;
@@ -675,6 +701,7 @@ void DictionaryValue::SetString(StringPiece path, const string16& in_value) {
void DictionaryValue::SetWithoutPathExpansion(StringPiece key,
std::unique_ptr<Value> in_value) {
(**dict_ptr_)[key.as_string()] = std::move(in_value);
+ CHECK(IsValid());
}
void DictionaryValue::SetWithoutPathExpansion(StringPiece key,
@@ -1093,6 +1120,8 @@ bool ListValue::Set(size_t index, std::unique_ptr<Value> in_value) {
DCHECK((*list_)[index] != in_value);
(*list_)[index] = std::move(in_value);
}
+
+ CHECK(IsValid());
return true;
}
@@ -1242,6 +1271,7 @@ ListValue::iterator ListValue::Erase(iterator iter,
void ListValue::Append(std::unique_ptr<Value> in_value) {
list_->push_back(std::move(in_value));
+ CHECK(IsValid());
}
#if !defined(OS_LINUX)
« no previous file with comments | « base/values.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698