| 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 import "dart:_js_helper"; | 5 import 'native_testing.dart'; |
| 6 import "package:expect/expect.dart"; | |
| 7 | 6 |
| 8 // Test that type checks occur on native methods. | 7 // Test that type checks occur on native methods. |
| 9 | 8 |
| 10 @Native("A") | 9 @Native("A") |
| 11 class A { | 10 class A { |
| 12 int foo(int x) native ; | 11 int foo(int x) native ; |
| 13 int cmp(A other) native ; | 12 int cmp(A other) native ; |
| 14 } | 13 } |
| 15 | 14 |
| 16 @Native("B") | 15 @Native("B") |
| 17 class B { | 16 class B { |
| 18 String foo(String x) native ; | 17 String foo(String x) native ; |
| 19 int cmp(B other) native ; | 18 int cmp(B other) native ; |
| 20 } | 19 } |
| 21 | 20 |
| 22 A makeA() native ; | 21 A makeA() native ; |
| 23 B makeB() native ; | 22 B makeB() native ; |
| 24 | 23 |
| 25 void setup() native """ | 24 void setup() native """ |
| 26 function A() {} | 25 function A() {} |
| 27 A.prototype.foo = function (x) { return x + 1; }; | 26 A.prototype.foo = function (x) { return x + 1; }; |
| 28 A.prototype.cmp = function (x) { return 0; }; | 27 A.prototype.cmp = function (x) { return 0; }; |
| 29 | 28 |
| 30 function B() {} | 29 function B() {} |
| 31 B.prototype.foo = function (x) { return x + 'ha!'; }; | 30 B.prototype.foo = function (x) { return x + 'ha!'; }; |
| 32 B.prototype.cmp = function (x) { return 1; }; | 31 B.prototype.cmp = function (x) { return 1; }; |
| 33 | 32 |
| 34 makeA = function(){return new A;}; | 33 makeA = function(){return new A;}; |
| 35 makeB = function(){return new B;}; | 34 makeB = function(){return new B;}; |
| 35 |
| 36 self.nativeConstructor(A); |
| 37 self.nativeConstructor(B); |
| 36 """; | 38 """; |
| 37 | 39 |
| 38 expectThrows(action()) { | 40 expectThrows(action()) { |
| 39 bool threw = false; | 41 bool threw = false; |
| 40 try { | 42 try { |
| 41 action(); | 43 action(); |
| 42 } catch (e) { | 44 } catch (e) { |
| 43 threw = true; | 45 threw = true; |
| 44 } | 46 } |
| 45 Expect.isTrue(threw); | 47 Expect.isTrue(threw); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 try { | 130 try { |
| 129 String s = a; | 131 String s = a; |
| 130 return false; | 132 return false; |
| 131 } catch (e) { | 133 } catch (e) { |
| 132 // Ignore. | 134 // Ignore. |
| 133 } | 135 } |
| 134 return true; | 136 return true; |
| 135 } | 137 } |
| 136 | 138 |
| 137 main() { | 139 main() { |
| 140 nativeTesting(); |
| 138 setup(); | 141 setup(); |
| 139 | 142 |
| 140 if (isCheckedMode()) { | 143 if (isCheckedMode()) { |
| 141 checkedModeTest(); | 144 checkedModeTest(); |
| 142 } else { | 145 } else { |
| 143 uncheckedModeTest(); | 146 uncheckedModeTest(); |
| 144 } | 147 } |
| 145 } | 148 } |
| OLD | NEW |