| 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 class A native "*A" { | 9 @native("*A") |
| 10 class A { |
| 10 int key; // jsname is 'key' | 11 int key; // jsname is 'key' |
| 11 int getKey() => key; | 12 int getKey() => key; |
| 12 } | 13 } |
| 13 | 14 |
| 14 class B { | 15 class B { |
| 15 int key; // jsname is not 'key' | 16 int key; // jsname is not 'key' |
| 16 B([this.key = 222]); | 17 B([this.key = 222]); |
| 17 int getKey() => key; | 18 int getKey() => key; |
| 18 } | 19 } |
| 19 | 20 |
| 20 class X native "*X" { | 21 @native("*X") |
| 21 int native_key_method() native 'key'; | 22 class X { |
| 23 @native('key') int native_key_method(); |
| 22 // 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. |
| 23 | 25 |
| 24 int key() native 'key'; | 26 @natve('key') int key(); |
| 25 } | 27 } |
| 26 | 28 |
| 27 A makeA() native; | 29 @native A makeA(); |
| 28 X makeX() native; | 30 @native X makeX(); |
| 29 | 31 |
| 30 | 32 |
| 31 void setup() native """ | 33 @native(""" |
| 32 // This code is all inside 'setup' and so not accesible from the global scope. | 34 // This code is all inside 'setup' and so not accesible from the global scope. |
| 33 function A(){ this.key = 111; } | 35 function A(){ this.key = 111; } |
| 34 A.prototype.getKey = function(){return this.key;}; | 36 A.prototype.getKey = function(){return this.key;}; |
| 35 | 37 |
| 36 function X(){} | 38 function X(){} |
| 37 X.prototype.key = function(){return 666;}; | 39 X.prototype.key = function(){return 666;}; |
| 38 | 40 |
| 39 makeA = function(){return new A}; | 41 makeA = function(){return new A}; |
| 40 makeX = function(){return new X}; | 42 makeX = function(){return new X}; |
| 41 """; | 43 """) |
| 44 void setup(); |
| 42 | 45 |
| 43 testDynamic() { | 46 testDynamic() { |
| 44 var things = [makeA(), new B(), makeX()]; | 47 var things = [makeA(), new B(), makeX()]; |
| 45 var a = things[0]; | 48 var a = things[0]; |
| 46 var b = things[1]; | 49 var b = things[1]; |
| 47 var x = things[2]; | 50 var x = things[2]; |
| 48 | 51 |
| 49 Expect.equals(111, a.key); | 52 Expect.equals(111, a.key); |
| 50 Expect.equals(222, b.key); | 53 Expect.equals(222, b.key); |
| 51 Expect.equals(111, a.getKey()); | 54 Expect.equals(111, a.getKey()); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 70 Expect.equals(111, a.getKey()); | 73 Expect.equals(111, a.getKey()); |
| 71 Expect.equals(222, b.getKey()); | 74 Expect.equals(222, b.getKey()); |
| 72 } | 75 } |
| 73 | 76 |
| 74 main() { | 77 main() { |
| 75 setup(); | 78 setup(); |
| 76 | 79 |
| 77 testTyped(); | 80 testTyped(); |
| 78 testDynamic(); | 81 testDynamic(); |
| 79 } | 82 } |
| OLD | NEW |