| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 // Test for correct simple is-checks on hidden native classes. | |
| 6 | |
| 7 import "package:expect/expect.dart"; | |
| 8 import 'native_metadata.dart'; | |
| 9 | |
| 10 abstract class J { | |
| 11 } | |
| 12 | |
| 13 abstract class I extends J { | |
| 14 I read(); | |
| 15 write(I x); | |
| 16 } | |
| 17 | |
| 18 // Native implementation. | |
| 19 | |
| 20 @Native("*A") | |
| 21 class A implements I { | |
| 22 // The native class accepts only other native instances. | |
| 23 @native A read(); | |
| 24 @native write(A x); | |
| 25 } | |
| 26 | |
| 27 @Native("*B") | |
| 28 class B extends A { | |
| 29 } | |
| 30 | |
| 31 @native makeA(); | |
| 32 @native makeB(); | |
| 33 | |
| 34 @Native(""" | |
| 35 // This code is all inside 'setup' and so not accesible from the global scope. | |
| 36 function inherits(child, parent) { | |
| 37 if (child.prototype.__proto__) { | |
| 38 child.prototype.__proto__ = parent.prototype; | |
| 39 } else { | |
| 40 function tmp() {}; | |
| 41 tmp.prototype = parent.prototype; | |
| 42 child.prototype = new tmp(); | |
| 43 child.prototype.constructor = child; | |
| 44 } | |
| 45 } | |
| 46 function A(){} | |
| 47 function B(){} | |
| 48 inherits(B, A); | |
| 49 A.prototype.read = function() { return this._x; }; | |
| 50 A.prototype.write = function(x) { this._x = x; }; | |
| 51 makeA = function(){return new A}; | |
| 52 makeB = function(){return new B}; | |
| 53 """) | |
| 54 void setup(); | |
| 55 | |
| 56 class C {} | |
| 57 | |
| 58 main() { | |
| 59 setup(); | |
| 60 | |
| 61 var a1 = makeA(); | |
| 62 var b1 = makeB(); | |
| 63 var ob = new Object(); | |
| 64 | |
| 65 Expect.isFalse(ob is J); | |
| 66 Expect.isFalse(ob is I); | |
| 67 Expect.isFalse(ob is A); | |
| 68 Expect.isFalse(ob is B); | |
| 69 Expect.isFalse(ob is C); | |
| 70 | |
| 71 // Use b1 first to prevent a1 is checks patching the A prototype. | |
| 72 Expect.isTrue(b1 is J); | |
| 73 Expect.isTrue(b1 is I); | |
| 74 Expect.isTrue(b1 is A); | |
| 75 Expect.isTrue(b1 is B); | |
| 76 Expect.isTrue(b1 is !C); | |
| 77 | |
| 78 Expect.isTrue(a1 is J); | |
| 79 Expect.isTrue(a1 is I); | |
| 80 Expect.isTrue(a1 is A); | |
| 81 Expect.isTrue(a1 is !B); | |
| 82 Expect.isTrue(a1 is !C); | |
| 83 } | |
| OLD | NEW |