| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2014, 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 library test.delegate_function_invocation; | |
| 6 | |
| 7 @MirrorsUsed(targets: "test.delegate_function_invocation") | |
| 8 import 'dart:mirrors'; | |
| 9 | |
| 10 import 'package:expect/expect.dart'; | |
| 11 | |
| 12 class Proxy { | |
| 13 var targetMirror; | |
| 14 Proxy(target) : this.targetMirror = reflect(target); | |
| 15 noSuchMethod(invocation) => targetMirror.delegate(invocation); | |
| 16 } | |
| 17 | |
| 18 testClosure() { | |
| 19 var proxy = new Proxy(() => 42); | |
| 20 Expect.equals(42, proxy()); | |
| 21 Expect.equals(42, proxy.call()); | |
| 22 } | |
| 23 | |
| 24 class FakeFunction { | |
| 25 call() => 43; | |
| 26 } | |
| 27 | |
| 28 testFakeFunction() { | |
| 29 var proxy = new Proxy(new FakeFunction()); | |
| 30 Expect.equals(43, proxy()); | |
| 31 Expect.equals(43, proxy.call()); | |
| 32 } | |
| 33 | |
| 34 topLevelFunction() => 44; | |
| 35 | |
| 36 testTopLevelTearOff() { | |
| 37 var proxy = new Proxy(topLevelFunction); | |
| 38 Expect.equals(44, proxy()); | |
| 39 Expect.equals(44, proxy.call()); | |
| 40 } | |
| 41 | |
| 42 class C { | |
| 43 method() => 45; | |
| 44 } | |
| 45 | |
| 46 testInstanceTearOff() { | |
| 47 var proxy = new Proxy(new C().method); | |
| 48 Expect.equals(45, proxy()); | |
| 49 Expect.equals(45, proxy.call()); | |
| 50 } | |
| 51 | |
| 52 main() { | |
| 53 testClosure(); | |
| 54 testFakeFunction(); | |
| 55 testTopLevelTearOff(); | |
| 56 testInstanceTearOff(); | |
| 57 } | |
| OLD | NEW |