| 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 to noSuchMethod | 5 // Test to see if resolving a hidden native class's method to noSuchMethod |
| 6 // interferes with subsequent resolving of the method. This might happen if the | 6 // interferes with subsequent resolving of the method. This might happen if the |
| 7 // noSuchMethod is cached on Object.prototype. | 7 // noSuchMethod is cached on Object.prototype. |
| 8 | 8 |
| 9 class A1 native "*A1" { | 9 @native("*A1") |
| 10 class A1 { |
| 10 } | 11 } |
| 11 | 12 |
| 12 class B1 extends A1 native "*B1" { | 13 @native("*B1") |
| 14 class B1 extends A1 { |
| 13 } | 15 } |
| 14 | 16 |
| 15 makeA1() native; | 17 @native makeA1(); |
| 16 makeB1() native; | 18 @native makeB1(); |
| 17 | 19 |
| 18 | 20 |
| 19 class A2 native "*A2" { | 21 @native("*A2") |
| 20 foo([a=99]) native; | 22 class A2 { |
| 23 @native foo([a=99]); |
| 21 } | 24 } |
| 22 | 25 |
| 23 class B2 extends A2 native "*B2" { | 26 @native("*B2") |
| 27 class B2 extends A2 { |
| 24 } | 28 } |
| 25 | 29 |
| 26 makeA2() native; | 30 @native makeA2(); |
| 27 makeB2() native; | 31 @native makeB2(); |
| 28 | 32 |
| 29 makeObject() native; | 33 @native makeObject(); |
| 30 | 34 |
| 31 void setup() native """ | 35 @native(""" |
| 32 // 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. |
| 33 function inherits(child, parent) { | 37 function inherits(child, parent) { |
| 34 if (child.prototype.__proto__) { | 38 if (child.prototype.__proto__) { |
| 35 child.prototype.__proto__ = parent.prototype; | 39 child.prototype.__proto__ = parent.prototype; |
| 36 } else { | 40 } else { |
| 37 function tmp() {}; | 41 function tmp() {}; |
| 38 tmp.prototype = parent.prototype; | 42 tmp.prototype = parent.prototype; |
| 39 child.prototype = new tmp(); | 43 child.prototype = new tmp(); |
| 40 child.prototype.constructor = child; | 44 child.prototype.constructor = child; |
| 41 } | 45 } |
| 42 } | 46 } |
| 43 function A1(){} | 47 function A1(){} |
| 44 function B1(){} | 48 function B1(){} |
| 45 inherits(B1, A1); | 49 inherits(B1, A1); |
| 46 | 50 |
| 47 makeA1 = function(){return new A1}; | 51 makeA1 = function(){return new A1}; |
| 48 makeB1 = function(){return new B1}; | 52 makeB1 = function(){return new B1}; |
| 49 | 53 |
| 50 function A2(){} | 54 function A2(){} |
| 51 function B2(){} | 55 function B2(){} |
| 52 inherits(B2, A2); | 56 inherits(B2, A2); |
| 53 A2.prototype.foo = function(a){return 'A2.foo(' + a + ')';} | 57 A2.prototype.foo = function(a){return 'A2.foo(' + a + ')';} |
| 54 | 58 |
| 55 makeA2 = function(){return new A2}; | 59 makeA2 = function(){return new A2}; |
| 56 makeB2 = function(){return new B2}; | 60 makeB2 = function(){return new B2}; |
| 57 | 61 |
| 58 makeObject = function(){return new Object}; | 62 makeObject = function(){return new Object}; |
| 59 """; | 63 """) |
| 64 void setup(); |
| 60 | 65 |
| 61 | 66 |
| 62 main() { | 67 main() { |
| 63 setup(); | 68 setup(); |
| 64 | 69 |
| 65 var a1 = makeA1(); | 70 var a1 = makeA1(); |
| 66 var b1 = makeB1(); | 71 var b1 = makeB1(); |
| 67 var ob = makeObject(); | 72 var ob = makeObject(); |
| 68 | 73 |
| 69 // Does calling missing methods in one tree of inheritance forest affect other | 74 // Does calling missing methods in one tree of inheritance forest affect other |
| (...skipping 18 matching lines...) Expand all Loading... |
| 88 expectNoSuchMethod(action, note) { | 93 expectNoSuchMethod(action, note) { |
| 89 bool caught = false; | 94 bool caught = false; |
| 90 try { | 95 try { |
| 91 action(); | 96 action(); |
| 92 } catch (var ex) { | 97 } catch (var ex) { |
| 93 caught = true; | 98 caught = true; |
| 94 Expect.isTrue(ex is NoSuchMethodException, note); | 99 Expect.isTrue(ex is NoSuchMethodException, note); |
| 95 } | 100 } |
| 96 Expect.isTrue(caught, note); | 101 Expect.isTrue(caught, note); |
| 97 } | 102 } |
| OLD | NEW |