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