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

Side by Side Diff: runtime/vm/isolate_reload_test.cc

Issue 2489723003: Run field initializers for new instance fields after a reload (Closed)
Patch Set: 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "include/dart_api.h" 5 #include "include/dart_api.h"
6 #include "include/dart_tools_api.h" 6 #include "include/dart_tools_api.h"
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/globals.h" 8 #include "vm/globals.h"
9 #include "vm/isolate.h" 9 #include "vm/isolate.h"
10 #include "vm/lockers.h" 10 #include "vm/lockers.h"
(...skipping 3111 matching lines...) Expand 10 before | Expand all | Expand 10 after
3122 "const value = const Duration(seconds: 2);\n" 3122 "const value = const Duration(seconds: 2);\n"
3123 "main() {\n" 3123 "main() {\n"
3124 " return 'value=${value}';\n" 3124 " return 'value=${value}';\n"
3125 "}\n"; 3125 "}\n";
3126 3126
3127 lib = TestCase::ReloadTestScript(kReloadScript); 3127 lib = TestCase::ReloadTestScript(kReloadScript);
3128 EXPECT_VALID(lib); 3128 EXPECT_VALID(lib);
3129 EXPECT_STREQ("value=0:00:02.000000", SimpleInvokeStr(lib, "main")); 3129 EXPECT_STREQ("value=0:00:02.000000", SimpleInvokeStr(lib, "main"));
3130 } 3130 }
3131 3131
3132
3133 TEST_CASE(IsolateReload_RunNewFieldInitializers) {
3134 const char* kScript =
3135 "class Foo {\n"
3136 " int x = 4;\n"
3137 "}\n"
3138 "Foo value;\n"
3139 "main() {\n"
3140 " value = new Foo();\n"
3141 " return value.x;\n"
3142 "}\n";
3143
3144 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
3145 EXPECT_VALID(lib);
3146 EXPECT_EQ(4, SimpleInvoke(lib, "main"));
3147
3148 // Add the field y.
3149 const char* kReloadScript =
3150 "class Foo {\n"
3151 " int x = 4;\n"
3152 " int y = 7;\n"
3153 "}\n"
3154 "Foo value;\n"
3155 "main() {\n"
3156 " return value.y;\n"
3157 "}\n";
3158
3159 lib = TestCase::ReloadTestScript(kReloadScript);
3160 EXPECT_VALID(lib);
3161 // Verify that we ran field initializers on existing instances.
3162 EXPECT_EQ(7, SimpleInvoke(lib, "main"));
3163 }
3164
3165
3166 TEST_CASE(IsolateReload_RunNewFieldInitializersReferenceStaticField) {
3167 const char* kScript =
3168 "int myInitialValue = 8 * 7;\n"
3169 "class Foo {\n"
3170 " int x = 4;\n"
3171 "}\n"
3172 "Foo value;\n"
3173 "main() {\n"
3174 " value = new Foo();\n"
3175 " return value.x;\n"
3176 "}\n";
3177
3178 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
3179 EXPECT_VALID(lib);
3180 EXPECT_EQ(4, SimpleInvoke(lib, "main"));
3181
3182 // Add the field y.
3183 const char* kReloadScript =
3184 "int myInitialValue = 8 * 7;\n"
3185 "class Foo {\n"
3186 " int x = 4;\n"
3187 " int y = myInitialValue;\n"
3188 "}\n"
3189 "Foo value;\n"
3190 "main() {\n"
3191 " return value.y;\n"
3192 "}\n";
3193
3194 lib = TestCase::ReloadTestScript(kReloadScript);
3195 EXPECT_VALID(lib);
3196 // Verify that we ran field initializers on existing instances.
3197 EXPECT_EQ(56, SimpleInvoke(lib, "main"));
3198 }
3199
3200
3201 // The following test is expected to fail because of how we run the initializing
3202 // expression during reload compared to how it actually runs when the
3203 // constructor is invoked.
rmacnak 2016/11/09 00:36:32 I don't see why this should fail. Static field acc
Cutch 2016/11/09 23:20:58 Fails because of an ordering bug in my CL. Works n
3204 TEST_CASE(IsolateReload_RunNewFieldInitializersMutateStaticField) {
3205 const char* kScript =
3206 "int myInitialValue = 8 * 7;\n"
3207 "class Foo {\n"
3208 " int x = 4;\n"
3209 "}\n"
3210 "Foo value;\n"
3211 "Foo value1;\n"
3212 "main() {\n"
3213 " value = new Foo();\n"
3214 " value1 = new Foo();\n"
3215 " return value.x;\n"
3216 "}\n";
3217
3218 Dart_Handle lib = TestCase::LoadTestScript(kScript, NULL);
3219 EXPECT_VALID(lib);
3220 EXPECT_EQ(4, SimpleInvoke(lib, "main"));
3221
3222 // Add the field y.
3223 const char* kReloadScript =
3224 "int myInitialValue = 8 * 7;\n"
3225 "class Foo {\n"
3226 " int x = 4;\n"
3227 " int y = myInitialValue++;\n"
3228 "}\n"
3229 "Foo value;\n"
3230 "Foo value1;\n"
3231 "main() {\n"
3232 " new Foo();"
3233 " return myInitialValue;\n"
3234 "}\n";
3235
3236 lib = TestCase::ReloadTestScript(kReloadScript);
3237 EXPECT_VALID(lib);
3238 // Verify that we ran field initializers on existing instances and that
3239 // they affected the value of the field myInitialValue.
3240 EXPECT_EQ(59, SimpleInvoke(lib, "main"));
3241 }
rmacnak 2016/11/09 00:36:32 Add a test where the new initializer throws. Add
Cutch 2016/11/09 23:20:58 Done.
3132 #endif // !PRODUCT 3242 #endif // !PRODUCT
3133 3243
3134 } // namespace dart 3244 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698