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 the feature where the native string declares the native method's name. | |
6 | |
7 class A native "*A" { | |
8 int foo() native 'fooA'; | |
9 } | |
10 | |
11 class B extends A native "*B" { | |
12 int foo() native 'fooB'; | |
13 } | |
14 | |
15 makeA() native; | |
16 makeB() native; | |
17 | |
18 void setup() native """ | |
19 // This code is all inside 'setup' and so not accesible from the global scope. | |
20 function inherits(child, parent) { | |
21 if (child.prototype.__proto__) { | |
22 child.prototype.__proto__ = parent.prototype; | |
23 } else { | |
24 function tmp() {}; | |
25 tmp.prototype = parent.prototype; | |
26 child.prototype = new tmp(); | |
27 child.prototype.constructor = child; | |
28 } | |
29 } | |
30 function A(){} | |
31 A.prototype.fooA = function(){return 100;}; | |
32 function B(){} | |
33 inherits(B, A); | |
34 B.prototype.fooB = function(){return 200;}; | |
35 | |
36 makeA = function(){return new A}; | |
37 makeB = function(){return new B}; | |
38 """; | |
39 | |
40 testDynamic() { | |
41 var things = [makeA(), makeB()]; | |
42 var a = things[0]; | |
43 var b = things[1]; | |
44 | |
45 Expect.equals(100, a.foo()); | |
46 Expect.equals(200, b.foo()); | |
47 | |
48 expectNoSuchMethod((){ a.fooA(); }, 'fooA should be invisible on A'); | |
49 expectNoSuchMethod((){ b.fooA(); }, 'fooA should be invisible on B'); | |
50 | |
51 expectNoSuchMethod((){ a.fooB(); }, 'fooB should be absent on A'); | |
52 expectNoSuchMethod((){ b.fooB(); }, 'fooA should be invisible on B'); | |
53 } | |
54 | |
55 testTyped() { | |
56 A a = makeA(); | |
57 B b = makeB(); | |
58 | |
59 Expect.equals(100, a.foo()); | |
60 Expect.equals(200, b.foo()); | |
61 } | |
62 | |
63 main() { | |
64 setup(); | |
65 | |
66 testDynamic(); | |
67 testTyped(); | |
68 } | |
69 | |
70 expectNoSuchMethod(action, note) { | |
71 bool caught = false; | |
72 try { | |
73 action(); | |
74 } catch (var ex) { | |
75 caught = true; | |
76 Expect.isTrue(ex is NoSuchMethodException, note); | |
77 } | |
78 Expect.isTrue(caught, note); | |
79 } | |
OLD | NEW |