| 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 import 'native_testing.dart'; | 9 import 'native_testing.dart'; |
| 10 | 10 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 int native_key_method() native; | 26 int native_key_method() native; |
| 27 // 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. |
| 28 | 28 |
| 29 @JSName('key') | 29 @JSName('key') |
| 30 int key() native; | 30 int key() native; |
| 31 } | 31 } |
| 32 | 32 |
| 33 A makeA() native; | 33 A makeA() native; |
| 34 X makeX() native; | 34 X makeX() native; |
| 35 | 35 |
| 36 void setup() native """ | 36 void setup() { |
| 37 // This code is all inside 'setup' and so not accessible from the global scope. | 37 JS('', r""" |
| 38 function A(){ this.key = 111; } | 38 (function(){ |
| 39 A.prototype.getKey = function(){return this.key;}; | 39 // This code is inside 'setup' and so not accessible from the global scope. |
| 40 function A(){ this.key = 111; } |
| 41 A.prototype.getKey = function(){return this.key;}; |
| 40 | 42 |
| 41 function X(){} | 43 function X(){} |
| 42 X.prototype.key = function(){return 666;}; | 44 X.prototype.key = function(){return 666;}; |
| 43 | 45 |
| 44 makeA = function(){return new A}; | 46 makeA = function(){return new A()}; |
| 45 makeX = function(){return new X}; | 47 makeX = function(){return new X()}; |
| 46 | 48 |
| 47 self.nativeConstructor(A); | 49 self.nativeConstructor(A); |
| 48 self.nativeConstructor(X); | 50 self.nativeConstructor(X); |
| 49 """; | 51 })()"""); |
| 52 } |
| 50 | 53 |
| 51 testDynamic() { | 54 testDynamic() { |
| 52 var a = confuse(makeA()); | 55 var a = confuse(makeA()); |
| 53 var b = confuse(new B()); | 56 var b = confuse(new B()); |
| 54 var x = confuse(makeX()); | 57 var x = confuse(makeX()); |
| 55 | 58 |
| 56 Expect.equals(111, a.key); | 59 Expect.equals(111, a.key); |
| 57 Expect.equals(222, b.key); | 60 Expect.equals(222, b.key); |
| 58 Expect.equals(111, a.getKey()); | 61 Expect.equals(111, a.getKey()); |
| 59 Expect.equals(222, b.getKey()); | 62 Expect.equals(222, b.getKey()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 77 Expect.equals(222, b.getKey()); | 80 Expect.equals(222, b.getKey()); |
| 78 } | 81 } |
| 79 | 82 |
| 80 main() { | 83 main() { |
| 81 nativeTesting(); | 84 nativeTesting(); |
| 82 setup(); | 85 setup(); |
| 83 | 86 |
| 84 testTyped(); | 87 testTyped(); |
| 85 testDynamic(); | 88 testDynamic(); |
| 86 } | 89 } |
| OLD | NEW |