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