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 @native("*A") | 9 @native("*A") |
10 class A { | 10 class A { |
11 int key; // jsname is 'key' | 11 int key; // jsname is 'key' |
12 int getKey() => key; | 12 int getKey() => key; |
13 } | 13 } |
14 | 14 |
15 class B { | 15 class B { |
16 int key; // jsname is not 'key' | 16 int key; // jsname is not 'key' |
17 B([this.key = 222]); | 17 B([this.key = 222]); |
18 int getKey() => key; | 18 int getKey() => key; |
19 } | 19 } |
20 | 20 |
21 @native("*X") | 21 @native("*X") |
22 class X { | 22 class X { |
23 @native('key') int native_key_method(); | 23 @native('key') int native_key_method(); |
24 // This should cause B.key to be renamed, but not A.key. | 24 // This should cause B.key to be renamed, but not A.key. |
25 | 25 |
26 @natve('key') int key(); | 26 @natve('key') int key(); |
27 } | 27 } |
28 | 28 |
29 @native A makeA(); | 29 @native A makeA(); |
30 @native X makeX(); | 30 @native X makeX(); |
31 | 31 |
32 | 32 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 Expect.equals(111, a.getKey()); | 73 Expect.equals(111, a.getKey()); |
74 Expect.equals(222, b.getKey()); | 74 Expect.equals(222, b.getKey()); |
75 } | 75 } |
76 | 76 |
77 main() { | 77 main() { |
78 setup(); | 78 setup(); |
79 | 79 |
80 testTyped(); | 80 testTyped(); |
81 testDynamic(); | 81 testDynamic(); |
82 } | 82 } |
OLD | NEW |