| 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 "native_testing.dart"; | 5 import "native_testing.dart"; |
| 6 | 6 |
| 7 // Test to see if resolving a hidden native class's method interferes with | 7 // Test to see if resolving a hidden native class's method interferes with |
| 8 // subsequent resolving the subclass's method. This might happen if the | 8 // subsequent resolving the subclass's method. This might happen if the |
| 9 // superclass caches the method in the prototype, so shadowing the dispatcher | 9 // superclass caches the method in the prototype, so shadowing the dispatcher |
| 10 // stored on Object.prototype. | 10 // stored on Object.prototype. |
| 11 | 11 |
| 12 // Version 1: It might be possible to call foo directly. | 12 // Version 1: It might be possible to call foo directly. |
| 13 @Native("A1") | 13 @Native("A1") |
| 14 class A1 { | 14 class A1 { |
| 15 foo() native ; | 15 foo() native; |
| 16 } | 16 } |
| 17 | 17 |
| 18 @Native("B1") | 18 @Native("B1") |
| 19 class B1 extends A1 { | 19 class B1 extends A1 { |
| 20 foo() native ; | 20 foo() native; |
| 21 } | 21 } |
| 22 | 22 |
| 23 makeA1() native ; | 23 makeA1() native; |
| 24 makeB1() native ; | 24 makeB1() native; |
| 25 | 25 |
| 26 // Version 2: foo needs some kind of trampoline. | 26 // Version 2: foo needs some kind of trampoline. |
| 27 @Native("A2") | 27 @Native("A2") |
| 28 class A2 { | 28 class A2 { |
| 29 foo([a = 99]) native ; | 29 foo([a = 99]) native; |
| 30 } | 30 } |
| 31 | 31 |
| 32 @Native("B2") | 32 @Native("B2") |
| 33 class B2 extends A2 { | 33 class B2 extends A2 { |
| 34 foo([z = 1000]) native ; | 34 foo([z = 1000]) native; |
| 35 } | 35 } |
| 36 | 36 |
| 37 makeA2() native ; | 37 makeA2() native; |
| 38 makeB2() native ; | 38 makeB2() native; |
| 39 | 39 |
| 40 void setup() native """ | 40 void setup() native """ |
| 41 // This code is all inside 'setup' and so not accesible from the global scope. | 41 // This code is all inside 'setup' and so not accesible from the global scope. |
| 42 function inherits(child, parent) { | 42 function inherits(child, parent) { |
| 43 if (child.prototype.__proto__) { | 43 if (child.prototype.__proto__) { |
| 44 child.prototype.__proto__ = parent.prototype; | 44 child.prototype.__proto__ = parent.prototype; |
| 45 } else { | 45 } else { |
| 46 function tmp() {}; | 46 function tmp() {}; |
| 47 tmp.prototype = parent.prototype; | 47 tmp.prototype = parent.prototype; |
| 48 child.prototype = new tmp(); | 48 child.prototype = new tmp(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 caught = false; | 102 caught = false; |
| 103 try { | 103 try { |
| 104 var x = 123; | 104 var x = 123; |
| 105 x.foo(20); | 105 x.foo(20); |
| 106 } catch (ex) { | 106 } catch (ex) { |
| 107 caught = true; | 107 caught = true; |
| 108 Expect.isTrue(ex is NoSuchMethodError); | 108 Expect.isTrue(ex is NoSuchMethodError); |
| 109 } | 109 } |
| 110 Expect.isTrue(caught, "x.foo(20) should throw"); | 110 Expect.isTrue(caught, "x.foo(20) should throw"); |
| 111 } | 111 } |
| OLD | NEW |