| 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 import 'native_metadata.dart'; |
| 11 |
| 10 // Version 1: It might be possible to call foo directly. | 12 // Version 1: It might be possible to call foo directly. |
| 11 @native("*A1") | 13 @Native("*A1") |
| 12 class A1 { | 14 class A1 { |
| 13 @native foo(); | 15 @native foo(); |
| 14 } | 16 } |
| 15 | 17 |
| 16 @native("*B1") | 18 @Native("*B1") |
| 17 class B1 extends A1 { | 19 class B1 extends A1 { |
| 18 @native foo(); | 20 @native foo(); |
| 19 } | 21 } |
| 20 | 22 |
| 21 @native makeA1(); | 23 @native makeA1(); |
| 22 @native makeB1(); | 24 @native makeB1(); |
| 23 | 25 |
| 24 | 26 |
| 25 // Version 2: foo needs some kind of trampoline. | 27 // Version 2: foo needs some kind of trampoline. |
| 26 @native("*A2") | 28 @Native("*A2") |
| 27 class A2 { | 29 class A2 { |
| 28 @native foo([a=99]); | 30 @native foo([a=99]); |
| 29 } | 31 } |
| 30 | 32 |
| 31 @native("*B2") | 33 @Native("*B2") |
| 32 class B2 extends A2 { | 34 class B2 extends A2 { |
| 33 @native foo([z=1000]); | 35 @native foo([z=1000]); |
| 34 } | 36 } |
| 35 | 37 |
| 36 @native makeA2(); | 38 @native makeA2(); |
| 37 @native makeB2(); | 39 @native makeB2(); |
| 38 | 40 |
| 39 @native(""" | 41 @Native(""" |
| 40 // 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. |
| 41 function inherits(child, parent) { | 43 function inherits(child, parent) { |
| 42 if (child.prototype.__proto__) { | 44 if (child.prototype.__proto__) { |
| 43 child.prototype.__proto__ = parent.prototype; | 45 child.prototype.__proto__ = parent.prototype; |
| 44 } else { | 46 } else { |
| 45 function tmp() {}; | 47 function tmp() {}; |
| 46 tmp.prototype = parent.prototype; | 48 tmp.prototype = parent.prototype; |
| 47 child.prototype = new tmp(); | 49 child.prototype = new tmp(); |
| 48 child.prototype.constructor = child; | 50 child.prototype.constructor = child; |
| 49 } | 51 } |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 caught = false; | 99 caught = false; |
| 98 try { | 100 try { |
| 99 var x = 123; | 101 var x = 123; |
| 100 x.foo(20); | 102 x.foo(20); |
| 101 } catch (ex) { | 103 } catch (ex) { |
| 102 caught = true; | 104 caught = true; |
| 103 Expect.isTrue(ex is NoSuchMethodError); | 105 Expect.isTrue(ex is NoSuchMethodError); |
| 104 } | 106 } |
| 105 Expect.isTrue(caught, "x.foo(20) should throw"); | 107 Expect.isTrue(caught, "x.foo(20) should throw"); |
| 106 } | 108 } |
| OLD | NEW |