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

Side by Side Diff: tests/compiler/dart2js/closure_tracer_test.dart

Issue 110383008: Re-apply: Trace static tear-off closures. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years 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
OLDNEW
(Empty)
1 // Copyright (c) 2013, 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 import 'package:expect/expect.dart';
6 import "package:async_helper/async_helper.dart";
7
8 import 'compiler_helper.dart';
9 import 'parser_helper.dart';
10
11 const String TEST = '''
12 testFunctionStatement() {
13 var res;
14 closure(a) => res = a;
15 closure(42);
16 return res;
17 }
18
19 testFunctionExpression() {
20 var res;
21 var closure = (a) => res = a;
22 closure(42);
23 return res;
24 }
25
26 var staticField;
27
28 testStoredInStatic() {
29 var res;
30 closure(a) => res = a;
31 staticField = closure;
32 staticField(42);
33 return res;
34 }
35
36 class A {
37 var field;
38 A(this.field);
39 static foo(a) => topLevel3 = a;
40 }
41
42 testStoredInInstance() {
43 var res;
44 closure(a) => res = a;
45 var a = new A(closure);
46 a.field(42);
47 return res;
48 }
49
50 foo(closure) {
51 closure(42);
52 }
53
54 testPassedInParameter() {
55 var res;
56 closure(a) => res = a;
57 foo(closure);
58 return res;
59 }
60
61 var topLevel1;
62 foo2(a) => topLevel1 = a;
63 testStaticClosure1() {
64 var a = foo2;
65 a(42);
66 return topLevel1;
67 }
68
69 var topLevel2;
70 bar(a) => topLevel2 = a;
71 testStaticClosure2() {
72 var a = bar;
73 a(42);
74 var b = bar;
75 b(2.5);
76 return topLevel2;
77 }
78
79 var topLevel3;
80 testStaticClosure3() {
81 var a = A.foo;
82 a(42);
83 return topLevel3;
84 }
85
86 var topLevel4;
87 testStaticClosure4Helper(a) => topLevel4 = a;
88 testStaticClosure4() {
89 var a = testStaticClosure4Helper;
90 // Test calling the static after tearing it off.
91 testStaticClosure4Helper(2.5);
92 a(42);
93 return topLevel4;
94 }
95
96 main() {
97 testFunctionStatement();
98 testFunctionExpression();
99 testStoredInStatic();
100 testStoredInInstance();
101 testPassedInParameter();
102 testStaticClosure1();
103 testStaticClosure2();
104 testStaticClosure3();
105 testStaticClosure4();
106 }
107 ''';
108
109 void main() {
110 Uri uri = new Uri(scheme: 'source');
111 var compiler = compilerFor(TEST, uri);
112 asyncTest(() => compiler.runCompiler(uri).then((_) {
113 var typesTask = compiler.typesTask;
114 var typesInferrer = typesTask.typesInferrer;
115
116 checkType(String name, type) {
117 var element = findElement(compiler, name);
118 var mask = typesInferrer.getReturnTypeOfElement(element);
119 Expect.equals(type.nullable(), mask.simplify(compiler), name);
120 }
121
122 checkType('testFunctionStatement', typesTask.uint31Type);
123 checkType('testFunctionExpression', typesTask.uint31Type);
124 checkType('testStoredInInstance', typesTask.uint31Type);
125 checkType('testStoredInStatic', typesTask.uint31Type);
126 checkType('testPassedInParameter', typesTask.uint31Type);
127 checkType('testStaticClosure1', typesTask.uint31Type);
128 checkType('testStaticClosure2', typesTask.numType);
129 checkType('testStaticClosure3', typesTask.uint31Type);
130 checkType('testStaticClosure4', typesTask.numType);
131 }));
132 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698