| 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=10 --no-use-osr | 4 // VMOptions=--optimization-counter-threshold=10 --no-use-osr |
| 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); | |
| 27 } | |
| 28 } | |
| 29 | |
| 30 class C { | 19 class C { |
| 31 C(this.pos, this.named, this.posArgs, this.namedArgs); | 20 C(this.pos, this.named, this.posArgs, this.namedArgs); |
| 32 var pos, named; | 21 var pos, named; |
| 33 noSuchMethod(m) { | 22 noSuchMethod(m) { |
| 34 Expect.equals(pos, m.positionalArguments.length); | 23 Expect.equals(pos, m.positionalArguments.length); |
| 35 Expect.equals(named, m.namedArguments.length); | 24 Expect.equals(named, m.namedArguments.length); |
| 36 for (var i = 0; i < posArgs.length; ++i) { | 25 for (var i = 0; i < posArgs.length; ++i) { |
| 37 Expect.equals(posArgs[i], m.positionalArguments[i]); | 26 Expect.equals(posArgs[i], m.positionalArguments[i]); |
| 38 } | 27 } |
| 39 for (var k in namedArgs.keys) { | 28 for (var k in namedArgs.keys) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 62 Expect.equals(123, b.bar(1,2,3)); | 51 Expect.equals(123, b.bar(1,2,3)); |
| 63 Expect.equals(123, b.bar(1,2,foo:3)); | 52 Expect.equals(123, b.bar(1,2,foo:3)); |
| 64 } | 53 } |
| 65 | 54 |
| 66 // Test named and positional arguments. | 55 // Test named and positional arguments. |
| 67 var c = new C(1, 2, [100], {"n1":101, "n2":102}); | 56 var c = new C(1, 2, [100], {"n1":101, "n2":102}); |
| 68 for (var i = 0; i < 20; ++i) { | 57 for (var i = 0; i < 20; ++i) { |
| 69 Expect.equals(123, c.bar(100, n1:101, n2:102)); | 58 Expect.equals(123, c.bar(100, n1:101, n2:102)); |
| 70 Expect.equals(123, c.bar(100, n2:102, n1:101)); | 59 Expect.equals(123, c.bar(100, n2:102, n1:101)); |
| 71 } | 60 } |
| 72 | |
| 73 // Test NoSuchMethodError message. | |
| 74 for (var i = 0; i < 20; i++) testMessage(); | |
| 75 | |
| 76 } | 61 } |
| 77 | 62 |
| OLD | NEW |