| 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 // Test for downcasts on native classes. | 5 // Test for downcasts on native classes. |
| 6 | 6 |
| 7 import "dart:_js_helper"; | 7 import "native_testing.dart"; |
| 8 import "package:expect/expect.dart"; | |
| 9 | 8 |
| 10 abstract class J {} | 9 abstract class J {} |
| 11 | 10 |
| 12 abstract class I extends J { | 11 abstract class I extends J { |
| 13 I read(); | 12 I read(); |
| 14 write(I x); | 13 write(I x); |
| 15 } | 14 } |
| 16 | 15 |
| 17 // Native implementation. | 16 // Native implementation. |
| 18 | 17 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 41 child.prototype.constructor = child; | 40 child.prototype.constructor = child; |
| 42 } | 41 } |
| 43 } | 42 } |
| 44 function A(){} | 43 function A(){} |
| 45 function B(){} | 44 function B(){} |
| 46 inherits(B, A); | 45 inherits(B, A); |
| 47 A.prototype.read = function() { return this._x; }; | 46 A.prototype.read = function() { return this._x; }; |
| 48 A.prototype.write = function(x) { this._x = x; }; | 47 A.prototype.write = function(x) { this._x = x; }; |
| 49 makeA = function(){return new A}; | 48 makeA = function(){return new A}; |
| 50 makeB = function(){return new B}; | 49 makeB = function(){return new B}; |
| 50 |
| 51 self.nativeConstructor(A); |
| 52 self.nativeConstructor(B); |
| 51 """; | 53 """; |
| 52 | 54 |
| 53 class C {} | 55 class C {} |
| 54 | 56 |
| 55 bool _check(a, b) => identical(a, b); | 57 bool _check(a, b) => identical(a, b); |
| 56 | 58 |
| 57 main() { | 59 main() { |
| 60 nativeTesting(); |
| 58 setup(); | 61 setup(); |
| 59 | 62 |
| 60 var a1 = makeA(); | 63 var a1 = makeA(); |
| 61 var b1 = makeB(); | 64 var b1 = makeB(); |
| 62 var ob = new Object(); | 65 var ob = new Object(); |
| 63 | 66 |
| 64 Expect.throws(() => ob as J); | 67 Expect.throws(() => ob as J); |
| 65 Expect.throws(() => ob as I); | 68 Expect.throws(() => ob as I); |
| 66 Expect.throws(() => ob as A); | 69 Expect.throws(() => ob as A); |
| 67 Expect.throws(() => ob as B); | 70 Expect.throws(() => ob as B); |
| 68 Expect.throws(() => ob as C); | 71 Expect.throws(() => ob as C); |
| 69 | 72 |
| 70 // Use b1 first to prevent a1 is checks patching the A prototype. | 73 // Use b1 first to prevent a1 is checks patching the A prototype. |
| 71 Expect.equals(b1, b1 as J); | 74 Expect.equals(b1, b1 as J); |
| 72 Expect.equals(b1, b1 as I); | 75 Expect.equals(b1, b1 as I); |
| 73 Expect.equals(b1, b1 as A); | 76 Expect.equals(b1, b1 as A); |
| 74 Expect.equals(b1, b1 as B); | 77 Expect.equals(b1, b1 as B); |
| 75 | 78 |
| 76 Expect.equals(a1, a1 as J); | 79 Expect.equals(a1, a1 as J); |
| 77 Expect.equals(a1, a1 as I); | 80 Expect.equals(a1, a1 as I); |
| 78 Expect.equals(a1, a1 as A); | 81 Expect.equals(a1, a1 as A); |
| 79 Expect.throws(() => a1 as B); | 82 Expect.throws(() => a1 as B); |
| 80 Expect.throws(() => a1 as C); | 83 Expect.throws(() => a1 as C); |
| 81 } | 84 } |
| OLD | NEW |