OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, 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 to see if resolving a hidden native class's method interferes with | 8 // Test to see if resolving a hidden native class's method interferes with |
9 // subsequent resolving the subclass's method. This might happen if the | 9 // subsequent resolving the subclass's method. This might happen if the |
10 // superclass caches the method in the prototype, so shadowing the dispatcher | 10 // superclass caches the method in the prototype, so shadowing the dispatcher |
(...skipping 14 matching lines...) Expand all Loading... |
25 class C extends B { | 25 class C extends B { |
26 foo() => 'C.foo; super.foo = ${super.foo()}'; | 26 foo() => 'C.foo; super.foo = ${super.foo()}'; |
27 bar() => 'C.bar'; | 27 bar() => 'C.bar'; |
28 } | 28 } |
29 | 29 |
30 @Native("D") | 30 @Native("D") |
31 class D extends C { | 31 class D extends C { |
32 bar() => 'D.bar'; | 32 bar() => 'D.bar'; |
33 } | 33 } |
34 | 34 |
35 makeA() native; | 35 makeA() native ; |
36 makeB() native; | 36 makeB() native ; |
37 makeC() native; | 37 makeC() native ; |
38 makeD() native; | 38 makeD() native ; |
39 | 39 |
40 void setup() native """ | 40 void setup() native """ |
41 // This code is all inside 'setup' and so not accesible from the global scope. | 41 // This code is all inside 'setup' and so not accesible from the global scope. |
42 function inherits(child, parent) { | 42 function inherits(child, parent) { |
43 if (child.prototype.__proto__) { | 43 if (child.prototype.__proto__) { |
44 child.prototype.__proto__ = parent.prototype; | 44 child.prototype.__proto__ = parent.prototype; |
45 } else { | 45 } else { |
46 function tmp() {}; | 46 function tmp() {}; |
47 tmp.prototype = parent.prototype; | 47 tmp.prototype = parent.prototype; |
48 child.prototype = new tmp(); | 48 child.prototype = new tmp(); |
49 child.prototype.constructor = child; | 49 child.prototype.constructor = child; |
50 } | 50 } |
51 } | 51 } |
52 | 52 |
53 function A(){} | 53 function A(){} |
54 function B(){} | 54 function B(){} |
55 inherits(B, A); | 55 inherits(B, A); |
56 function C(){} | 56 function C(){} |
57 inherits(C, B); | 57 inherits(C, B); |
58 function D(){} | 58 function D(){} |
59 inherits(D, C); | 59 inherits(D, C); |
60 | 60 |
61 makeA = function(){return new A}; | 61 makeA = function(){return new A}; |
62 makeB = function(){return new B}; | 62 makeB = function(){return new B}; |
63 makeC = function(){return new C}; | 63 makeC = function(){return new C}; |
64 makeD = function(){return new D}; | 64 makeD = function(){return new D}; |
65 """; | 65 """; |
66 | 66 |
67 | |
68 main() { | 67 main() { |
69 setup(); | 68 setup(); |
70 | 69 |
71 var a = makeA(); | 70 var a = makeA(); |
72 var b = makeB(); | 71 var b = makeB(); |
73 var c = makeC(); | 72 var c = makeC(); |
74 var d = makeD(); | 73 var d = makeD(); |
75 | 74 |
76 Expect.equals('A.foo A.bar', a.foo()); | 75 Expect.equals('A.foo A.bar', a.foo()); |
77 Expect.equals('A.foo B.bar', b.foo()); | 76 Expect.equals('A.foo B.bar', b.foo()); |
78 Expect.equals('C.foo; super.foo = A.foo C.bar', c.foo()); | 77 Expect.equals('C.foo; super.foo = A.foo C.bar', c.foo()); |
79 Expect.equals('C.foo; super.foo = A.foo D.bar', d.foo()); | 78 Expect.equals('C.foo; super.foo = A.foo D.bar', d.foo()); |
80 } | 79 } |
OLD | NEW |