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

Unified Diff: tests/lib/mirrors/private_symbol_mangling_test.dart

Issue 425023002: Ensure that unmangled private names are unique. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 5 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/lib/mirrors/private_symbol_mangling_test.dart
diff --git a/tests/lib/mirrors/private_symbol_mangling_test.dart b/tests/lib/mirrors/private_symbol_mangling_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..7ac0753cf1057460e133c98c59b71e5ac8125ced
--- /dev/null
+++ b/tests/lib/mirrors/private_symbol_mangling_test.dart
@@ -0,0 +1,71 @@
+// Copyright (c) 2014, 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.
+
+library main;
+
+//@MirrorsUsed(targets: const ['C1', 'C2', '_privateGlobalField', '_privateGlobalMethod'])
+import 'dart:mirrors';
+import 'package:expect/expect.dart';
+import 'private_symbol_mangling_lib.dart';
+
+var _privateGlobalField = 1;
+
+_privateGlobalMethod() => 9;
+
+class C1 {
+ var _privateField = 0;
+ _privateMethod() => 2;
+}
+
+getPrivateGlobalFieldValue(LibraryMirror lib) {
+ for (Symbol symbol in lib.declarations.keys) {
+ DeclarationMirror decl = lib.declarations[symbol];
+ if (decl is VariableMirror) {
+ return lib.getField(symbol).reflectee;
+ }
+ }
+}
+
+getPrivateFieldValue(InstanceMirror cls) {
+ for (Symbol symbol in cls.type.declarations.keys) {
+ DeclarationMirror decl = cls.type.declarations[symbol];
+ if (decl is VariableMirror) {
+ return cls.getField(symbol).reflectee;
+ }
+ }
+}
+
+getPrivateGlobalMethodValue(LibraryMirror lib) {
+ for (Symbol symbol in lib.declarations.keys) {
+ DeclarationMirror decl = lib.declarations[symbol];
+ if (decl is MethodMirror && decl.isRegularMethod) {
+ return lib.invoke(symbol, []).reflectee;
+ }
+ }
+}
+
+getPrivateMethodValue(InstanceMirror cls) {
+ for (Symbol symbol in cls.type.declarations.keys) {
+ DeclarationMirror decl = cls.type.declarations[symbol];
+ if (decl is MethodMirror && decl.isRegularMethod) {
+ return cls.invoke(symbol, []).reflectee;
+ }
+ }
+}
+
+main() {
+ LibraryMirror libmain = currentMirrorSystem().findLibrary(#main);
+ LibraryMirror libother = currentMirrorSystem().findLibrary(#other);
+ Expect.equals(1, getPrivateGlobalFieldValue(libmain));
+ Expect.equals(3, getPrivateGlobalFieldValue(libother));
+ Expect.equals(9, getPrivateGlobalMethodValue(libmain));
+ Expect.equals(11, getPrivateGlobalMethodValue(libother));
+
+ var c1 = reflect(new C1());
+ var c2 = reflect(new C2());
+ Expect.equals(0, getPrivateFieldValue(c1));
+ Expect.equals(1, getPrivateFieldValue(c2));
+ Expect.equals(2, getPrivateMethodValue(c1));
+ Expect.equals(3, getPrivateMethodValue(c2));
+}

Powered by Google App Engine
This is Rietveld 408576698