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