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