| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 "package:expect/expect.dart"; | 5 import "package:expect/expect.dart"; |
| 6 | 6 |
| 7 // Test that native objects cannot accidentally or maliciously be mistaken for | 7 // Test that native objects cannot accidentally or maliciously be mistaken for |
| 8 // Dart objects. | 8 // Dart objects. |
| 9 | 9 |
| 10 // This test currently fails because we do not recognize the need for |
| 11 // interceptors without native *classes*. |
| 12 |
| 10 class Thing { | 13 class Thing { |
| 11 } | 14 } |
| 12 | 15 |
| 13 make1() native; | 16 make1() native; |
| 14 make2() native; | 17 make2() native; |
| 15 | 18 |
| 16 void setup() native r""" | 19 void setup() native r""" |
| 17 function A() {} | 20 function A() {} |
| 18 A.prototype.$isThing = true; | 21 A.prototype.$isThing = true; |
| 19 make1 = function(){return new A;}; | 22 make1 = function(){return new A;}; |
| 20 make2 = function(){return {$isThing: true}}; | 23 make2 = function(){return {$isThing: true}}; |
| 21 """; | 24 """; |
| 22 | 25 |
| 23 var inscrutable; | 26 inscrutable(x) { |
| 27 if (new DateTime.now().millisecondsSinceEpoch == 0) { |
| 28 return x; |
| 29 } else { |
| 30 return 42; |
| 31 } |
| 32 } |
| 33 |
| 24 main() { | 34 main() { |
| 25 setup(); | 35 setup(); |
| 26 inscrutable = (x) => x; | |
| 27 | 36 |
| 28 var a = new Thing(); | 37 var a = new Thing(); |
| 29 var b = make1(); | 38 var b = make1(); |
| 30 var c = make2(); | 39 var c = make2(); |
| 31 Expect.isTrue(inscrutable(a) is Thing); | 40 Expect.isTrue(inscrutable(a) is Thing); |
| 32 Expect.isFalse(inscrutable(b) is Thing); | 41 Expect.isFalse(inscrutable(b) is Thing); |
| 33 Expect.isFalse(inscrutable(c) is Thing); | 42 Expect.isFalse(inscrutable(c) is Thing); |
| 34 } | 43 } |
| OLD | NEW |