OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 // Test to see if resolving a hidden native class's method interferes with | |
6 // subsequent resolving the subclass's method. This might happen if the | |
7 // superclass caches the method in the prototype, so shadowing the dispatcher | |
8 // stored on Object.prototype. | |
9 | |
10 class A native "*A" { | |
11 foo([a=100]) native; | |
12 } | |
13 | |
14 class B extends A native "*B" { | |
15 } | |
16 | |
17 class C extends B native "*C" { | |
18 foo([z=300]) native; | |
19 } | |
20 | |
21 class D extends C native "*D" { | |
22 } | |
23 | |
24 makeA() native; | |
25 makeB() native; | |
26 makeC() native; | |
27 makeD() native; | |
28 | |
29 void setup() native """ | |
30 // This code is all inside 'setup' and so not accesible from the global scope. | |
31 function inherits(child, parent) { | |
32 if (child.prototype.__proto__) { | |
33 child.prototype.__proto__ = parent.prototype; | |
34 } else { | |
35 function tmp() {}; | |
36 tmp.prototype = parent.prototype; | |
37 child.prototype = new tmp(); | |
38 child.prototype.constructor = child; | |
39 } | |
40 } | |
41 | |
42 function A(){} | |
43 function B(){} | |
44 inherits(B, A); | |
45 function C(){} | |
46 inherits(C, B); | |
47 function D(){} | |
48 inherits(D, C); | |
49 | |
50 A.prototype.foo = function(a){return 'A.foo(' + a + ')';} | |
51 C.prototype.foo = function(z){return 'C.foo(' + z + ')';} | |
52 | |
53 makeA = function(){return new A}; | |
54 makeB = function(){return new B}; | |
55 makeC = function(){return new C}; | |
56 makeD = function(){return new D}; | |
57 """; | |
58 | |
59 | |
60 main() { | |
61 setup(); | |
62 | |
63 var a = makeA(); | |
64 var b = makeB(); | |
65 var c = makeC(); | |
66 var d = makeD(); | |
67 | |
68 Expect.equals('A.foo(100)', b.foo()); | |
69 Expect.equals('C.foo(300)', d.foo()); | |
70 // If the above line fails with C.foo(100) then the dispatch to fill in the | |
71 // default got the wrong one, followed by a second dispatch that resolved to | |
72 // the correct native method. | |
73 | |
74 Expect.equals('A.foo(1)', a.foo(1)); | |
75 Expect.equals('A.foo(2)', b.foo(2)); | |
76 Expect.equals('C.foo(3)', c.foo(3)); | |
77 Expect.equals('C.foo(4)', d.foo(4)); | |
78 } | |
OLD | NEW |