| OLD | NEW |
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 // Test that native methods with unnamed optional arguments are called with the | 5 // Test that native methods with unnamed optional arguments are called with the |
| 6 // number of arguments in the call site AND the call site is inlined. | 6 // number of arguments in the call site AND the call site is inlined. |
| 7 | 7 |
| 8 import "package:expect/expect.dart"; | 8 import "package:expect/expect.dart"; |
| 9 import 'dart:_js_helper' show Native, NoInline; | 9 import 'dart:_js_helper' show Native, NoInline; |
| 10 | 10 |
| 11 typedef int Int2Int(int x); | 11 typedef int Int2Int(int x); |
| 12 | 12 |
| 13 @Native("A") | 13 @Native("A") |
| 14 class A { | 14 class A { |
| 15 int foo([x, y, z]) native; | 15 int foo([x, y, z]) native ; |
| 16 | 16 |
| 17 // Calls can be inlined provided they don't pass an argument. | 17 // Calls can be inlined provided they don't pass an argument. |
| 18 int callFun([Int2Int fn]) native; | 18 int callFun([Int2Int fn]) native ; |
| 19 } | 19 } |
| 20 | 20 |
| 21 class B { | 21 class B { |
| 22 static var g; | 22 static var g; |
| 23 @NoInline() | 23 @NoInline() |
| 24 method1(a) { | 24 method1(a) { |
| 25 g = '(Method1Tag)'; // Tag to identify compiled JavaScript method. | 25 g = '(Method1Tag)'; // Tag to identify compiled JavaScript method. |
| 26 A x = makeA(); | 26 A x = makeA(); |
| 27 // Call sites that are searched for in compiled JavaScript. | 27 // Call sites that are searched for in compiled JavaScript. |
| 28 x.foo(); | 28 x.foo(); |
| 29 x.foo(1); | 29 x.foo(1); |
| 30 x.foo(2, 10); | 30 x.foo(2, 10); |
| 31 return x.foo(3, 10, 30); | 31 return x.foo(3, 10, 30); |
| 32 } | 32 } |
| 33 |
| 33 @NoInline() | 34 @NoInline() |
| 34 method2() { | 35 method2() { |
| 35 g = '(Method2Tag)'; | 36 g = '(Method2Tag)'; |
| 36 A x = makeA(); | 37 A x = makeA(); |
| 37 var r1 = x.callFun(); // Can be inlined. | 38 var r1 = x.callFun(); // Can be inlined. |
| 38 var r2 = x.callFun(); | 39 var r2 = x.callFun(); |
| 39 return r1 + r2; | 40 return r1 + r2; |
| 40 } | 41 } |
| 42 |
| 41 @NoInline() | 43 @NoInline() |
| 42 method3() { | 44 method3() { |
| 43 g = '(Method3Tag)'; | 45 g = '(Method3Tag)'; |
| 44 A x = makeA(); | 46 A x = makeA(); |
| 45 var r1 = x.callFun((x) => x * 2); // Can't be inlined due to conversion. | 47 var r1 = x.callFun((x) => x * 2); // Can't be inlined due to conversion. |
| 46 var r2 = x.callFun((x) => x * 0); | 48 var r2 = x.callFun((x) => x * 0); |
| 47 return r1 + r2; | 49 return r1 + r2; |
| 48 } | 50 } |
| 49 } | 51 } |
| 50 | 52 |
| 51 A makeA() native; | 53 A makeA() native ; |
| 52 | 54 |
| 53 String findMethodTextContaining(instance, string) native; | 55 String findMethodTextContaining(instance, string) native ; |
| 54 | 56 |
| 55 void setup() native r""" | 57 void setup() native r""" |
| 56 function A() {} | 58 function A() {} |
| 57 A.prototype.foo = function () { return arguments.length; }; | 59 A.prototype.foo = function () { return arguments.length; }; |
| 58 A.prototype.callFun = function (fn) { return fn ? fn(123) : 1; }; | 60 A.prototype.callFun = function (fn) { return fn ? fn(123) : 1; }; |
| 59 | 61 |
| 60 makeA = function(){return new A;}; | 62 makeA = function(){return new A;}; |
| 61 | 63 |
| 62 findMethodTextContaining = function (instance, string) { | 64 findMethodTextContaining = function (instance, string) { |
| 63 var proto = Object.getPrototypeOf(instance); | 65 var proto = Object.getPrototypeOf(instance); |
| 64 var keys = Object.keys(proto); | 66 var keys = Object.keys(proto); |
| 65 for (var i = 0; i < keys.length; i++) { | 67 for (var i = 0; i < keys.length; i++) { |
| 66 var name = keys[i]; | 68 var name = keys[i]; |
| 67 var member = proto[name]; | 69 var member = proto[name]; |
| 68 var s = String(member); | 70 var s = String(member); |
| 69 if (s.indexOf(string)>0) return s; | 71 if (s.indexOf(string)>0) return s; |
| 70 } | 72 } |
| 71 }; | 73 }; |
| 72 """; | 74 """; |
| 73 | 75 |
| 74 | |
| 75 bool get isCheckedMode { | 76 bool get isCheckedMode { |
| 76 int i = 0; | 77 int i = 0; |
| 77 try { | 78 try { |
| 78 i = 'a'; | 79 i = 'a'; |
| 79 } catch (e) { | 80 } catch (e) { |
| 80 return true; | 81 return true; |
| 81 } | 82 } |
| 82 return false; | 83 return false; |
| 83 } | 84 } |
| 84 | 85 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 var b = new B(); | 145 var b = new B(); |
| 145 Expect.equals(2, b.method2()); | 146 Expect.equals(2, b.method2()); |
| 146 Expect.equals(246, b.method3()); | 147 Expect.equals(246, b.method3()); |
| 147 } | 148 } |
| 148 | 149 |
| 149 main() { | 150 main() { |
| 150 setup(); | 151 setup(); |
| 151 test1(); | 152 test1(); |
| 152 test2(); | 153 test2(); |
| 153 } | 154 } |
| OLD | NEW |