| 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 // Version 1: It might be possible to call foo directly. | 13 // Version 1: It might be possible to call foo directly. |
| 14 @Native("A1") | 14 @Native("A1") |
| 15 class A1 { | 15 class A1 { |
| 16 foo() native; | 16 foo() native ; |
| 17 } | 17 } |
| 18 | 18 |
| 19 @Native("B1") | 19 @Native("B1") |
| 20 class B1 extends A1 { | 20 class B1 extends A1 { |
| 21 foo() native; | 21 foo() native ; |
| 22 } | 22 } |
| 23 | 23 |
| 24 makeA1() native; | 24 makeA1() native ; |
| 25 makeB1() native; | 25 makeB1() native ; |
| 26 | |
| 27 | 26 |
| 28 // Version 2: foo needs some kind of trampoline. | 27 // Version 2: foo needs some kind of trampoline. |
| 29 @Native("A2") | 28 @Native("A2") |
| 30 class A2 { | 29 class A2 { |
| 31 foo([a=99]) native; | 30 foo([a = 99]) native ; |
| 32 } | 31 } |
| 33 | 32 |
| 34 @Native("B2") | 33 @Native("B2") |
| 35 class B2 extends A2 { | 34 class B2 extends A2 { |
| 36 foo([z=1000]) native; | 35 foo([z = 1000]) native ; |
| 37 } | 36 } |
| 38 | 37 |
| 39 makeA2() native; | 38 makeA2() native ; |
| 40 makeB2() native; | 39 makeB2() native ; |
| 41 | 40 |
| 42 void setup() native """ | 41 void setup() native """ |
| 43 // This code is all inside 'setup' and so not accesible from the global scope. | 42 // This code is all inside 'setup' and so not accesible from the global scope. |
| 44 function inherits(child, parent) { | 43 function inherits(child, parent) { |
| 45 if (child.prototype.__proto__) { | 44 if (child.prototype.__proto__) { |
| 46 child.prototype.__proto__ = parent.prototype; | 45 child.prototype.__proto__ = parent.prototype; |
| 47 } else { | 46 } else { |
| 48 function tmp() {}; | 47 function tmp() {}; |
| 49 tmp.prototype = parent.prototype; | 48 tmp.prototype = parent.prototype; |
| 50 child.prototype = new tmp(); | 49 child.prototype = new tmp(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 63 function A2(){} | 62 function A2(){} |
| 64 function B2(){} | 63 function B2(){} |
| 65 inherits(B2, A2); | 64 inherits(B2, A2); |
| 66 A2.prototype.foo = function(a){return a + 10000;} | 65 A2.prototype.foo = function(a){return a + 10000;} |
| 67 B2.prototype.foo = function(z){return z + 20000;} | 66 B2.prototype.foo = function(z){return z + 20000;} |
| 68 | 67 |
| 69 makeA2 = function(){return new A2}; | 68 makeA2 = function(){return new A2}; |
| 70 makeB2 = function(){return new B2}; | 69 makeB2 = function(){return new B2}; |
| 71 """; | 70 """; |
| 72 | 71 |
| 73 | |
| 74 main() { | 72 main() { |
| 75 setup(); | 73 setup(); |
| 76 | 74 |
| 77 var a1 = makeA1(); | 75 var a1 = makeA1(); |
| 78 var b1 = makeB1(); | 76 var b1 = makeB1(); |
| 79 Expect.equals(100, a1.foo()); | 77 Expect.equals(100, a1.foo()); |
| 80 Expect.equals(200, b1.foo()); | 78 Expect.equals(200, b1.foo()); |
| 81 | 79 |
| 82 var a2 = makeA2(); | 80 var a2 = makeA2(); |
| 83 var b2 = makeB2(); | 81 var b2 = makeB2(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 99 caught = false; | 97 caught = false; |
| 100 try { | 98 try { |
| 101 var x = 123; | 99 var x = 123; |
| 102 x.foo(20); | 100 x.foo(20); |
| 103 } catch (ex) { | 101 } catch (ex) { |
| 104 caught = true; | 102 caught = true; |
| 105 Expect.isTrue(ex is NoSuchMethodError); | 103 Expect.isTrue(ex is NoSuchMethodError); |
| 106 } | 104 } |
| 107 Expect.isTrue(caught, "x.foo(20) should throw"); | 105 Expect.isTrue(caught, "x.foo(20) should throw"); |
| 108 } | 106 } |
| OLD | NEW |