OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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 | 4 |
5 // Tests of interceptors. | 5 // Tests of interceptors. |
6 | 6 |
7 library supercall_test; | 7 library supercall_test; |
8 | 8 |
9 import 'js_backend_cps_ir.dart'; | 9 import 'js_backend_cps_ir.dart'; |
10 | 10 |
11 const List<TestEntry> tests = const [ | 11 const List<TestEntry> tests = const [ |
12 const TestEntry.forMethod('function(Sub#m)', """ | 12 const TestEntry(""" |
13 class Base { | 13 class Base { |
14 m(x) { | 14 m(x) { |
15 print(x+1); | 15 print(x+1); |
16 } | 16 } |
17 } | 17 } |
18 class Sub extends Base { | 18 class Sub extends Base { |
19 m(x) => super.m(x+10); | 19 m(x) => super.m(x+10); |
20 } | 20 } |
21 main() { | 21 main() { |
22 new Sub().m(100); | 22 new Sub().m(100); |
23 }""", | 23 }""", |
24 r""" | 24 r""" |
25 function(x) { | 25 function() { |
26 return V.Base.prototype.m$1.call(this, x + 10); | 26 var v0; |
| 27 V.Sub$(); |
| 28 v0 = H.S(100 + 10 + 1); |
| 29 if (typeof dartPrint == "function") |
| 30 dartPrint(v0); |
| 31 else if (typeof console == "object" && typeof console.log != "undefined") |
| 32 console.log(v0); |
| 33 else if (!(typeof window == "object")) { |
| 34 if (!(typeof print == "function")) |
| 35 throw "Unable to print message: " + String(v0); |
| 36 print(v0); |
| 37 } |
27 }"""), | 38 }"""), |
28 | 39 |
29 // Reenable when we support compiling functions that | 40 // Reenable when we support compiling functions that |
30 // need interceptor calling convention. | 41 // need interceptor calling convention. |
31 // const TestEntry.forMethod('function(Sub#+)', """ | 42 // const TestEntry.forMethod('function(Sub#+)', """ |
32 // class Base { | 43 // class Base { |
33 // m(x) { | 44 // m(x) { |
34 // print(x+1000); | 45 // print(x+1000); |
35 // } | 46 // } |
36 // operator+(x) => m(x+10); | 47 // operator+(x) => m(x+10); |
37 // } | 48 // } |
38 // class Sub extends Base { | 49 // class Sub extends Base { |
39 // m(x) => super.m(x+100); | 50 // m(x) => super.m(x+100); |
40 // operator+(x) => super + (x+1); | 51 // operator+(x) => super + (x+1); |
41 // } | 52 // } |
42 // main() { | 53 // main() { |
43 // new Sub() + 10000; | 54 // new Sub() + 10000; |
44 // }""", | 55 // }""", |
45 // r""" | 56 // r""" |
46 // function(x) { | 57 // function(x) { |
47 // var v0, v1, v2; | 58 // var v0, v1, v2; |
48 // v0 = 1; | 59 // v0 = 1; |
49 // v1 = J.getInterceptor$ns(x).$add(x, v0); | 60 // v1 = J.getInterceptor$ns(x).$add(x, v0); |
50 // v2 = this; | 61 // v2 = this; |
51 // return V.Base.prototype.$add.call(null, v2, v1); | 62 // return V.Base.prototype.$add.call(null, v2, v1); |
52 // }"""), | 63 // }"""), |
53 | 64 |
54 const TestEntry.forMethod('function(Sub#m)', """ | 65 const TestEntry(""" |
55 class Base { | 66 class Base { |
56 var field = 123; | 67 var field = 123; |
57 } | 68 } |
58 class Sub extends Base { | 69 class Sub extends Base { |
59 m(x) => x + super.field; | 70 m(x) => x + super.field; |
60 } | 71 } |
61 main() { | 72 main() { |
62 print(new Sub().m(10)); | 73 print(new Sub().m(10)); |
63 }""", | 74 }""", |
64 r""" | 75 r""" |
65 function(x) { | 76 function() { |
66 return x + this.field; | 77 var v0 = H.S(10 + V.Sub$().field); |
| 78 if (typeof dartPrint == "function") |
| 79 dartPrint(v0); |
| 80 else if (typeof console == "object" && typeof console.log != "undefined") |
| 81 console.log(v0); |
| 82 else if (!(typeof window == "object")) { |
| 83 if (!(typeof print == "function")) |
| 84 throw "Unable to print message: " + String(v0); |
| 85 print(v0); |
| 86 } |
67 }"""), | 87 }"""), |
68 | 88 |
69 | 89 |
70 ]; | 90 ]; |
71 | 91 |
72 void main() { | 92 void main() { |
73 runTests(tests); | 93 runTests(tests); |
74 } | 94 } |
OLD | NEW |