| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 // InvocationMirror and noSuchMethod testing. | 5 // InvocationMirror and noSuchMethod testing. |
| 6 | 6 |
| 7 /** Class with noSuchMethod that returns the mirror */ | 7 /** Class with noSuchMethod that returns the mirror */ |
| 8 class N { | 8 class N { |
| 9 noSuchMethod(InvocationMirror m) => m; | 9 noSuchMethod(InvocationMirror m) => m; |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 /** | 26 /** |
| 27 * Checks the data of an InvocationMirror. | 27 * Checks the data of an InvocationMirror. |
| 28 * | 28 * |
| 29 * Call without optionals for getters, with only positional for setters, | 29 * Call without optionals for getters, with only positional for setters, |
| 30 * and with both optionals for everything else. | 30 * and with both optionals for everything else. |
| 31 */ | 31 */ |
| 32 testInvocationMirror(InvocationMirror im, String name, | 32 testInvocationMirror(InvocationMirror im, String name, |
| 33 [List positional, Map named]) { | 33 [List positional, Map named]) { |
| 34 Expect.isTrue(im is InvocationMirror); | 34 Expect.isTrue(im is InvocationMirror); |
| 35 Expect.equals(name, im.methodName); | 35 Expect.equals(name, im.memberName); |
| 36 if (named == null) { | 36 if (named == null) { |
| 37 Expect.isTrue(im.isAccessor); | 37 Expect.isTrue(im.isAccessor); |
| 38 Expect.isFalse(im.isMethod); | 38 Expect.isFalse(im.isMethod); |
| 39 if (positional == null) { | 39 if (positional == null) { |
| 40 Expect.isTrue(im.isGetter); | 40 Expect.isTrue(im.isGetter); |
| 41 Expect.isFalse(im.isSetter); | 41 Expect.isFalse(im.isSetter); |
| 42 Expect.equals(null, im.positionalArguments); | 42 Expect.equals(null, im.positionalArguments); |
| 43 Expect.equals(null, im.positionalArguments); | 43 Expect.equals(null, im.positionalArguments); |
| 44 return; | 44 return; |
| 45 } | 45 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 testInvocationMirror(n + 4, '+', [4], {}); | 88 testInvocationMirror(n + 4, '+', [4], {}); |
| 89 testInvocationMirror(n - 4, '-', [4], {}); | 89 testInvocationMirror(n - 4, '-', [4], {}); |
| 90 testInvocationMirror(-n, '+', [], {}); | 90 testInvocationMirror(-n, '+', [], {}); |
| 91 testInvocationMirror(n[42], '[]', [42], {}); | 91 testInvocationMirror(n[42], '[]', [42], {}); |
| 92 testInvocationMirror(n[37] = 42, '[]=', [37, 42], {}); | 92 testInvocationMirror(n[37] = 42, '[]=', [37, 42], {}); |
| 93 | 93 |
| 94 // Calling as function when it's not. | 94 // Calling as function when it's not. |
| 95 testInvocationMirror(n(), 'call', [], {}); | 95 testInvocationMirror(n(), 'call', [], {}); |
| 96 testInvocationMirror(n(42), 'call', [42], {}); | 96 testInvocationMirror(n(42), 'call', [42], {}); |
| 97 testInvocationMirror(n(x: 42), 'call', [], {"x": 42}); | 97 testInvocationMirror(n(x: 42), 'call', [], {"x": 42}); |
| 98 testInvocationMirror(n(37, x: 42), 'call', [37], {"x": 42});is | 98 testInvocationMirror(n(37, x: 42), 'call', [37], {"x": 42}); |
| 99 | 99 |
| 100 // Calling with arguments not matching existing call method. | 100 // Calling with arguments not matching existing call method. |
| 101 testInvocationMirror(c(), 'call', [], {}); | 101 testInvocationMirror(c(), 'call', [], {}); |
| 102 testInvocationMirror(c(37, 42), 'call', [37, 42], {}); | 102 testInvocationMirror(c(37, 42), 'call', [37, 42], {}); |
| 103 testInvocationMirror(c(x: 42), 'call', [], {"x": 42}); | 103 testInvocationMirror(c(x: 42), 'call', [], {"x": 42}); |
| 104 testInvocationMirror(c(37, x: 42), 'call', [37], {"x": 42}); | 104 testInvocationMirror(c(37, x: 42), 'call', [37], {"x": 42}); |
| 105 | 105 |
| 106 // Wrong arguments to existing function. | 106 // Wrong arguments to existing function. |
| 107 testInvocationMirror(n.flif(), "flif", [], {}); | 107 testInvocationMirror(n.flif(), "flif", [], {}); |
| 108 testInvocationMirror(n.flif(37, 42), "flif", [37, 42], {}); | 108 testInvocationMirror(n.flif(37, 42), "flif", [37, 42], {}); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 130 testInvocationMirror(n.plif = 42, "plif=", [42]); | 130 testInvocationMirror(n.plif = 42, "plif=", [42]); |
| 131 testInvocationMirror(n.plaf = 42, "plaf=", [42]); | 131 testInvocationMirror(n.plaf = 42, "plaf=", [42]); |
| 132 | 132 |
| 133 // Trick call to n.call - wut is a getter returning n again. | 133 // Trick call to n.call - wut is a getter returning n again. |
| 134 testInvocationMirror(n.wut(42), "call", [42]); | 134 testInvocationMirror(n.wut(42), "call", [42]); |
| 135 | 135 |
| 136 // Closurizing a method means that calling it badly will not hit the | 136 // Closurizing a method means that calling it badly will not hit the |
| 137 // original receivers noSuchMethod, only the one inherited from Object | 137 // original receivers noSuchMethod, only the one inherited from Object |
| 138 // by the closure object. | 138 // by the closure object. |
| 139 Expect.throws(() { var x = n.flif; x(37, 42); }, | 139 Expect.throws(() { var x = n.flif; x(37, 42); }, |
| 140 (e) => e is noSuchMethodError); | 140 (e) => e is NoSuchMethodError); |
| 141 Expect.throws(() { var x = c.call; x(37, 42); }, | 141 Expect.throws(() { var x = c.call; x(37, 42); }, |
| 142 (e) => e is noSuchMethodError); | 142 (e) => e is NoSuchMethodError); |
| 143 } | 143 } |
| 144 | 144 |
| 145 // Test the NoSuchMethodError thrown by different incorrect calls. | 145 // Test the NoSuchMethodError thrown by different incorrect calls. |
| 146 testNoSuchMethodErrors() { | 146 testNoSuchMethodErrors() { |
| 147 test(Function block) { | 147 test(Function block) { |
| 148 Expect.throws(block, (e) => e is noSuchMethodError); | 148 Expect.throws(block, (e) => e is NoSuchMethodError); |
| 149 } | 149 } |
| 150 | 150 |
| 151 var o = new Object(); | 151 var o = new Object(); |
| 152 test(() => o.bar); | 152 test(() => o.bar); |
| 153 test(() => o.bar = 42); | 153 test(() => o.bar = 42); |
| 154 test(() => o.bar()); | 154 test(() => o.bar()); |
| 155 test(() => o.toString = 42); | 155 test(() => o.toString = 42); |
| 156 test(() => o.toString(42)); | 156 test(() => o.toString(42)); |
| 157 test(() => o.toString(x: 37)); | 157 test(() => o.toString(x: 37)); |
| 158 test(() => o.hashCode = 42); | 158 test(() => o.hashCode = 42); |
| 159 test(() => o.hashCode()); // Thrown by int.noSuchMethod. | 159 test(() => o.hashCode()); // Thrown by int.noSuchMethod. |
| 160 test(() => o()); | 160 test(() => o()); |
| 161 } | 161 } |
| 162 | 162 |
| 163 main() { | 163 main() { |
| 164 testInvocationMirrors(); | 164 testInvocationMirrors(); |
| 165 testNoSuchMethodErrors(); | 165 testNoSuchMethodErrors(); |
| 166 } | 166 } |
| OLD | NEW |