Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: tests/language/src/IsFunctionTest.dart

Issue 9666006: Support for "a is Function". (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/language/src/FunctionGetterTest.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 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 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 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; 5 var staticClosure;
24 staticMethod() => 42; 6 staticMethod() => 42;
25 7
26 class B { 8 class B {
27 var instanceClosure; 9 var instanceClosure;
10 var nullField;
28 instanceMethod() => 43; 11 instanceMethod() => 43;
29 } 12 }
30 13
31 checkUntyped(a, closure) { 14 checkUntyped(closure) {
32 a.setClosure(closure); 15 Expect.isTrue(closure is Function);
33 Expect.isTrue(a.check(closure));
34 Expect.equals(closure(), a.invoke());
35 } 16 }
36 17
37 checkTyped(A a, MyFunctionType closure) { 18 checkTyped(int closure()) {
38 a.setClosure(closure); 19 Expect.isTrue(closure is Function);
39 Expect.isTrue(a.check(closure)); 20 }
40 Expect.equals(closure(), a.invoke()); 21
22 checkTypedNull(int closure()) {
23 Expect.isFalse(closure is Function);
24 }
25
26 checkUntypedNull(closure) {
27 Expect.isFalse(closure is Function);
41 } 28 }
42 29
43 main() { 30 main() {
44 setup();
45
46 staticClosure = () => 44; 31 staticClosure = () => 44;
47 B b = new B(); 32 B b = new B();
48 b.instanceClosure = () => 45; 33 b.instanceClosure = () => 45;
49 34
50 closureStatement() => 46; 35 closureStatement() => 46;
51 var closureExpression = () => 47; 36 var closureExpression = () => 47;
52 37
53 checkUntyped(makeA(), staticClosure); 38 checkUntyped(staticClosure);
54 checkTyped(makeA(), staticClosure); 39 checkTyped(staticClosure);
55 40
56 checkUntyped(makeA(), staticMethod); 41 checkUntyped(staticMethod);
57 checkTyped(makeA(), staticMethod); 42 checkTyped(staticMethod);
58 43
59 checkUntyped(makeA(), b.instanceClosure); 44 checkUntyped(b.instanceClosure);
60 checkTyped(makeA(), b.instanceClosure); 45 checkTyped(b.instanceClosure);
61 46
62 checkUntyped(makeA(), b.instanceMethod); 47 checkUntyped(b.instanceMethod);
63 checkTyped(makeA(), b.instanceMethod); 48 checkTyped(b.instanceMethod);
64 49
65 checkUntyped(makeA(), closureStatement); 50 checkUntyped(closureStatement);
66 checkTyped(makeA(), closureStatement); 51 checkTyped(closureStatement);
67 52
68 checkUntyped(makeA(), closureExpression); 53 checkUntyped(closureExpression);
69 checkTyped(makeA(), closureExpression); 54 checkTyped(closureExpression);
55
56 checkTypedNull(b.nullField);
57 checkUntypedNull(b.nullField);
70 } 58 }
OLDNEW
« no previous file with comments | « tests/language/src/FunctionGetterTest.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698