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

Unified Diff: tests/compiler/dart2js_extra/mirror_invalid_field_access4_test.dart

Issue 23045004: Throw when reflecting on elements not covered by a `MirrorsUsed` annotation. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address Nicolas' comments. Created 7 years, 4 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
Index: tests/compiler/dart2js_extra/mirror_invalid_field_access4_test.dart
diff --git a/tests/compiler/dart2js_extra/mirror_invalid_field_access4_test.dart b/tests/compiler/dart2js_extra/mirror_invalid_field_access4_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..cdd562e34649624f0f758a2685745af92b3d8b73
--- /dev/null
+++ b/tests/compiler/dart2js_extra/mirror_invalid_field_access4_test.dart
@@ -0,0 +1,40 @@
+// Copyright (c) 2013, 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.
+
+// Test that we cannot reflect on elements not covered by the `MirrorsUsed`
+// annotation.
+
+library test;
+
+@MirrorsUsed(targets: 'C.foo')
+import 'dart:mirrors';
+
+import 'package:expect/expect.dart';
+
+class C {
+ var foo;
+ var bar;
+}
+
+class D {
+ get bar {}
+ set bar(x) {}
+}
+
+int inscrutable(int x) => x == 0 ? 0 : x | inscrutable(x & (x - 1));
+
+main() {
+ var c = inscrutable(1) == 1 ? new C() : new D();
+
+ c.bar = 1;
+ var local = c.bar;
+
+ var mirror = reflect(c);
+ Expect.equals(1, mirror.setField(const Symbol('foo'), 1).reflectee);
+ Expect.equals(1, mirror.getField(const Symbol('foo')).reflectee);
+ Expect.throws(() => mirror.setField(const Symbol('bar'), 2),
+ (e) => e is UnsupportedError);
+ Expect.throws(() => mirror.getField(const Symbol('bar')),
+ (e) => e is UnsupportedError);
+}

Powered by Google App Engine
This is Rietveld 408576698