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

Unified Diff: lib/src/js/nodes.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/src/codegen/js_codegen.dart ('k') | lib/src/js/printer.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/js/nodes.dart
diff --git a/lib/src/js/nodes.dart b/lib/src/js/nodes.dart
index 365d8844e877b5d0eb26b9f622b5b1c3df0ef56b..da3bd993834053f955107137e00971632b6fead7 100644
--- a/lib/src/js/nodes.dart
+++ b/lib/src/js/nodes.dart
@@ -890,6 +890,8 @@ class ArrowFun extends FunctionExpression {
final List<Identifier> params;
final body; // Expression or Block
+ bool _bindThisWorkaround; // lazy initialized
+
ArrowFun(this.params, this.body);
accept(NodeVisitor visitor) => visitor.visitArrowFun(this);
@@ -901,10 +903,29 @@ class ArrowFun extends FunctionExpression {
ArrowFun _clone() => new ArrowFun(params, body);
+ /// This is a workaround for V8 arrow function bindings being not yet
+ /// implemented. See <https://code.google.com/p/v8/issues/detail?id=2700>
+ bool get bindThisWorkaround {
+ if (_bindThisWorkaround != null) return _bindThisWorkaround;
+ var visitor = new _ThisFinder();
+ body.accept(visitor);
+ return _bindThisWorkaround = visitor.found;
+ }
+
/// Ensure parens always get generated if necessary.
// TODO(jmesserly): I'm not sure the printer is handling this correctly for
// function() { ... } either.
- int get precedenceLevel => ASSIGNMENT;
+ int get precedenceLevel => bindThisWorkaround ? CALL : ASSIGNMENT;
+}
+
+class _ThisFinder extends BaseVisitor {
+ bool found = false;
+ visitThis(This node) {
+ found = true;
+ }
+ visitNode(Node node) {
+ if (!found) super.visitNode(node);
+ }
}
class AsyncModifier {
« no previous file with comments | « lib/src/codegen/js_codegen.dart ('k') | lib/src/js/printer.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698