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

Unified Diff: runtime/vm/class_finalizer.cc

Issue 2498863002: Map deleted enum values to a sentinel value. (Closed)
Patch Set: asiva review Created 4 years, 1 month 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 | « runtime/tests/vm/vm.status ('k') | runtime/vm/isolate_reload_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/class_finalizer.cc
diff --git a/runtime/vm/class_finalizer.cc b/runtime/vm/class_finalizer.cc
index 98d74ff073efddae795a4921b18cbceedb87f616..dafa69eaffec19c123bc3f44c9cc78c8894a8c18 100644
--- a/runtime/vm/class_finalizer.cc
+++ b/runtime/vm/class_finalizer.cc
@@ -2478,17 +2478,31 @@ void ClassFinalizer::AllocateEnumValues(const Class& enum_cls) {
ASSERT(Instance::Handle(zone, values_field.StaticValue()).IsArray());
Array& values_list =
Array::Handle(zone, Array::RawCast(values_field.StaticValue()));
+ const String& enum_name = String::Handle(enum_cls.ScrubbedName());
+ const String& name_prefix =
+ String::Handle(String::Concat(enum_name, Symbols::Dot()));
- const Array& fields = Array::Handle(zone, enum_cls.fields());
Field& field = Field::Handle(zone);
Instance& ordinal_value = Instance::Handle(zone);
Instance& enum_value = Instance::Handle(zone);
- const String& enum_name = String::Handle(enum_cls.ScrubbedName());
- const String& name_prefix =
- String::Handle(String::Concat(enum_name, Symbols::Dot()));
-
String& enum_ident = String::Handle();
+
+ enum_ident =
+ Symbols::FromConcat(thread, Symbols::_DeletedEnumPrefix(), enum_name);
+ enum_value = Instance::New(enum_cls, Heap::kOld);
+ enum_value.SetField(index_field, Smi::Handle(zone, Smi::New(-1)));
+ enum_value.SetField(name_field, enum_ident);
+ const char* error_msg = NULL;
+ enum_value = enum_value.CheckAndCanonicalize(thread, &error_msg);
+ ASSERT(!enum_value.IsNull());
+ ASSERT(enum_value.IsCanonical());
+ field = enum_cls.LookupStaticField(Symbols::_DeletedEnumSentinel());
+ ASSERT(!field.IsNull());
+ field.SetStaticValue(enum_value, true);
+ field.RecordStore(enum_value);
+
+ const Array& fields = Array::Handle(zone, enum_cls.fields());
for (intptr_t i = 0; i < fields.Length(); i++) {
field = Field::RawCast(fields.At(i));
if (!field.is_static()) continue;
@@ -2509,7 +2523,6 @@ void ClassFinalizer::AllocateEnumValues(const Class& enum_cls) {
enum_value = Instance::New(enum_cls, Heap::kOld);
enum_value.SetField(index_field, ordinal_value);
enum_value.SetField(name_field, enum_ident);
- const char* error_msg = "";
enum_value = enum_value.CheckAndCanonicalize(thread, &error_msg);
ASSERT(!enum_value.IsNull());
ASSERT(enum_value.IsCanonical());
@@ -2520,7 +2533,6 @@ void ClassFinalizer::AllocateEnumValues(const Class& enum_cls) {
values_list.SetAt(ord, enum_value);
}
values_list.MakeImmutable();
- const char* error_msg = NULL;
values_list ^= values_list.CheckAndCanonicalize(thread, &error_msg);
ASSERT(!values_list.IsNull());
}
« no previous file with comments | « runtime/tests/vm/vm.status ('k') | runtime/vm/isolate_reload_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698