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