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 "package:expect/expect.dart"; |
| 6 import "dart:_js_helper"; |
| 7 import 'dart:_foreign_helper' show JS; |
6 | 8 |
7 // Test to see runtimeType works on native classes and does not use the native | 9 // Test to see runtimeType works on native classes and does not use the native |
8 // constructor name. | 10 // constructor name. |
9 | 11 |
10 @Native("TAGX") | 12 @Native("TAGX") |
11 class A {} | 13 class A {} |
12 | 14 |
13 @Native("TAGY") | 15 @Native("TAGY") |
14 class B extends A {} | 16 class B extends A {} |
15 | 17 |
16 makeA() native ; | 18 makeA() native ; |
17 makeB() native ; | 19 makeB() native ; |
18 | 20 |
19 void setup() native """ | 21 void setup() native """ |
20 // This code is all inside 'setup' and so not accesible from the global scope. | 22 // This code is all inside 'setup' and so not accesible from the global scope. |
21 function inherits(child, parent) { | 23 function inherits(child, parent) { |
22 function tmp() {}; | 24 function tmp() {}; |
23 tmp.prototype = parent.prototype; | 25 tmp.prototype = parent.prototype; |
24 child.prototype = new tmp(); | 26 child.prototype = new tmp(); |
25 child.prototype.constructor = child; | 27 child.prototype.constructor = child; |
26 } | 28 } |
27 | 29 |
28 function TAGX(){} | 30 function TAGX(){} |
29 function TAGY(){} | 31 function TAGY(){} |
30 inherits(TAGY, TAGX); | 32 inherits(TAGY, TAGX); |
31 | 33 |
32 makeA = function(){return new TAGX}; | 34 makeA = function(){return new TAGX}; |
33 makeB = function(){return new TAGY}; | 35 makeB = function(){return new TAGY}; |
34 | |
35 self.nativeConstructor(TAGX); | |
36 self.nativeConstructor(TAGY); | |
37 """; | 36 """; |
38 | 37 |
39 testDynamicContext() { | 38 testDynamicContext() { |
40 var a = makeA(); | 39 var a = makeA(); |
41 var b = makeB(); | 40 var b = makeB(); |
42 | 41 |
43 var aT = a.runtimeType; | 42 var aT = a.runtimeType; |
44 var bT = b.runtimeType; | 43 var bT = b.runtimeType; |
45 | 44 |
46 Expect.notEquals('TAGX', '$aT'); | 45 Expect.notEquals('TAGX', '$aT'); |
47 Expect.notEquals('TAGY', '$bT'); | 46 Expect.notEquals('TAGY', '$bT'); |
48 } | 47 } |
49 | 48 |
50 testStaticContext() { | 49 testStaticContext() { |
51 var a = JS('A', '#', makeA()); // Force compiler to know type. | 50 var a = JS('A', '#', makeA()); // Force compiler to know type. |
52 var b = JS('B', '#', makeB()); | 51 var b = JS('B', '#', makeB()); |
53 | 52 |
54 var aT = a.runtimeType; | 53 var aT = a.runtimeType; |
55 var bT = b.runtimeType; | 54 var bT = b.runtimeType; |
56 | 55 |
57 Expect.notEquals('TAGX', '$aT'); | 56 Expect.notEquals('TAGX', '$aT'); |
58 Expect.notEquals('TAGY', '$bT'); | 57 Expect.notEquals('TAGY', '$bT'); |
59 } | 58 } |
60 | 59 |
61 main() { | 60 main() { |
62 nativeTesting(); | |
63 setup(); | 61 setup(); |
64 | 62 |
65 testDynamicContext(); | 63 testDynamicContext(); |
66 testStaticContext(); | 64 testStaticContext(); |
67 } | 65 } |
OLD | NEW |