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 // Regression test: this used to crash the VM. | |
8 | |
9 library test.find_in_context_fake_function; | |
10 | |
11 import "dart:mirrors"; | |
12 import "package:expect/expect.dart"; | |
13 | |
14 var topLevelField = 1; | |
15 get topLevelGetter => 2; | |
16 topLevelFunction() => 3; | |
17 | |
18 class FakeFunction1 { | |
19 var field = 4; | |
20 get getter => 5; | |
21 method() => 6; | |
22 static var staticField = 7; | |
23 static get staticGetter => 8; | |
24 staticFunction() => 9; | |
25 call(x) { | |
26 var local = x * 2; | |
27 return local; | |
28 } | |
29 } | |
30 | |
31 class FakeFunction2 implements Function { | |
32 var field = 10; | |
33 get getter => 11; | |
34 method() => 12; | |
35 static var staticField = 13; | |
36 static get staticGetter => 14; | |
37 staticFunction() => 15; | |
38 noSuchMethod(msg) { | |
39 var local = msg.positionalArguments; | |
40 if (msg.memberName != #call) return super.noSuchMethod(msg); | |
41 return local.join('+'); | |
42 } | |
43 } | |
44 | |
45 doFindInContext(cm, name, value) { | |
46 Expect.equals(value, | |
47 cm.findInContext(name).reflectee); | |
48 } | |
49 dontFindInContext(cm, name) { | |
50 Expect.isNull(cm.findInContext(name)); | |
51 } | |
52 | |
53 main() { | |
54 ClosureMirror cm = reflect(new FakeFunction1()); | |
55 dontFindInContext(cm, #local); | |
56 dontFindInContext(cm, const Symbol('this')); | |
57 dontFindInContext(cm, #field); | |
58 dontFindInContext(cm, #getter); | |
59 dontFindInContext(cm, #method); | |
60 dontFindInContext(cm, #staticField); | |
61 dontFindInContext(cm, #staticGetter); | |
62 dontFindInContext(cm, #staticFunction); | |
63 dontFindInContext(cm, #topLevelField); | |
64 dontFindInContext(cm, #topLevelGetter); | |
65 dontFindInContext(cm, #topLevelFunction); | |
66 | |
67 cm = reflect(new FakeFunction2()); | |
68 dontFindInContext(cm, #local); | |
69 dontFindInContext(cm, const Symbol('this')); | |
70 dontFindInContext(cm, #field); | |
71 dontFindInContext(cm, #getter); | |
72 dontFindInContext(cm, #method); | |
73 dontFindInContext(cm, #staticField); | |
74 dontFindInContext(cm, #staticGetter); | |
75 dontFindInContext(cm, #staticFunction); | |
76 dontFindInContext(cm, #topLevelField); | |
77 dontFindInContext(cm, #topLevelGetter); | |
78 dontFindInContext(cm, #topLevelFunction); | |
79 } | |
OLD | NEW |