| 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 // Additional Dart code may be 'placed on' hidden native classes. With | 5 // Additional Dart code may be 'placed on' hidden native classes. With |
| 6 // inheritance, the superclass method must not be reached by a call on the | 6 // inheritance, the superclass method must not be reached by a call on the |
| 7 // subclass. | 7 // subclass. |
| 8 | 8 |
| 9 class A native "*A" { | 9 @native("*A") |
| 10 class A { |
| 10 var _field; | 11 var _field; |
| 11 | 12 |
| 12 int get X => _field; | 13 int get X => _field; |
| 13 void set X(int x) { _field = x; } | 14 void set X(int x) { _field = x; } |
| 14 | 15 |
| 15 int method(int z) => _field + z; | 16 int method(int z) => _field + z; |
| 16 } | 17 } |
| 17 | 18 |
| 18 class B extends A native "*B" { | 19 @native("*B") |
| 20 class B extends A { |
| 19 var _field2; | 21 var _field2; |
| 20 | 22 |
| 21 int get X => _field2; | 23 int get X => _field2; |
| 22 void set X(int x) { _field2 = x; } | 24 void set X(int x) { _field2 = x; } |
| 23 | 25 |
| 24 int method(int z) => _field2 + z; | 26 int method(int z) => _field2 + z; |
| 25 } | 27 } |
| 26 | 28 |
| 27 A makeA() native { return new A(); } | 29 @native A makeA() { return new A(); } |
| 28 B makeB() native { return new B(); } | 30 @native B makeB() { return new B(); } |
| 29 | 31 |
| 30 void setup() native @""" | 32 @native(@""" |
| 31 function inherits(child, parent) { | 33 function inherits(child, parent) { |
| 32 if (child.prototype.__proto__) { | 34 if (child.prototype.__proto__) { |
| 33 child.prototype.__proto__ = parent.prototype; | 35 child.prototype.__proto__ = parent.prototype; |
| 34 } else { | 36 } else { |
| 35 function tmp() {}; | 37 function tmp() {}; |
| 36 tmp.prototype = parent.prototype; | 38 tmp.prototype = parent.prototype; |
| 37 child.prototype = new tmp(); | 39 child.prototype = new tmp(); |
| 38 child.prototype.constructor = child; | 40 child.prototype.constructor = child; |
| 39 } | 41 } |
| 40 } | 42 } |
| 41 | 43 |
| 42 function A(){} | 44 function A(){} |
| 43 function B(){} | 45 function B(){} |
| 44 inherits(B, A); | 46 inherits(B, A); |
| 45 makeA = function(){return new A;}; | 47 makeA = function(){return new A;}; |
| 46 makeB = function(){return new B;}; | 48 makeB = function(){return new B;}; |
| 47 """; | 49 """) |
| 50 void setup(); |
| 48 | 51 |
| 49 testBasicA_dynamic() { | 52 testBasicA_dynamic() { |
| 50 setup(); // Fresh constructors. | 53 setup(); // Fresh constructors. |
| 51 | 54 |
| 52 var a = [makeA()][0]; | 55 var a = [makeA()][0]; |
| 53 | 56 |
| 54 a.X = 100; | 57 a.X = 100; |
| 55 Expect.equals(100, a._field); | 58 Expect.equals(100, a._field); |
| 56 Expect.equals(100, a.X); | 59 Expect.equals(100, a.X); |
| 57 Expect.equals(150, a.method(50)); | 60 Expect.equals(150, a.method(50)); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 } | 139 } |
| 137 | 140 |
| 138 main() { | 141 main() { |
| 139 testBasicA_dynamic(); | 142 testBasicA_dynamic(); |
| 140 testBasicA_typed(); | 143 testBasicA_typed(); |
| 141 testBasicB_dynamic(); | 144 testBasicB_dynamic(); |
| 142 testBasicB_typed(); | 145 testBasicB_typed(); |
| 143 testAB_dynamic(); | 146 testAB_dynamic(); |
| 144 testAB_typed(); | 147 testAB_typed(); |
| 145 } | 148 } |
| OLD | NEW |