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

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

Issue 1052693004: move => bind this workaround to js_ast (Closed) Base URL: git@github.com:dart-lang/dev_compiler.git@master
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/runtime/dart/isolate.js ('k') | lib/src/js/nodes.dart » ('j') | 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 d1cd2a15ac8f67b9e600fa1083e731704f33118a..2e33710b01faa99d714007543139dd0d8c5ade4c 100644
--- a/lib/src/codegen/js_codegen.dart
+++ b/lib/src/codegen/js_codegen.dart
@@ -913,8 +913,6 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
if (node.parent is FunctionDeclaration) {
return new JS.Fun(params, _visit(node.body));
} else {
- var bindThis = _maybeBindThis(node.body);
-
String code;
AstNode body;
var nodeBody = node.body;
@@ -925,7 +923,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
code = '(#) => { #; }';
body = nodeBody;
}
- return js.call('($code)$bindThis', [params, _visit(body)]);
+ return js.call(code, [params, _visit(body)]);
}
}
@@ -1531,7 +1529,6 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
bool _isNull(Expression expr) => expr is NullLiteral;
- // TODO(jmesserly, vsm): Refactor this logic.
SimpleIdentifier _createTemporary(String name, DartType type) {
// We use an invalid source location to signal that this is a temporary.
// See [_isTemporary].
@@ -1561,13 +1558,8 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
increment.staticType = type;
var write = _emitAssignment(expr, increment);
- var bindThis = _maybeBindThis(expr);
- return js.call("((#) => (#, #))$bindThis(#)", [
- _visit(tmp),
- write,
- _visit(tmp),
- _visit(expr)
- ]);
+ return js.call(
+ "((#) => (#, #))(#)", [_visit(tmp), write, _visit(tmp), _visit(expr)]);
}
@override
@@ -1662,8 +1654,6 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
// In the general case we need to capture the target expression into
// a temporary. This uses a lambda to get a temporary scope, and it also
// remains valid in an expression context.
- // TODO(jmesserly): need a better way to handle temps.
- // TODO(jmesserly): special case for parent is ExpressionStatement?
_cascadeTarget = _createTemporary('_', node.target.staticType);
var body = _visitList(node.cascadeSections);
@@ -1671,8 +1661,7 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
body.add(js.statement('return #;', _visit(_cascadeTarget)));
}
- var bindThis = _maybeBindThis(node.cascadeSections);
- result = js.call('((#) => { # })$bindThis(#)', [
+ result = js.call('((#) => { # })(#)', [
_visit(_cascadeTarget),
body,
_visit(node.target)
@@ -2177,14 +2166,6 @@ class JSCodegenVisitor extends GeneralizingAstVisitor with ConversionVisitor {
return new JS.Identifier(jsLibraryName(library));
}
- String _maybeBindThis(node) {
- if (currentClass == null) return '';
- var visitor = _BindThisVisitor._instance;
- visitor._bindThis = false;
- node.accept(visitor);
- return visitor._bindThis ? '.bind(this)' : '';
- }
-
static bool _needsImplicitThis(Element e) =>
e is PropertyAccessorElement && !e.variable.isStatic ||
e is ClassMemberElement && !e.isStatic && e is! ConstructorElement;
@@ -2239,26 +2220,6 @@ class _AssignmentFinder extends RecursiveAstVisitor {
}
}
-/// This is a workaround for V8 arrow function bindings being not yet
-/// implemented. See issue #43
-// TODO(jmesserly): cleaner to handle this workaround on the JS side.
-class _BindThisVisitor extends RecursiveAstVisitor {
- static _BindThisVisitor _instance = new _BindThisVisitor();
- bool _bindThis = false;
-
- @override
- visitSimpleIdentifier(SimpleIdentifier node) {
- if (JSCodegenVisitor._needsImplicitThis(node.staticElement)) {
- _bindThis = true;
- }
- }
-
- @override
- visitThisExpression(ThisExpression node) {
- _bindThis = true;
- }
-}
-
class JSGenerator extends CodeGenerator {
final JSCodeOptions options;
« no previous file with comments | « lib/runtime/dart/isolate.js ('k') | lib/src/js/nodes.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698