| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011, 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 import "package:expect/expect.dart"; | |
| 6 | |
| 7 // Tests that we can call functions through getters which return null. | |
| 8 | |
| 9 const TOP_LEVEL_NULL = null; | |
| 10 | |
| 11 var topLevel; | |
| 12 | |
| 13 class CallThroughNullGetterTest { | |
| 14 static void testMain() { | |
| 15 testTopLevel(); | |
| 16 testField(); | |
| 17 testGetter(); | |
| 18 testMethod(); | |
| 19 } | |
| 20 | |
| 21 static void testTopLevel() { | |
| 22 topLevel = null; | |
| 23 expectThrowsNoSuchMethodError(() { | |
| 24 topLevel(); | |
| 25 }); | |
| 26 expectThrowsNoSuchMethodError(() { | |
| 27 (topLevel)(); | |
| 28 }); | |
| 29 expectThrowsNoSuchMethodError(() { | |
| 30 TOP_LEVEL_NULL(); | |
| 31 }); | |
| 32 expectThrowsNoSuchMethodError(() { | |
| 33 (TOP_LEVEL_NULL)(); | |
| 34 }); | |
| 35 } | |
| 36 | |
| 37 static void testField() { | |
| 38 A a = new A(); | |
| 39 | |
| 40 a.field = null; | |
| 41 expectThrowsNoSuchMethodError(() { | |
| 42 a.field(); | |
| 43 }); | |
| 44 expectThrowsNoSuchMethodError(() { | |
| 45 (a.field)(); | |
| 46 }); | |
| 47 } | |
| 48 | |
| 49 static void testGetter() { | |
| 50 A a = new A(); | |
| 51 | |
| 52 a.field = null; | |
| 53 expectThrowsNoSuchMethodError(() { | |
| 54 a.getter(); | |
| 55 }); | |
| 56 expectThrowsNoSuchMethodError(() { | |
| 57 (a.getter)(); | |
| 58 }); | |
| 59 } | |
| 60 | |
| 61 static void testMethod() { | |
| 62 A a = new A(); | |
| 63 | |
| 64 a.field = null; | |
| 65 expectThrowsNoSuchMethodError(() { | |
| 66 a.method()(); | |
| 67 }); | |
| 68 } | |
| 69 | |
| 70 static void expectThrowsNoSuchMethodError(fn) { | |
| 71 Expect.throws( | |
| 72 fn, (e) => e is NoSuchMethodError, "Should throw NoSuchMethodError"); | |
| 73 } | |
| 74 } | |
| 75 | |
| 76 class A { | |
| 77 A() {} | |
| 78 var field; | |
| 79 get getter { | |
| 80 return field; | |
| 81 } | |
| 82 | |
| 83 method() { | |
| 84 return field; | |
| 85 } | |
| 86 } | |
| 87 | |
| 88 main() { | |
| 89 CallThroughNullGetterTest.testMain(); | |
| 90 } | |
| OLD | NEW |