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