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

Unified Diff: tests/compiler/dart2js/closure_tracer_test.dart

Issue 112103007: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/inferrer/type_graph_nodes.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/compiler/dart2js/closure_tracer_test.dart
===================================================================
--- tests/compiler/dart2js/closure_tracer_test.dart (revision 0)
+++ tests/compiler/dart2js/closure_tracer_test.dart (revision 0)
@@ -0,0 +1,110 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+import 'package:expect/expect.dart';
+import "package:async_helper/async_helper.dart";
+
+import 'compiler_helper.dart';
+import 'parser_helper.dart';
+
+const String TEST = '''
+testFunctionStatement() {
+ var res;
+ closure(a) => res = a;
+ closure(42);
+ return res;
+}
+
+testFunctionExpression() {
+ var res;
+ var closure = (a) => res = a;
+ closure(42);
+ return res;
+}
+
+var staticField;
+
+testStoredInStatic() {
+ var res;
+ closure(a) => res = a;
+ staticField = closure;
+ staticField(42);
+ return res;
+}
+
+class A {
+ var field;
+ A(this.field);
+}
+
+testStoredInInstance() {
+ var res;
+ closure(a) => res = a;
+ var a = new A(closure);
+ a.field(42);
+ return res;
+}
+
+foo(closure) {
+ closure(42);
+}
+
+testPassedInParameter() {
+ var res;
+ closure(a) => res = a;
+ foo(closure);
+ return res;
+}
+
+var topLevel1;
+foo2(a) => topLevel1 = a;
+testStaticClosure1() {
+ var a = foo2;
+ a(42);
+ return topLevel1;
+}
+
+var topLevel2;
+bar(a) => topLevel2 = a;
+testStaticClosure2() {
+ var a = bar;
+ a(42);
+ var b = bar;
+ b(2.5);
+ return topLevel2;
+}
+
+main() {
+ testFunctionStatement();
+ testFunctionExpression();
+ testStoredInStatic();
+ testStoredInInstance();
+ testPassedInParameter();
+ testStaticClosure1();
+ testStaticClosure2();
kasperl 2013/12/19 13:33:34 Add test for static method on class too?
ngeoffray 2013/12/19 13:39:26 Done.
+}
+''';
+
+void main() {
+ Uri uri = new Uri(scheme: 'source');
+ var compiler = compilerFor(TEST, uri);
+ asyncTest(() => compiler.runCompiler(uri).then((_) {
+ var typesTask = compiler.typesTask;
+ var typesInferrer = typesTask.typesInferrer;
+
+ checkType(String name, type) {
+ var element = findElement(compiler, name);
+ var mask = typesInferrer.getReturnTypeOfElement(element);
+ Expect.equals(type.nullable(), mask.simplify(compiler), name);
+ }
+
+ checkType('testFunctionStatement', typesTask.uint31Type);
+ checkType('testFunctionExpression', typesTask.uint31Type);
+ checkType('testStoredInInstance', typesTask.uint31Type);
+ checkType('testStoredInStatic', typesTask.uint31Type);
+ checkType('testPassedInParameter', typesTask.uint31Type);
+ checkType('testStaticClosure1', typesTask.uint31Type);
+ checkType('testStaticClosure2', typesTask.numType);
+ }));
+}
« no previous file with comments | « sdk/lib/_internal/compiler/implementation/inferrer/type_graph_nodes.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698