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

Side by Side Diff: pkg/kernel/testcases/closures/uncaptured_for_in_loop.dart.expect

Issue 2778223002: Add primitive to create closures and use it for closure conversion (Closed)
Patch Set: Skip context param in closure type construction, rather than remove it Created 3 years, 8 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
OLDNEW
1 library; 1 library;
2 import self as self; 2 import self as self;
3 import "dart:core" as core; 3 import "dart:core" as core;
4 4
5 class Closure#main#function extends core::Object implements core::Function {
6 field core::String note = "This is temporary. The VM doesn't need closure clas ses.";
7 field Vector context;
8 constructor •(final Vector context) → dynamic
9 : self::Closure#main#function::context = context
10 ;
11 method call() → dynamic {
12 "This is a temporary solution. In the VM, this will become an additional par ameter.";
13 final Vector #contextParameter = this.{self::Closure#main#function::context} ;
14 return #contextParameter[1];
15 }
16 }
17 static const field dynamic numbers = const <core::int>[0, 1, 2, 3, 4, 5, 6, 7, 8 , 9]; 5 static const field dynamic numbers = const <core::int>[0, 1, 2, 3, 4, 5, 6, 7, 8 , 9];
18 static method main() → dynamic { 6 static method main() → dynamic {
19 dynamic closures = <dynamic>[]; 7 dynamic closures = <dynamic>[];
20 for (core::int i in self::numbers) { 8 for (core::int i in self::numbers) {
21 final Vector #context = MakeVector(2); 9 final Vector #context = MakeVector(2);
22 #context[1] = i; 10 #context[1] = i;
23 closures.add(new self::Closure#main#function::•(#context)); 11 closures.add(MakeClosure<() → dynamic>(self::closure#main#function, #context ));
24 } 12 }
25 core::int sum = 0; 13 core::int sum = 0;
26 for (core::Function f in closures) { 14 for (core::Function f in closures) {
27 sum = sum.+(f.call()); 15 sum = sum.+(f.call());
28 } 16 }
29 core::int expectedSum = self::numbers.length.-(1).*(self::numbers.length).~/(2 ); 17 core::int expectedSum = self::numbers.length.-(1).*(self::numbers.length).~/(2 );
30 if(!expectedSum.==(sum)) { 18 if(!expectedSum.==(sum)) {
31 throw core::Exception::•("Unexpected sum = ${sum} != ${expectedSum}"); 19 throw core::Exception::•("Unexpected sum = ${sum} != ${expectedSum}");
32 } 20 }
33 } 21 }
22 static method closure#main#function(Vector #contextParameter) → dynamic {
23 return #contextParameter[1];
24 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698