| 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() { |
| 26 // This code is all inside 'setup' and so not accessible from the global scope. | 26 JS('', r""" |
| 27 function A(){} | 27 (function(){ |
| 28 A.prototype.read = function() { return this._x; }; | 28 // This code is inside 'setup' and so not accessible from the global scope. |
| 29 A.prototype.write = function(x) { this._x = x; }; | 29 function A(){} |
| 30 makeA = function(){return new A}; | 30 A.prototype.read = function() { return this._x; }; |
| 31 self.nativeConstructor(A); | 31 A.prototype.write = function(x) { this._x = x; }; |
| 32 """; | 32 makeA = function(){return new A()}; |
| 33 self.nativeConstructor(A); |
| 34 })()"""); |
| 35 } |
| 33 | 36 |
| 34 class B {} | 37 class B {} |
| 35 | 38 |
| 36 main() { | 39 main() { |
| 37 nativeTesting(); | 40 nativeTesting(); |
| 38 setup(); | 41 setup(); |
| 39 | 42 |
| 40 var a1 = makeA(); | 43 var a1 = makeA(); |
| 41 var ob = new Object(); | 44 var ob = new Object(); |
| 42 | 45 |
| 43 Expect.isFalse(ob is I); | 46 Expect.isFalse(ob is I); |
| 44 Expect.isFalse(ob is A); | 47 Expect.isFalse(ob is A); |
| 45 Expect.isFalse(ob is B); | 48 Expect.isFalse(ob is B); |
| 46 | 49 |
| 47 Expect.isTrue(a1 is I); | 50 Expect.isTrue(a1 is I); |
| 48 Expect.isTrue(a1 is A); | 51 Expect.isTrue(a1 is A); |
| 49 Expect.isTrue(a1 is! B); | 52 Expect.isTrue(a1 is! B); |
| 50 } | 53 } |
| OLD | NEW |