| 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 import 'native_metadata.dart'; |
| 10 |
| 11 @Native("*A") |
| 10 class A { | 12 class A { |
| 11 int key; // jsname is 'key' | 13 int key; // jsname is 'key' |
| 12 int getKey() => key; | 14 int getKey() => key; |
| 13 } | 15 } |
| 14 | 16 |
| 15 class B { | 17 class B { |
| 16 int key; // jsname is not 'key' | 18 int key; // jsname is not 'key' |
| 17 B([this.key = 222]); | 19 B([this.key = 222]); |
| 18 int getKey() => key; | 20 int getKey() => key; |
| 19 } | 21 } |
| 20 | 22 |
| 21 @native("*X") | 23 @Native("*X") |
| 22 class X { | 24 class X { |
| 23 @native('key') int native_key_method(); | 25 @Native('key') int native_key_method(); |
| 24 // This should cause B.key to be renamed, but not A.key. | 26 // This should cause B.key to be renamed, but not A.key. |
| 25 | 27 |
| 26 @natve('key') int key(); | 28 @natve('key') int key(); |
| 27 } | 29 } |
| 28 | 30 |
| 29 @native A makeA(); | 31 @native A makeA(); |
| 30 @native X makeX(); | 32 @native X makeX(); |
| 31 | 33 |
| 32 | 34 |
| 33 @native(""" | 35 @Native(""" |
| 34 // This code is all inside 'setup' and so not accesible from the global scope. | 36 // This code is all inside 'setup' and so not accesible from the global scope. |
| 35 function A(){ this.key = 111; } | 37 function A(){ this.key = 111; } |
| 36 A.prototype.getKey = function(){return this.key;}; | 38 A.prototype.getKey = function(){return this.key;}; |
| 37 | 39 |
| 38 function X(){} | 40 function X(){} |
| 39 X.prototype.key = function(){return 666;}; | 41 X.prototype.key = function(){return 666;}; |
| 40 | 42 |
| 41 makeA = function(){return new A}; | 43 makeA = function(){return new A}; |
| 42 makeX = function(){return new X}; | 44 makeX = function(){return new X}; |
| 43 """) | 45 """) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 73 Expect.equals(111, a.getKey()); | 75 Expect.equals(111, a.getKey()); |
| 74 Expect.equals(222, b.getKey()); | 76 Expect.equals(222, b.getKey()); |
| 75 } | 77 } |
| 76 | 78 |
| 77 main() { | 79 main() { |
| 78 setup(); | 80 setup(); |
| 79 | 81 |
| 80 testTyped(); | 82 testTyped(); |
| 81 testDynamic(); | 83 testDynamic(); |
| 82 } | 84 } |
| OLD | NEW |