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

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

Issue 16757007: Changes to mirrors in support of metadata access at runtime. Assumes VM changes in flight.… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 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
« runtime/lib/mirrors_impl.dart ('K') | « sdk/lib/mirrors/mirrors.dart ('k') | 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) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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 @string @symbol 5 @string @symbol
6 library test.metadata_test; 6 library test.metadata_test;
7 7
8 import 'dart:mirrors'; 8 import 'dart:mirrors';
9 9
10 const string = 'a metadata string'; 10 const string = 'a metadata string';
(...skipping 21 matching lines...) Expand all
32 int actualLength = metadata.length; 32 int actualLength = metadata.length;
33 if (expectedLength != actualLength) { 33 if (expectedLength != actualLength) {
34 throw 'Expected length = $expectedLength, but got length = $actualLength.'; 34 throw 'Expected length = $expectedLength, but got length = $actualLength.';
35 } 35 }
36 for (int i = 0; i < expectedLength; i++) { 36 for (int i = 0; i < expectedLength; i++) {
37 if (metadata[i] != expectedMetadata[i]) { 37 if (metadata[i] != expectedMetadata[i]) {
38 throw '${metadata[i]} is not "${expectedMetadata[i]}"' 38 throw '${metadata[i]} is not "${expectedMetadata[i]}"'
39 ' in $mirror at index $i'; 39 ' in $mirror at index $i';
40 } 40 }
41 } 41 }
42 print(metadata);
Ivan Posva 2013/06/14 15:16:48 Please leave the print in.
gbracha 2013/06/14 20:42:46 Done.
43 } 42 }
44 43
45 @symbol @string @symbol 44 @symbol @string @symbol
46 main() { 45 main() {
47 if (MirrorSystem.getName(symbol) != 'symbol') { 46 if (MirrorSystem.getName(symbol) != 'symbol') {
48 // This happened in dart2js due to how early library metadata is 47 // This happened in dart2js due to how early library metadata is
49 // computed. 48 // computed.
50 throw 'Bad constant: $symbol'; 49 throw 'Bad constant: $symbol';
51 } 50 }
52 51
53 MirrorSystem mirrors = currentMirrorSystem(); 52 MirrorSystem mirrors = currentMirrorSystem();
54 checkMetadata(mirrors.findLibrary(const Symbol('test.metadata_test')).first, 53 LibraryMirror lib = mirrors.findLibrary(const Symbol('test.metadata_test')).fi rst;
55 [string, symbol]); 54 /* checkMetadata(mirrors.findLibrary(const Symbol('test.metadata_test')).first,
Ivan Posva 2013/06/14 15:16:48 I think the easiest way is to split this into sepa
gbracha 2013/06/14 20:42:46 Done.
55 [string, symbol]); */
56 ClassMirror myClassMirror = reflectClass(MyClass); 56 ClassMirror myClassMirror = reflectClass(MyClass);
57 checkMetadata(myClassMirror, [symbol, string]); 57 checkMetadata(myClassMirror, [symbol, string]);
58 ClosureMirror closure = reflect(main); 58 MethodMirror function = lib.functions[const Symbol('main')];
59 checkMetadata(closure.function, [symbol, string, symbol]); 59 checkMetadata(function, [symbol, string, symbol]);
60 closure = reflect(new MyClass().myMethod); 60 MethodMirror method = myClassMirror.methods[const Symbol('myMethod')];
61 checkMetadata(closure.function, [string, symbol, string]); 61 checkMetadata(method, [string, symbol, string]);
62 62
63 VariableMirror xMirror = myClassMirror.variables[const Symbol('x')]; 63 VariableMirror xMirror = myClassMirror.variables[const Symbol('x')];
64 checkMetadata(xMirror, [hest, hest, symbol]); 64 checkMetadata(xMirror, [hest, hest, symbol]);
65 65
66 VariableMirror yMirror = myClassMirror.variables[const Symbol('y')]; 66 VariableMirror yMirror = myClassMirror.variables[const Symbol('y')];
67 checkMetadata(yMirror, []); 67 checkMetadata(yMirror, []);
68 68
69 // TODO(ahe): Test local functions. 69 // TODO(ahe): Test local functions.
70 } 70 }
OLDNEW
« runtime/lib/mirrors_impl.dart ('K') | « sdk/lib/mirrors/mirrors.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698