OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 // VMOptions=--support_find_in_context=true | |
6 | |
7 library test.find_in_context_private; | |
8 | |
9 import "dart:mirrors"; | |
10 import "package:expect/expect.dart"; | |
11 | |
12 var _globalVariable = "globalVariable"; | |
13 _globalFoo() => 17; | |
14 | |
15 class S { | |
16 static _staticFooInS() => "staticFooInS"; | |
17 static var _staticInS = "staticInS"; | |
18 var _instanceInS = "instanceInS"; | |
19 } | |
20 | |
21 class C extends S { | |
22 static _staticFooInC() => "staticFooInC"; | |
23 static var _staticInC = "staticInC"; | |
24 var _instanceInC = "instanceInC"; | |
25 | |
26 _method() { | |
27 var _local = "local"; | |
28 nested() { | |
29 var _innerLocal = "innerLocal"; | |
30 print(this._instanceInC); | |
31 print(_local); | |
32 print(_innerLocal); | |
33 } | |
34 return nested; | |
35 } | |
36 | |
37 } | |
38 | |
39 doFindInContext(cm, name, value) { | |
40 Expect.equals(value, | |
41 cm.findInContext(name).reflectee); | |
42 } | |
43 dontFindInContext(cm, name) { | |
44 Expect.isNull(cm.findInContext(name)); | |
45 } | |
46 | |
47 main() { | |
48 LibraryMirror wrongLibrary = reflectClass(List).owner; | |
49 p(name) => MirrorSystem.getSymbol(name, wrongLibrary); | |
50 | |
51 C c = new C(); | |
52 | |
53 // In the context of C._method.nested. | |
54 ClosureMirror cm = reflect(c._method()); | |
55 | |
56 // N.B.: innerLocal is only defined with respective to an activation of the | |
57 // closure 'nested', not the closure itself. | |
58 dontFindInContext(cm, #_innerLocal); | |
59 | |
60 doFindInContext(cm, #_local, "local"); | |
61 doFindInContext(cm, #_method, c._method); | |
62 doFindInContext(cm, #_instanceInC, "instanceInC"); | |
63 doFindInContext(cm, #_staticInC, "staticInC"); | |
64 doFindInContext(cm, #_staticFooInC, C._staticFooInC); | |
65 dontFindInContext(cm, #_staticInS); | |
66 dontFindInContext(cm, #_staticFooInS); | |
67 doFindInContext(cm, #_globalFoo, _globalFoo); | |
68 doFindInContext(cm, #_globalVariable, "globalVariable"); | |
69 | |
70 dontFindInContext(cm, p('_local')); | |
71 dontFindInContext(cm, p('_innerLocal')); | |
72 dontFindInContext(cm, p('_method')); | |
73 dontFindInContext(cm, p('_instanceInC')); | |
74 dontFindInContext(cm, p('_staticInC')); | |
75 dontFindInContext(cm, p('_staticFooInC')); | |
76 dontFindInContext(cm, p('_staticInS')); | |
77 dontFindInContext(cm, p('_staticFooInS')); | |
78 dontFindInContext(cm, p('_globalFoo')); | |
79 dontFindInContext(cm, p('_globalVariable')); | |
80 | |
81 // In the context of C._method. | |
82 cm = reflect(c._method); | |
83 dontFindInContext(cm, #_innerLocal); | |
84 dontFindInContext(cm, #_local); // N.B.: See above. | |
85 doFindInContext(cm, #_method, c._method); | |
86 doFindInContext(cm, #_instanceInC, "instanceInC"); | |
87 doFindInContext(cm, #_staticInC, "staticInC"); | |
88 doFindInContext(cm, #_staticFooInC, C._staticFooInC); | |
89 dontFindInContext(cm, #_staticInS); | |
90 dontFindInContext(cm, #_staticFooInS); | |
91 doFindInContext(cm, #_globalFoo, _globalFoo); | |
92 doFindInContext(cm, #_globalVariable, "globalVariable"); | |
93 | |
94 dontFindInContext(cm, p('_local')); | |
95 dontFindInContext(cm, p('_innerLocal')); | |
96 dontFindInContext(cm, p('_method')); | |
97 dontFindInContext(cm, p('_instanceInC')); | |
98 dontFindInContext(cm, p('_staticInC')); | |
99 dontFindInContext(cm, p('_staticFooInC')); | |
100 dontFindInContext(cm, p('_staticInS')); | |
101 dontFindInContext(cm, p('_staticFooInS')); | |
102 dontFindInContext(cm, p('_globalFoo')); | |
103 dontFindInContext(cm, p('_globalVariable')); | |
104 } | |
OLD | NEW |