Chromium Code Reviews| 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 import "dart:mirrors"; | |
| 6 | |
| 7 import "package:expect/expect.dart"; | |
| 8 | |
| 9 class WannabeFunction { | |
| 10 int call(int a, int b) => a + b; | |
| 11 method(); | |
| 12 } | |
| 13 | |
| 14 main() { | |
| 15 Expect.isTrue(new WannabeFunction() is Function); | |
| 16 | |
| 17 ClosureMirror cm = reflect(new WannabeFunction()); | |
| 18 Expect.equals(7, cm.invoke(const Symbol("call"), [3,4]).reflectee); | |
| 19 Expect.throws(() => cm.invoke(const Symbol("call"), [3]), | |
| 20 (e) => e is NoSuchMethodError, | |
| 21 "Wrong arity"); | |
| 22 Expect.equals(7, cm.apply([3,4]).reflectee); | |
| 23 Expect.throws(() => cm.apply([3]), | |
| 24 (e) => e is NoSuchMethodError, | |
| 25 "Wrong arity"); | |
| 26 | |
| 27 MethodMirror mm = cm.function; | |
| 28 Expect.equals(const Symbol("call"), mm.simpleName); | |
| 29 Expect.equals(reflectClass(WannabeFunction), | |
| 30 mm.owner); | |
| 31 // TODO(11944): isOperator not yet implemented. | |
| 32 // Expect.isTrue(mm.isOperator); | |
|
ahe
2013/08/06 20:32:46
I don't think call is an operator (it's just a ver
rmacnak
2013/08/06 20:38:02
Ah, it used to be one last summer :)
| |
| 33 // Operators are considered regular methods. | |
| 34 Expect.isTrue(mm.isRegularMethod); | |
| 35 | |
| 36 FunctionTypeMirror ftm = cm.type; | |
| 37 Expect.equals(reflectClass(WannabeFunction), ftm); | |
| 38 Expect.equals(const Symbol("WannabeFunction"), ftm.simpleName); | |
| 39 Expect.equals(mm, ftm.callMethod); | |
| 40 Expect.equals(const Symbol("int"), ftm.returnType.simpleName); | |
| 41 Expect.equals(const Symbol("int"), ftm.parameters[0].type.simpleName); | |
| 42 Expect.equals(const Symbol("int"), ftm.parameters[1].type.simpleName); | |
| 43 Expect.setEquals([const Symbol("call"), const Symbol("method")], | |
| 44 ftm.members.keys); | |
| 45 } | |
| OLD | NEW |