| 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 18 matching lines...) Expand all Loading... |
| 29 @JSName('key') | 29 @JSName('key') |
| 30 int native_key_method() native; | 30 int native_key_method() native; |
| 31 // This should cause B.key to be renamed, but not A.key. | 31 // This should cause B.key to be renamed, but not A.key. |
| 32 @JSName('key') | 32 @JSName('key') |
| 33 int key() native; | 33 int key() native; |
| 34 } | 34 } |
| 35 | 35 |
| 36 A makeA() native; | 36 A makeA() native; |
| 37 X makeX() native; | 37 X makeX() native; |
| 38 | 38 |
| 39 void setup() native """ | 39 void setup() { |
| 40 // This code is all inside 'setup' and so not accessible from the global scope. | 40 JS('', r""" |
| 41 function A(){ this.key = 111; } | 41 (function(){ |
| 42 A.prototype.getKey = function(){return this.key;}; | 42 // This code is inside 'setup' and so not accessible from the global scope. |
| 43 function A(){ this.key = 111; } |
| 44 A.prototype.getKey = function(){return this.key;}; |
| 43 | 45 |
| 44 function X(){} | 46 function X(){} |
| 45 X.prototype.key = function(){return 666;}; | 47 X.prototype.key = function(){return 666;}; |
| 46 | 48 |
| 47 makeA = function(){return new A}; | 49 makeA = function(){return new A()}; |
| 48 makeX = function(){return new X}; | 50 makeX = function(){return new X()}; |
| 49 | 51 |
| 50 self.nativeConstructor(A); | 52 self.nativeConstructor(A); |
| 51 self.nativeConstructor(X); | 53 self.nativeConstructor(X); |
| 52 """; | 54 })()"""); |
| 55 } |
| 53 | 56 |
| 54 testDynamic() { | 57 testDynamic() { |
| 55 var a = confuse(makeA()); | 58 var a = confuse(makeA()); |
| 56 var b = confuse(new B()); | 59 var b = confuse(new B()); |
| 57 var x = confuse(makeX()); | 60 var x = confuse(makeX()); |
| 58 | 61 |
| 59 Expect.equals(111, a.key); | 62 Expect.equals(111, a.key); |
| 60 Expect.equals(222, b.key); | 63 Expect.equals(222, b.key); |
| 61 Expect.equals(111, a.getKey()); | 64 Expect.equals(111, a.getKey()); |
| 62 Expect.equals(222, b.getKey()); | 65 Expect.equals(222, b.getKey()); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 92 } | 95 } |
| 93 | 96 |
| 94 main() { | 97 main() { |
| 95 nativeTesting(); | 98 nativeTesting(); |
| 96 setup(); | 99 setup(); |
| 97 | 100 |
| 98 testTyped(); | 101 testTyped(); |
| 99 testPartial(); | 102 testPartial(); |
| 100 testDynamic(); | 103 testDynamic(); |
| 101 } | 104 } |
| OLD | NEW |