| 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 class A native "*A" { | 7 @native("*A") |
| 8 int foo() native 'fooA'; | 8 class A { |
| 9 int bar() native 'barA'; | 9 @native('fooA') int foo(); |
| 10 int baz() native 'bazA'; | 10 @native('barA') int bar(); |
| 11 @native('bazA') int baz(); |
| 11 } | 12 } |
| 12 | 13 |
| 13 A makeA() native; | 14 @native A makeA(); |
| 14 | 15 |
| 15 class B { | 16 class B { |
| 16 int bar([x]) => 800; | 17 int bar([x]) => 800; |
| 17 int baz() => 900; | 18 int baz() => 900; |
| 18 } | 19 } |
| 19 | 20 |
| 20 void setup() native """ | 21 @native(""" |
| 21 // This code is all inside 'setup' and so not accesible from the global scope. | 22 // This code is all inside 'setup' and so not accesible from the global scope. |
| 22 function A(){} | 23 function A(){} |
| 23 A.prototype.fooA = function(){return 100;}; | 24 A.prototype.fooA = function(){return 100;}; |
| 24 A.prototype.barA = function(){return 200;}; | 25 A.prototype.barA = function(){return 200;}; |
| 25 A.prototype.bazA = function(){return 300;}; | 26 A.prototype.bazA = function(){return 300;}; |
| 26 | 27 |
| 27 makeA = function(){return new A}; | 28 makeA = function(){return new A}; |
| 28 """; | 29 """) |
| 30 void setup(); |
| 29 | 31 |
| 30 | 32 |
| 31 testDynamic() { | 33 testDynamic() { |
| 32 setup(); | 34 setup(); |
| 33 | 35 |
| 34 var things = [makeA(), new B()]; | 36 var things = [makeA(), new B()]; |
| 35 var a = things[0]; | 37 var a = things[0]; |
| 36 var b = things[1]; | 38 var b = things[1]; |
| 37 | 39 |
| 38 Expect.equals(100, a.foo()); | 40 Expect.equals(100, a.foo()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 62 expectNoSuchMethod(action, note) { | 64 expectNoSuchMethod(action, note) { |
| 63 bool caught = false; | 65 bool caught = false; |
| 64 try { | 66 try { |
| 65 action(); | 67 action(); |
| 66 } catch (var ex) { | 68 } catch (var ex) { |
| 67 caught = true; | 69 caught = true; |
| 68 Expect.isTrue(ex is NoSuchMethodException, note); | 70 Expect.isTrue(ex is NoSuchMethodException, note); |
| 69 } | 71 } |
| 70 Expect.isTrue(caught, note); | 72 Expect.isTrue(caught, note); |
| 71 } | 73 } |
| OLD | NEW |