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 "dart:_js_helper"; | 5 import "dart:_js_helper"; |
6 import "package:expect/expect.dart"; | 6 import "package:expect/expect.dart"; |
7 | 7 |
8 // Test that native objects cannot accidentally or maliciously be mistaken for | 8 // Test that native objects cannot accidentally or maliciously be mistaken for |
9 // Dart objects. | 9 // Dart objects. |
10 // The difference between fake_thing_test and fake_thing_2_test is the | 10 // The difference between fake_thing_test and fake_thing_2_test is the |
11 // presence of a used declared native class. | 11 // presence of a used declared native class. |
12 | 12 |
13 class Thing { | 13 class Thing {} |
14 } | |
15 | 14 |
16 @Native("NT") | 15 @Native("NT") |
17 class NativeThing { | 16 class NativeThing {} |
18 } | |
19 | 17 |
20 make1() native; | 18 make1() native ; |
21 make2() native; | 19 make2() native ; |
22 make3() native; | 20 make3() native ; |
23 | 21 |
24 void setup() native r""" | 22 void setup() native r""" |
25 function A() {} | 23 function A() {} |
26 A.prototype.$isThing = true; | 24 A.prototype.$isThing = true; |
27 make1 = function(){return new A;}; | 25 make1 = function(){return new A;}; |
28 make2 = function(){return {$isThing: true}}; | 26 make2 = function(){return {$isThing: true}}; |
29 function NT() {} | 27 function NT() {} |
30 NT.prototype.$isThing = true; | 28 NT.prototype.$isThing = true; |
31 make3 = function(){return new NT;}; | 29 make3 = function(){return new NT;}; |
32 """; | 30 """; |
33 | 31 |
34 var inscrutable; | 32 var inscrutable; |
35 main() { | 33 main() { |
36 setup(); | 34 setup(); |
37 inscrutable = (x) => x; | 35 inscrutable = (x) => x; |
38 | 36 |
39 var a = new Thing(); | 37 var a = new Thing(); |
40 var b = make1(); | 38 var b = make1(); |
41 var c = make2(); | 39 var c = make2(); |
42 var d = make3(); | 40 var d = make3(); |
43 Expect.isTrue(inscrutable(a) is Thing); | 41 Expect.isTrue(inscrutable(a) is Thing); |
44 Expect.isFalse(inscrutable(b) is Thing); | 42 Expect.isFalse(inscrutable(b) is Thing); |
45 Expect.isFalse(inscrutable(c) is Thing); | 43 Expect.isFalse(inscrutable(c) is Thing); |
46 Expect.isFalse(inscrutable(d) is Thing); | 44 Expect.isFalse(inscrutable(d) is Thing); |
47 } | 45 } |
OLD | NEW |