| 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 import "native_testing.dart"; | 5 import "native_testing.dart"; |
| 6 | 6 |
| 7 // Additional Dart code may be 'placed on' hidden native classes. With | 7 // Additional Dart code may be 'placed on' hidden native classes. With |
| 8 // inheritance, the superclass method must not be reached by a call on the | 8 // inheritance, the superclass method must not be reached by a call on the |
| 9 // subclass. | 9 // subclass. |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 void set X(int x) { | 28 void set X(int x) { |
| 29 _field2 = x; | 29 _field2 = x; |
| 30 } | 30 } |
| 31 | 31 |
| 32 int method(int z) => _field2 + z; | 32 int method(int z) => _field2 + z; |
| 33 } | 33 } |
| 34 | 34 |
| 35 A makeA() native; | 35 A makeA() native; |
| 36 B makeB() native; | 36 B makeB() native; |
| 37 | 37 |
| 38 void setup() native r""" | 38 void setup() { |
| 39 function inherits(child, parent) { | 39 JS('', r""" |
| 40 if (child.prototype.__proto__) { | 40 (function(){ |
| 41 child.prototype.__proto__ = parent.prototype; | 41 function inherits(child, parent) { |
| 42 } else { | 42 if (child.prototype.__proto__) { |
| 43 function tmp() {}; | 43 child.prototype.__proto__ = parent.prototype; |
| 44 tmp.prototype = parent.prototype; | 44 } else { |
| 45 child.prototype = new tmp(); | 45 function tmp() {}; |
| 46 child.prototype.constructor = child; | 46 tmp.prototype = parent.prototype; |
| 47 child.prototype = new tmp(); |
| 48 child.prototype.constructor = child; |
| 49 } |
| 47 } | 50 } |
| 51 |
| 52 function A(){} |
| 53 function B(){} |
| 54 inherits(B, A); |
| 55 makeA = function(){return new A()}; |
| 56 makeB = function(){return new B()}; |
| 57 |
| 58 self.nativeConstructor(A); |
| 59 self.nativeConstructor(B); |
| 60 })()"""); |
| 48 } | 61 } |
| 49 | 62 |
| 50 function A(){} | |
| 51 function B(){} | |
| 52 inherits(B, A); | |
| 53 makeA = function(){return new A;}; | |
| 54 makeB = function(){return new B;}; | |
| 55 | |
| 56 self.nativeConstructor(A); | |
| 57 self.nativeConstructor(B); | |
| 58 """; | |
| 59 | |
| 60 testBasicA_dynamic() { | 63 testBasicA_dynamic() { |
| 61 setup(); // Fresh constructors. | 64 setup(); // Fresh constructors. |
| 62 | 65 |
| 63 var a = [makeA()][0]; | 66 var a = [makeA()][0]; |
| 64 | 67 |
| 65 a.X = 100; | 68 a.X = 100; |
| 66 Expect.equals(100, a._field); | 69 Expect.equals(100, a._field); |
| 67 Expect.equals(100, a.X); | 70 Expect.equals(100, a.X); |
| 68 Expect.equals(150, a.method(50)); | 71 Expect.equals(150, a.method(50)); |
| 69 } | 72 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 | 151 |
| 149 main() { | 152 main() { |
| 150 nativeTesting(); | 153 nativeTesting(); |
| 151 testBasicA_dynamic(); | 154 testBasicA_dynamic(); |
| 152 testBasicA_typed(); | 155 testBasicA_typed(); |
| 153 testBasicB_dynamic(); | 156 testBasicB_dynamic(); |
| 154 testBasicB_typed(); | 157 testBasicB_typed(); |
| 155 testAB_dynamic(); | 158 testAB_dynamic(); |
| 156 testAB_typed(); | 159 testAB_typed(); |
| 157 } | 160 } |
| OLD | NEW |