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

Unified Diff: pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart

Issue 1510633003: Safety analysis for JS template placeholders. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Make predicate positional Created 5 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 | « pkg/compiler/lib/src/js/placeholder_safety.dart ('k') | tests/compiler/dart2js/js_safety_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart
diff --git a/pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart b/pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart
index 6667ded4b3ab0deedd68bd3f0dde4a7720c4ebee..ecdbccb2c6ff886921d45bbef35aea7f4b59ab60 100644
--- a/pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart
+++ b/pkg/compiler/lib/src/tree_ir/optimization/statement_rewriter.dart
@@ -8,6 +8,7 @@ import 'optimization.dart' show Pass;
import '../tree_ir_nodes.dart';
import '../../io/source_information.dart';
import '../../elements/elements.dart';
+import '../../js/placeholder_safety.dart';
/**
* Translates to direct-style.
@@ -1140,13 +1141,24 @@ class StatementRewriter extends Transformer implements Pass {
}
void handleForeignCode(ForeignCode node) {
- // Arguments will get inserted in a JS code template. The arguments will
- // not always be evaluated (e.g. if the template is '# && #').
- // TODO(asgerf): We could analyze the JS AST to see if arguments are
- // definitely evaluated left-to-right.
+ // Some arguments will get inserted in a JS code template. The arguments
+ // will not always be evaluated (e.g. the second placeholder in the template
+ // '# && #').
+
+ // TODO(sra): Find out which tree_ir expressions are not nullable. It helps
+ // a lot with templates like '#.push(#)'.
+ bool isNullable(e) => true;
+
+ int safeArguments =
+ PlaceholderSafetyAnalysis.analyze(node.codeTemplate.ast, isNullable);
inEmptyEnvironment(() {
- _rewriteList(node.arguments);
+ for (int i = node.arguments.length - 1; i >= safeArguments; --i) {
+ node.arguments[i] = visitExpression(node.arguments[i]);
+ }
});
+ for (int i = safeArguments - 1; i >= 0; --i) {
+ node.arguments[i] = visitExpression(node.arguments[i]);
+ }
}
@override
« no previous file with comments | « pkg/compiler/lib/src/js/placeholder_safety.dart ('k') | tests/compiler/dart2js/js_safety_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698