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 // Test for correct simple is-checks on hidden native classes. | 7 // Test for correct simple is-checks on hidden native classes. |
8 | 8 |
9 abstract class I { | 9 abstract class I { |
10 I read(); | 10 I read(); |
11 write(I x); | 11 write(I x); |
12 } | 12 } |
13 | 13 |
14 // Native implementation. | 14 // Native implementation. |
15 | 15 |
16 @Native("A") | 16 @Native("A") |
17 class A implements I { | 17 class A implements I { |
18 // The native class accepts only other native instances. | 18 // The native class accepts only other native instances. |
19 A read() native ; | 19 A read() native; |
20 write(A x) native ; | 20 write(A x) native; |
21 } | 21 } |
22 | 22 |
23 makeA() native ; | 23 makeA() native; |
24 | 24 |
25 void setup() native """ | 25 void setup() native """ |
26 // This code is all inside 'setup' and so not accesible from the global scope. | 26 // This code is all inside 'setup' and so not accesible from the global scope. |
27 function A(){} | 27 function A(){} |
28 A.prototype.read = function() { return this._x; }; | 28 A.prototype.read = function() { return this._x; }; |
29 A.prototype.write = function(x) { this._x = x; }; | 29 A.prototype.write = function(x) { this._x = x; }; |
30 makeA = function(){return new A}; | 30 makeA = function(){return new A}; |
31 self.nativeConstructor(A); | 31 self.nativeConstructor(A); |
32 """; | 32 """; |
33 | 33 |
34 class B {} | 34 class B {} |
35 | 35 |
36 main() { | 36 main() { |
37 nativeTesting(); | 37 nativeTesting(); |
38 setup(); | 38 setup(); |
39 | 39 |
40 var a1 = makeA(); | 40 var a1 = makeA(); |
41 var ob = new Object(); | 41 var ob = new Object(); |
42 | 42 |
43 Expect.isFalse(ob is I); | 43 Expect.isFalse(ob is I); |
44 Expect.isFalse(ob is A); | 44 Expect.isFalse(ob is A); |
45 Expect.isFalse(ob is B); | 45 Expect.isFalse(ob is B); |
46 | 46 |
47 Expect.isTrue(a1 is I); | 47 Expect.isTrue(a1 is I); |
48 Expect.isTrue(a1 is A); | 48 Expect.isTrue(a1 is A); |
49 Expect.isTrue(a1 is! B); | 49 Expect.isTrue(a1 is! B); |
50 } | 50 } |
OLD | NEW |