OLD | NEW |
| (Empty) |
1 // Copyright (c) 2012, 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 typedef void MyFunctionType(); | |
6 | |
7 class A native "*A" { | |
8 setClosure(MyFunctionType f) native; | |
9 check(MyFunctionType f) native; | |
10 invoke() native; | |
11 } | |
12 | |
13 makeA() native { return new A(); } | |
14 | |
15 void setup() native """ | |
16 function A() {} | |
17 A.prototype.setClosure = function(f) { this.f = f; }; | |
18 A.prototype.check = function(f) { return this.f === f; }; | |
19 A.prototype.invoke = function() { return this.f(); }; | |
20 makeA = function(){return new A;}; | |
21 """; | |
22 | |
23 var staticClosure; | |
24 staticMethod() => 42; | |
25 | |
26 class B { | |
27 var instanceClosure; | |
28 instanceMethod() => 43; | |
29 } | |
30 | |
31 checkUntyped(a, closure) { | |
32 a.setClosure(closure); | |
33 Expect.isTrue(a.check(closure)); | |
34 Expect.equals(closure(), a.invoke()); | |
35 } | |
36 | |
37 checkTyped(A a, MyFunctionType closure) { | |
38 a.setClosure(closure); | |
39 Expect.isTrue(a.check(closure)); | |
40 Expect.equals(closure(), a.invoke()); | |
41 } | |
42 | |
43 main() { | |
44 setup(); | |
45 | |
46 staticClosure = () => 44; | |
47 B b = new B(); | |
48 b.instanceClosure = () => 45; | |
49 | |
50 closureStatement() => 46; | |
51 var closureExpression = () => 47; | |
52 | |
53 checkUntyped(makeA(), staticClosure); | |
54 checkTyped(makeA(), staticClosure); | |
55 | |
56 checkUntyped(makeA(), staticMethod); | |
57 checkTyped(makeA(), staticMethod); | |
58 | |
59 checkUntyped(makeA(), b.instanceClosure); | |
60 checkTyped(makeA(), b.instanceClosure); | |
61 | |
62 checkUntyped(makeA(), b.instanceMethod); | |
63 checkTyped(makeA(), b.instanceMethod); | |
64 | |
65 checkUntyped(makeA(), closureStatement); | |
66 checkTyped(makeA(), closureStatement); | |
67 | |
68 checkUntyped(makeA(), closureExpression); | |
69 checkTyped(makeA(), closureExpression); | |
70 } | |
OLD | NEW |