| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 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 | |
| 7 // noSuchMethod is cached on Object.prototype. | |
| 8 | |
| 9 import "package:expect/expect.dart"; | |
| 10 import 'native_metadata.dart'; | |
| 11 | |
| 12 @Native("*A1") | |
| 13 class A1 { | |
| 14 } | |
| 15 | |
| 16 @Native("*B1") | |
| 17 class B1 extends A1 { | |
| 18 } | |
| 19 | |
| 20 @native makeA1(); | |
| 21 @native makeB1(); | |
| 22 | |
| 23 | |
| 24 @Native("*A2") | |
| 25 class A2 { | |
| 26 @native foo([a=99]); | |
| 27 } | |
| 28 | |
| 29 @Native("*B2") | |
| 30 class B2 extends A2 { | |
| 31 } | |
| 32 | |
| 33 @native makeA2(); | |
| 34 @native makeB2(); | |
| 35 | |
| 36 @native makeObject(); | |
| 37 | |
| 38 @Native(""" | |
| 39 // This code is all inside 'setup' and so not accesible from the global scope. | |
| 40 function inherits(child, parent) { | |
| 41 if (child.prototype.__proto__) { | |
| 42 child.prototype.__proto__ = parent.prototype; | |
| 43 } else { | |
| 44 function tmp() {}; | |
| 45 tmp.prototype = parent.prototype; | |
| 46 child.prototype = new tmp(); | |
| 47 child.prototype.constructor = child; | |
| 48 } | |
| 49 } | |
| 50 function A1(){} | |
| 51 function B1(){} | |
| 52 inherits(B1, A1); | |
| 53 | |
| 54 makeA1 = function(){return new A1}; | |
| 55 makeB1 = function(){return new B1}; | |
| 56 | |
| 57 function A2(){} | |
| 58 function B2(){} | |
| 59 inherits(B2, A2); | |
| 60 A2.prototype.foo = function(a){return 'A2.foo(' + a + ')';} | |
| 61 | |
| 62 makeA2 = function(){return new A2}; | |
| 63 makeB2 = function(){return new B2}; | |
| 64 | |
| 65 makeObject = function(){return new Object}; | |
| 66 """) | |
| 67 void setup(); | |
| 68 | |
| 69 | |
| 70 main() { | |
| 71 setup(); | |
| 72 | |
| 73 var a1 = makeA1(); | |
| 74 var b1 = makeB1(); | |
| 75 var ob = makeObject(); | |
| 76 | |
| 77 // Does calling missing methods in one tree of inheritance forest affect other | |
| 78 // trees? | |
| 79 expectNoSuchMethod(() => b1.foo(), 'b1.foo()'); | |
| 80 expectNoSuchMethod(() => a1.foo(), 'a1.foo()'); | |
| 81 expectNoSuchMethod(() => ob.foo(), 'ob.foo()'); | |
| 82 | |
| 83 var a2 = makeA2(); | |
| 84 var b2 = makeB2(); | |
| 85 | |
| 86 Expect.equals('A2.foo(99)', a2.foo()); | |
| 87 Expect.equals('A2.foo(99)', b2.foo()); | |
| 88 Expect.equals('A2.foo(1)', a2.foo(1)); | |
| 89 Expect.equals('A2.foo(2)', b2.foo(2)); | |
| 90 | |
| 91 | |
| 92 expectNoSuchMethod(() => b1.foo(3), 'b1.foo(3)'); | |
| 93 expectNoSuchMethod(() => a1.foo(4), 'a1.foo(4)'); | |
| 94 } | |
| 95 | |
| 96 expectNoSuchMethod(action, note) { | |
| 97 bool caught = false; | |
| 98 try { | |
| 99 action(); | |
| 100 } catch (ex) { | |
| 101 caught = true; | |
| 102 Expect.isTrue(ex is NoSuchMethodError, note); | |
| 103 } | |
| 104 Expect.isTrue(caught, note); | |
| 105 } | |
| OLD | NEW |