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

Side by Side Diff: tests/lib/mirrors/private_symbol_mangling_test.dart

Issue 429083004: Make private symbol mangling test work on the VM, as well. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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 library main; 5 library main;
6 6
7 //@MirrorsUsed(targets: const ['C1', 'C2', '_privateGlobalField', '_privateGloba lMethod']) 7 //@MirrorsUsed(targets: const ['C1', 'C2', '_privateGlobalField', '_privateGloba lMethod'])
8 import 'dart:mirrors'; 8 import 'dart:mirrors';
9 import 'package:expect/expect.dart'; 9 import 'package:expect/expect.dart';
10 import 'private_symbol_mangling_lib.dart'; 10 import 'private_symbol_mangling_lib.dart';
11 11
12 var _privateGlobalField = 1; 12 var _privateGlobalField = 1;
13 13
14 _privateGlobalMethod() => 9; 14 _privateGlobalMethod() => 9;
15 15
16 class C1 { 16 class C1 {
17 var _privateField = 0; 17 var _privateField = 0;
18 _privateMethod() => 2; 18 _privateMethod() => 2;
19 } 19 }
20 20
21 getPrivateGlobalFieldValue(LibraryMirror lib) { 21 getPrivateGlobalFieldValue(LibraryMirror lib) {
22 for (Symbol symbol in lib.declarations.keys) { 22 for (Symbol symbol in lib.declarations.keys) {
23 DeclarationMirror decl = lib.declarations[symbol]; 23 DeclarationMirror decl = lib.declarations[symbol];
24 if (decl is VariableMirror) { 24 if (decl is VariableMirror && decl.isPrivate) {
25 return lib.getField(symbol).reflectee; 25 return lib.getField(symbol).reflectee;
26 } 26 }
27 } 27 }
28 } 28 }
29 29
30 getPrivateFieldValue(InstanceMirror cls) { 30 getPrivateFieldValue(InstanceMirror cls) {
31 for (Symbol symbol in cls.type.declarations.keys) { 31 for (Symbol symbol in cls.type.declarations.keys) {
32 DeclarationMirror decl = cls.type.declarations[symbol]; 32 DeclarationMirror decl = cls.type.declarations[symbol];
33 if (decl is VariableMirror) { 33 if (decl is VariableMirror && decl.isPrivate) {
34 return cls.getField(symbol).reflectee; 34 return cls.getField(symbol).reflectee;
35 } 35 }
36 } 36 }
37 } 37 }
38 38
39 getPrivateGlobalMethodValue(LibraryMirror lib) { 39 getPrivateGlobalMethodValue(LibraryMirror lib) {
40 for (Symbol symbol in lib.declarations.keys) { 40 for (Symbol symbol in lib.declarations.keys) {
41 DeclarationMirror decl = lib.declarations[symbol]; 41 DeclarationMirror decl = lib.declarations[symbol];
42 if (decl is MethodMirror && decl.isRegularMethod) { 42 if (decl is MethodMirror && decl.isRegularMethod && decl.isPrivate) {
43 return lib.invoke(symbol, []).reflectee; 43 return lib.invoke(symbol, []).reflectee;
44 } 44 }
45 } 45 }
46 } 46 }
47 47
48 getPrivateMethodValue(InstanceMirror cls) { 48 getPrivateMethodValue(InstanceMirror cls) {
49 for (Symbol symbol in cls.type.declarations.keys) { 49 for (Symbol symbol in cls.type.declarations.keys) {
50 DeclarationMirror decl = cls.type.declarations[symbol]; 50 DeclarationMirror decl = cls.type.declarations[symbol];
51 if (decl is MethodMirror && decl.isRegularMethod) { 51 if (decl is MethodMirror && decl.isRegularMethod && decl.isPrivate) {
52 return cls.invoke(symbol, []).reflectee; 52 return cls.invoke(symbol, []).reflectee;
53 } 53 }
54 } 54 }
55 } 55 }
56 56
57 main() { 57 main() {
58 LibraryMirror libmain = currentMirrorSystem().findLibrary(#main); 58 LibraryMirror libmain = currentMirrorSystem().findLibrary(#main);
59 LibraryMirror libother = currentMirrorSystem().findLibrary(#other); 59 LibraryMirror libother = currentMirrorSystem().findLibrary(#other);
60 Expect.equals(1, getPrivateGlobalFieldValue(libmain)); 60 Expect.equals(1, getPrivateGlobalFieldValue(libmain));
61 Expect.equals(3, getPrivateGlobalFieldValue(libother)); 61 Expect.equals(3, getPrivateGlobalFieldValue(libother));
62 Expect.equals(9, getPrivateGlobalMethodValue(libmain)); 62 Expect.equals(9, getPrivateGlobalMethodValue(libmain));
63 Expect.equals(11, getPrivateGlobalMethodValue(libother)); 63 Expect.equals(11, getPrivateGlobalMethodValue(libother));
64 64
65 var c1 = reflect(new C1()); 65 var c1 = reflect(new C1());
66 var c2 = reflect(new C2()); 66 var c2 = reflect(new C2());
67 Expect.equals(0, getPrivateFieldValue(c1)); 67 Expect.equals(0, getPrivateFieldValue(c1));
68 Expect.equals(1, getPrivateFieldValue(c2)); 68 Expect.equals(1, getPrivateFieldValue(c2));
69 Expect.equals(2, getPrivateMethodValue(c1)); 69 Expect.equals(2, getPrivateMethodValue(c1));
70 Expect.equals(3, getPrivateMethodValue(c2)); 70 Expect.equals(3, getPrivateMethodValue(c2));
71 } 71 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698