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

Unified Diff: lib/src/codegen/js_codegen.dart

Issue 1132113003: fixes #177, FunctionDeclarationStatement and closing over `this` (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/runtime/dart/isolate.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/codegen/js_codegen.dart
diff --git a/lib/src/codegen/js_codegen.dart b/lib/src/codegen/js_codegen.dart
index 61d12301f60533fef70b99ff271b5a284acf629d..264cccc42e23de10153334825d9e0422fa09896f 100644
--- a/lib/src/codegen/js_codegen.dart
+++ b/lib/src/codegen/js_codegen.dart
@@ -1068,7 +1068,9 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
var params = _visit(node.parameters);
if (params == null) params = [];
- if (node.parent is FunctionDeclaration) {
+ var parent = node.parent;
+ if (parent is FunctionDeclaration &&
Jennifer Messerly 2015/05/08 21:49:38 AST is a little wacky here... parent is a Function
+ parent.parent is! FunctionDeclarationStatement) {
return new JS.Fun(params, _visit(node.body));
} else {
String code;
@@ -1093,10 +1095,13 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
return js.comment('Unimplemented function get/set statement: $node');
}
+ // Use an => function to bind this.
+ // Technically we only need to do this if the function actually closes over
+ // `this`, but it seems harmless enough to just do it always.
var name = new JS.Identifier(func.name.name);
return new JS.Block([
js.comment("// Function ${func.name.name}: ${func.element.type}\n"),
- new JS.FunctionDeclaration(name, _visit(func.functionExpression))
+ js.statement('let # = #;', [name, _visit(func.functionExpression)])
]);
}
« no previous file with comments | « lib/runtime/dart/isolate.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698