Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(567)

Unified Diff: tests/language/invocation_mirror_test.dart

Issue 11264005: InvocationMirror implemented in dart2js. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Check JSInvocationMirror.invokeOn instead of InvocationMirror.invokeOn. Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tests/language/invocation_mirror_test.dart
diff --git a/tests/language/invocation_mirror_test.dart b/tests/language/invocation_mirror_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..85b06c3faf3d96d2282731fa281f8cf51bb51fab
--- /dev/null
+++ b/tests/language/invocation_mirror_test.dart
@@ -0,0 +1,45 @@
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Test direct use of InvocationMirror.invokeOn and Function.apply in
+// noSuchMethod.
+
+class PlusMinus {
+ noSuchMethod(InvocationMirror invocation) {
+ if (invocation.memberName == 'mul') return invocation.invokeOn(mulObject);
+ if (invocation.memberName == 'div') return invocation.invokeOn(divObject);
+ return Function.apply(plus,
+ invocation.positionalArguments,
+ invocation.namedArguments);
+ }
+
+ int plus(int a, int b) => a + b;
+
+ Mul get mulObject => new Mul();
+
+ Div get divObject => new Div();
+}
+
+class Mul {
+ int mul(int a, int b, [int c]) {
+ if (?c) {
+ return a * b * c;
+ }
+ return a * b;
+ }
+}
+
+class Div {
+ int div({int num, int denom}) => num/denom;
+}
+
+void main() {
+ var pm = new PlusMinus();
+ Expect.equals(7, pm.plus(2, 5));
+ Expect.equals(5, pm.minus(2, 3)); // Calls plus.
+ Expect.equals(6, pm.mul(2, 3));
+ Expect.equals(24, pm.mul(2, 3, 4));
+ Expect.equals(5, pm.div(num:10, denom:2));
+ Expect.equals(5, pm.div(denom:2, num:10));
+}

Powered by Google App Engine
This is Rietveld 408576698