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