| 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 // A native method prevents other members from having that name, including | 5 // A native method prevents other members from having that name, including |
| 6 // fields. However, native fields keep their name. The implication: a getter | 6 // fields. However, native fields keep their name. The implication: a getter |
| 7 // for the field must be based on the field's name, not the field's jsname. | 7 // for the field must be based on the field's name, not the field's jsname. |
| 8 | 8 |
| 9 interface I { | 9 interface I { |
| 10 int key; | 10 int key; |
| 11 } | 11 } |
| 12 | 12 |
| 13 class A implements I native "*A" { | 13 class A implements I native "*A" { |
| 14 int key; // jsname is 'key' | 14 int key; // jsname is 'key' |
| 15 int getKey() => key; | 15 int getKey() => key; |
| 16 } | 16 } |
| 17 | 17 |
| 18 class B implements I { | 18 class B implements I { |
| 19 int key; // jsname is not 'key' | 19 int key; // jsname is not 'key' |
| 20 B([this.key = 222]); | 20 B([this.key = 222]); |
| 21 int getKey() => key; | 21 int getKey() => key; |
| 22 } | 22 } |
| 23 | 23 |
| 24 class X native "*X" { | 24 class X native "*X" { |
| 25 int native_key_method() native 'key'; | 25 @JSName('key') |
| 26 int native_key_method() native; |
| 26 // This should cause B.key to be renamed, but not A.key. | 27 // This should cause B.key to be renamed, but not A.key. |
| 27 int key() native 'key'; | 28 @JSName('key') |
| 29 int key() native; |
| 28 } | 30 } |
| 29 | 31 |
| 30 A makeA() native; | 32 A makeA() native; |
| 31 X makeX() native; | 33 X makeX() native; |
| 32 | 34 |
| 33 | 35 |
| 34 void setup() native """ | 36 void setup() native """ |
| 35 // This code is all inside 'setup' and so not accesible from the global scope. | 37 // This code is all inside 'setup' and so not accesible from the global scope. |
| 36 function A(){ this.key = 111; } | 38 function A(){ this.key = 111; } |
| 37 A.prototype.getKey = function(){return this.key;}; | 39 A.prototype.getKey = function(){return this.key;}; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 Expect.equals(222, b.getKey()); | 86 Expect.equals(222, b.getKey()); |
| 85 } | 87 } |
| 86 | 88 |
| 87 main() { | 89 main() { |
| 88 setup(); | 90 setup(); |
| 89 | 91 |
| 90 testTyped(); | 92 testTyped(); |
| 91 testPartial(); | 93 testPartial(); |
| 92 testDynamic(); | 94 testDynamic(); |
| 93 } | 95 } |
| OLD | NEW |