| 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 | 10 // This test currently fails because we do not recognize the need for |
| 11 // interceptors without native *classes*. | 11 // interceptors without native *classes*. |
| 12 | 12 |
| 13 class Thing {} | 13 class Thing {} |
| 14 | 14 |
| 15 make1() native ; | 15 make1() native; |
| 16 make2() native ; | 16 make2() native; |
| 17 | 17 |
| 18 void setup() native r""" | 18 void setup() native r""" |
| 19 function A() {} | 19 function A() {} |
| 20 A.prototype.$isThing = true; | 20 A.prototype.$isThing = true; |
| 21 make1 = function(){return new A;}; | 21 make1 = function(){return new A;}; |
| 22 make2 = function(){return {$isThing: true}}; | 22 make2 = function(){return {$isThing: true}}; |
| 23 """; | 23 """; |
| 24 | 24 |
| 25 inscrutable(x) { | 25 inscrutable(x) { |
| 26 if (new DateTime.now().millisecondsSinceEpoch == 0) { | 26 if (new DateTime.now().millisecondsSinceEpoch == 0) { |
| 27 return x; | 27 return x; |
| 28 } else { | 28 } else { |
| 29 return 42; | 29 return 42; |
| 30 } | 30 } |
| 31 } | 31 } |
| 32 | 32 |
| 33 main() { | 33 main() { |
| 34 setup(); | 34 setup(); |
| 35 | 35 |
| 36 var a = new Thing(); | 36 var a = new Thing(); |
| 37 var b = make1(); | 37 var b = make1(); |
| 38 var c = make2(); | 38 var c = make2(); |
| 39 Expect.isTrue(inscrutable(a) is Thing); | 39 Expect.isTrue(inscrutable(a) is Thing); |
| 40 Expect.isFalse(inscrutable(b) is Thing); | 40 Expect.isFalse(inscrutable(b) is Thing); |
| 41 Expect.isFalse(inscrutable(c) is Thing); | 41 Expect.isFalse(inscrutable(c) is Thing); |
| 42 } | 42 } |
| OLD | NEW |