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