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