| 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 the feature where the native string declares the native method's name. | 5 // Test the feature where the native string declares the native method's name. |
| 6 | 6 |
| 7 import "native_testing.dart"; | 7 import "package:expect/expect.dart"; |
| 8 import 'dart:_js_helper' show Native, JSName; |
| 8 | 9 |
| 9 @Native("A") | 10 @Native("A") |
| 10 class A { | 11 class A { |
| 11 @JSName('fooA') | 12 @JSName('fooA') |
| 12 int foo() native ; | 13 int foo() native ; |
| 13 } | 14 } |
| 14 | 15 |
| 15 @Native("B") | 16 @Native("B") |
| 16 class B extends A { | 17 class B extends A { |
| 17 @JSName('fooB') | 18 @JSName('fooB') |
| (...skipping 16 matching lines...) Expand all Loading... |
| 34 } | 35 } |
| 35 } | 36 } |
| 36 function A(){} | 37 function A(){} |
| 37 A.prototype.fooA = function(){return 100;}; | 38 A.prototype.fooA = function(){return 100;}; |
| 38 function B(){} | 39 function B(){} |
| 39 inherits(B, A); | 40 inherits(B, A); |
| 40 B.prototype.fooB = function(){return 200;}; | 41 B.prototype.fooB = function(){return 200;}; |
| 41 | 42 |
| 42 makeA = function(){return new A}; | 43 makeA = function(){return new A}; |
| 43 makeB = function(){return new B}; | 44 makeB = function(){return new B}; |
| 44 | |
| 45 self.nativeConstructor(A); | |
| 46 self.nativeConstructor(B); | |
| 47 """; | 45 """; |
| 48 | 46 |
| 49 testDynamic() { | 47 testDynamic() { |
| 50 var things = [makeA(), makeB()]; | 48 var things = [makeA(), makeB()]; |
| 51 var a = things[0]; | 49 var a = things[0]; |
| 52 var b = things[1]; | 50 var b = things[1]; |
| 53 | 51 |
| 54 Expect.equals(100, a.foo()); | 52 Expect.equals(100, a.foo()); |
| 55 Expect.equals(200, b.foo()); | 53 Expect.equals(200, b.foo()); |
| 56 | 54 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 71 | 69 |
| 72 testTyped() { | 70 testTyped() { |
| 73 A a = makeA(); | 71 A a = makeA(); |
| 74 B b = makeB(); | 72 B b = makeB(); |
| 75 | 73 |
| 76 Expect.equals(100, a.foo()); | 74 Expect.equals(100, a.foo()); |
| 77 Expect.equals(200, b.foo()); | 75 Expect.equals(200, b.foo()); |
| 78 } | 76 } |
| 79 | 77 |
| 80 main() { | 78 main() { |
| 81 nativeTesting(); | |
| 82 setup(); | 79 setup(); |
| 83 | 80 |
| 84 testDynamic(); | 81 testDynamic(); |
| 85 testTyped(); | 82 testTyped(); |
| 86 } | 83 } |
| 87 | 84 |
| 88 expectNoSuchMethod(action, note) { | 85 expectNoSuchMethod(action, note) { |
| 89 bool caught = false; | 86 bool caught = false; |
| 90 try { | 87 try { |
| 91 action(); | 88 action(); |
| 92 } catch (ex) { | 89 } catch (ex) { |
| 93 caught = true; | 90 caught = true; |
| 94 Expect.isTrue(ex is NoSuchMethodError, note); | 91 Expect.isTrue(ex is NoSuchMethodError, note); |
| 95 } | 92 } |
| 96 Expect.isTrue(caught, note); | 93 Expect.isTrue(caught, note); |
| 97 } | 94 } |
| OLD | NEW |