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 'native_testing.dart'; | 5 import 'native_testing.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 // The difference between fake_thing_test and fake_thing_2_test is the | 9 // The difference between fake_thing_test and fake_thing_2_test is the |
10 // presence of a used declared native class. | 10 // presence of a used declared native class. |
11 | 11 |
12 class Thing {} | 12 class Thing {} |
13 | 13 |
14 @Native("NT") | 14 @Native("NT") |
15 class NativeThing {} | 15 class NativeThing {} |
16 | 16 |
17 make1() native ; | 17 make1() native; |
18 make2() native ; | 18 make2() native; |
19 make3() native ; | 19 make3() native; |
20 | 20 |
21 void setup() native r""" | 21 void setup() native r""" |
22 function A() {} | 22 function A() {} |
23 A.prototype.$isThing = true; | 23 A.prototype.$isThing = true; |
24 make1 = function(){return new A;}; | 24 make1 = function(){return new A;}; |
25 make2 = function(){return {$isThing: true}}; | 25 make2 = function(){return {$isThing: true}}; |
26 function NT() {} | 26 function NT() {} |
27 NT.prototype.$isThing = true; | 27 NT.prototype.$isThing = true; |
28 make3 = function(){return new NT;}; | 28 make3 = function(){return new NT;}; |
29 | 29 |
30 self.nativeConstructor(NT); | 30 self.nativeConstructor(NT); |
31 """; | 31 """; |
32 | 32 |
33 main() { | 33 main() { |
34 nativeTesting(); | 34 nativeTesting(); |
35 setup(); | 35 setup(); |
36 | 36 |
37 var a = new Thing(); | 37 var a = new Thing(); |
38 var b = make1(); | 38 var b = make1(); |
39 var c = make2(); | 39 var c = make2(); |
40 var d = make3(); | 40 var d = make3(); |
41 Expect.isTrue(confuse(a) is Thing); | 41 Expect.isTrue(confuse(a) is Thing); |
42 Expect.isFalse(confuse(b) is Thing); | 42 Expect.isFalse(confuse(b) is Thing); |
43 Expect.isFalse(confuse(c) is Thing); | 43 Expect.isFalse(confuse(c) is Thing); |
44 Expect.isFalse(confuse(d) is Thing); | 44 Expect.isFalse(confuse(d) is Thing); |
45 } | 45 } |
OLD | NEW |