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

Unified Diff: tests/language/lazy_static8_test.dart

Issue 2620123002: Fix for 27467 - dart2js error with re-entrant static initializer (Closed)
Patch Set: Created 3 years, 11 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 | « sdk/lib/_internal/js_runtime/lib/js_helper.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/language/lazy_static8_test.dart
diff --git a/tests/language/lazy_static8_test.dart b/tests/language/lazy_static8_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..812219f7be0f4dd78d7ea0ac496a8c3f50be50d8
--- /dev/null
+++ b/tests/language/lazy_static8_test.dart
@@ -0,0 +1,73 @@
+// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import "package:expect/expect.dart";
+
+// Test re-entrant initializer - calls throw CyclicInitializationError.
+
+var trace;
+
+final foo = bar;
+
+get bar {
+ trace.add('bar');
+ try {
+ return foo ?? 1;
+ } catch (e) {
+ trace.add(e is CyclicInitializationError);
+ }
+ try {
+ return foo ?? 2;
+ } catch (e) {
+ trace.add(e is CyclicInitializationError);
+ }
+ return 42;
+}
+
+void testTopLevel() {
+ trace = [];
+ var result = foo;
+ Expect.equals(42, result);
+ Expect.equals('bar,true,true', trace.join(','));
+ trace = [];
+ result = foo;
+ Expect.equals(42, result);
+ Expect.equals('', trace.join(','));
+
+}
+
+class X {
+ static final foo = X.bar;
+
+ static get bar {
+ trace.add('X.bar');
+ try {
+ return foo ?? 1;
+ } catch (e) {
+ trace.add(e is CyclicInitializationError);
+ }
+ try {
+ return foo ?? 2;
+ } catch (e) {
+ trace.add(e is CyclicInitializationError);
+ }
+ return 49;
+ }
+}
+
+void testClassStatic() {
+ trace = [];
+ var result = X.foo;
+ Expect.equals(49, result);
+ Expect.equals('X.bar,true,true', trace.join(','));
+ trace = [];
+ result = X.foo;
+ Expect.equals(49, result);
+ Expect.equals('', trace.join(','));
+}
+
+main() {
+ testTopLevel();
+ testClassStatic();
+}
« no previous file with comments | « sdk/lib/_internal/js_runtime/lib/js_helper.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698