Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 // VMOptions=--optimization-counter-threshold=100 | 4 // VMOptions=--optimization-counter-threshold=100 |
| 5 | 5 |
| 6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
| 7 | 7 |
| 8 // Test that noSuchMethod dispatching and auto-closurization work correctly. | 8 // Test that noSuchMethod dispatching and auto-closurization work correctly. |
| 9 | 9 |
| 10 class A { | 10 class A { |
| 11 noSuchMethod(m) { | 11 noSuchMethod(m) { |
| 12 return 123; | 12 return 123; |
| 13 } | 13 } |
| 14 bar(x) => x + 1; | 14 bar(x) => x + 1; |
| 15 } | 15 } |
| 16 | 16 |
| 17 class B extends A { } | 17 class B extends A { } |
| 18 | 18 |
| 19 | |
| 20 call_bar(x) => x.bar(); | |
| 21 | |
| 22 testMessage() { | |
| 23 try { | |
| 24 call_bar(5); | |
| 25 } catch (e) { | |
| 26 Expect.isTrue(e.toString().indexOf("method not found") != -1); | |
|
ahe
2013/07/20 17:24:27
I'm working on improving dart2js' handling of NoSu
| |
| 27 } | |
| 28 } | |
| 29 | |
| 30 class C { | |
| 31 C(this.pos, this.named, this.posArgs, this.namedArgs); | |
| 32 var pos, named; | |
| 33 noSuchMethod(m) { | |
| 34 Expect.equals(pos, m.positionalArguments.length); | |
| 35 Expect.equals(named, m.namedArguments.length); | |
| 36 for (var i = 0; i < posArgs.length; ++i) { | |
| 37 Expect.equals(posArgs[i], m.positionalArguments[i]); | |
| 38 } | |
| 39 for (var k in namedArgs.keys) { | |
| 40 Expect.equals(namedArgs[k], m.namedArguments[new Symbol(k)]); | |
| 41 } | |
| 42 return 123; | |
| 43 } | |
| 44 List posArgs; | |
| 45 Map namedArgs; | |
| 46 } | |
| 47 | |
| 19 main() { | 48 main() { |
| 20 var a = new A(); | 49 var a = new A(); |
| 21 for (var i = 0; i < 100; ++i) Expect.equals(123, a.foo()); | 50 for (var i = 0; i < 100; ++i) Expect.equals(123, a.foo()); |
| 22 Expect.throws(() => (a.foo)()); | 51 Expect.throws(() => (a.foo)()); |
| 23 Expect.equals("123", (a.foo).toString()); | 52 Expect.equals("123", (a.foo).toString()); |
| 24 | 53 |
| 25 var b = new B(); | 54 var b = new B(); |
| 26 for (var i = 0; i < 100; ++i) { | 55 for (var i = 0; i < 100; ++i) { |
| 27 Expect.equals(2, b.bar(1)); | 56 Expect.equals(2, b.bar(1)); |
| 28 Expect.equals(123, b.bar()); | 57 Expect.equals(123, b.bar()); |
| 29 Expect.equals(2, b.bar(1)); | 58 Expect.equals(2, b.bar(1)); |
| 30 } | 59 } |
| 60 | |
| 61 for (var i = 0; i < 100; ++i) { | |
| 62 Expect.equals(123, b.bar(1,2,3)); | |
| 63 Expect.equals(123, b.bar(1,2,foo:3)); | |
| 64 } | |
| 65 | |
| 66 // Test named and positional arguments. | |
| 67 var c = new C(1, 2, [100], {"n1":101, "n2":102}); | |
| 68 for (var i = 0; i < 100; ++i) { | |
| 69 Expect.equals(123, c.bar(100, n1:101, n2:102)); | |
| 70 Expect.equals(123, c.bar(100, n2:102, n1:101)); | |
| 71 } | |
| 72 | |
| 73 // Test NoSuchMethodError message. | |
| 74 for (var i = 0; i < 100; i++) testMessage(); | |
| 75 | |
| 31 } | 76 } |
| 32 | 77 |
| OLD | NEW |