| 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 @native("*A") | 10 import 'native_metadata.dart'; |
| 11 |
| 12 @Native("*A") |
| 11 class A { | 13 class A { |
| 12 @native foo([a=100]); | 14 @native foo([a=100]); |
| 13 } | 15 } |
| 14 | 16 |
| 15 @native("*B") | 17 @Native("*B") |
| 16 class B extends A { | 18 class B extends A { |
| 17 } | 19 } |
| 18 | 20 |
| 19 @native("*C") | 21 @Native("*C") |
| 20 class C extends B { | 22 class C extends B { |
| 21 @native foo([z=300]); | 23 @native foo([z=300]); |
| 22 } | 24 } |
| 23 | 25 |
| 24 @native("*D") | 26 @Native("*D") |
| 25 class D extends C { | 27 class D extends C { |
| 26 } | 28 } |
| 27 | 29 |
| 28 @native makeA(); | 30 @native makeA(); |
| 29 @native makeB(); | 31 @native makeB(); |
| 30 @native makeC(); | 32 @native makeC(); |
| 31 @native makeD(); | 33 @native makeD(); |
| 32 | 34 |
| 33 @native(""" | 35 @Native(""" |
| 34 // This code is all inside 'setup' and so not accesible from the global scope. | 36 // This code is all inside 'setup' and so not accesible from the global scope. |
| 35 function inherits(child, parent) { | 37 function inherits(child, parent) { |
| 36 if (child.prototype.__proto__) { | 38 if (child.prototype.__proto__) { |
| 37 child.prototype.__proto__ = parent.prototype; | 39 child.prototype.__proto__ = parent.prototype; |
| 38 } else { | 40 } else { |
| 39 function tmp() {}; | 41 function tmp() {}; |
| 40 tmp.prototype = parent.prototype; | 42 tmp.prototype = parent.prototype; |
| 41 child.prototype = new tmp(); | 43 child.prototype = new tmp(); |
| 42 child.prototype.constructor = child; | 44 child.prototype.constructor = child; |
| 43 } | 45 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 74 Expect.equals('C.foo(300)', d.foo()); | 76 Expect.equals('C.foo(300)', d.foo()); |
| 75 // If the above line fails with C.foo(100) then the dispatch to fill in the | 77 // If the above line fails with C.foo(100) then the dispatch to fill in the |
| 76 // default got the wrong one, followed by a second dispatch that resolved to | 78 // default got the wrong one, followed by a second dispatch that resolved to |
| 77 // the correct native method. | 79 // the correct native method. |
| 78 | 80 |
| 79 Expect.equals('A.foo(1)', a.foo(1)); | 81 Expect.equals('A.foo(1)', a.foo(1)); |
| 80 Expect.equals('A.foo(2)', b.foo(2)); | 82 Expect.equals('A.foo(2)', b.foo(2)); |
| 81 Expect.equals('C.foo(3)', c.foo(3)); | 83 Expect.equals('C.foo(3)', c.foo(3)); |
| 82 Expect.equals('C.foo(4)', d.foo(4)); | 84 Expect.equals('C.foo(4)', d.foo(4)); |
| 83 } | 85 } |
| OLD | NEW |