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

Unified Diff: compiler/java/com/google/dart/compiler/backend/js/GenerateJavascriptAST.java

Issue 8232014: Fix named parameters handling of values that are falsy in JS. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 2 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
Index: compiler/java/com/google/dart/compiler/backend/js/GenerateJavascriptAST.java
===================================================================
--- compiler/java/com/google/dart/compiler/backend/js/GenerateJavascriptAST.java (revision 350)
+++ compiler/java/com/google/dart/compiler/backend/js/GenerateJavascriptAST.java (working copy)
@@ -174,7 +174,8 @@
private final DartCompilerContext context;
private final OptimizationStrategy optStrategy;
private final DartUnit unit;
- private CoreTypeProvider typeProvider;
+ private final CoreTypeProvider typeProvider;
+ private final boolean generateClosureCompatibleCode;
/**
* Generates the Javascript AST using the names created in {@link GenerateNamesAndScopes}.
@@ -182,6 +183,8 @@
static class GenerateJavascriptVisitor
implements DartPlainVisitor<JsNode>, TraversalContextProvider {
+ private final boolean generateClosureCompatibleCode;
+
private static boolean isSuperCall(Symbol symbol) {
return ElementKind.of(symbol).equals(ElementKind.SUPER);
}
@@ -252,13 +255,15 @@
public GenerateJavascriptVisitor(DartUnit unit, DartCompilerContext context,
TranslationContext translationContext,
- OptimizationStrategy optStrategy, CoreTypeProvider typeProvider) {
+ OptimizationStrategy optStrategy, CoreTypeProvider typeProvider,
+ boolean generateClosureCompatibleCode) {
this.context = context;
this.translationContext = translationContext;
this.optStrategy = optStrategy;
this.typeProvider = typeProvider;
this.typeUtils = Types.getInstance(typeProvider);
this.unitLibrary = unit.getLibrary().getElement();
+ this.generateClosureCompatibleCode = generateClosureCompatibleCode;
// Cache the mangler in a field since it is used frequently
mangler = translationContext.getMangler();
@@ -1178,23 +1183,23 @@
continue;
}
- JsNameRef ifExpr = AstUtil.newNameRef(namedParam.getName().makeRef(),
- jsParam.getName());
+ JsExpression paramName = string(jsParam.getName().getShortIdent());
+ if (generateClosureCompatibleCode) {
+ paramName = AstUtil.call(null,
+ AstUtil.nameref(null, "JSCompiler_renameProperty"), paramName);
+ }
+ JsExpression ifExpr = AstUtil.in(null, paramName, namedParam.getName().makeRef());
- JsPrefixOperation ppSeen = new JsPrefixOperation(JsUnaryOperator.INC, seen.makeRef());
- JsBinaryOperation thenExpr = new JsBinaryOperation(JsBinaryOperator.COMMA, ppSeen,
+ JsExpression ppSeen = AstUtil.preinc(null, seen.makeRef());
+ JsBinaryOperation thenExpr = AstUtil.comma(null, ppSeen,
AstUtil.newNameRef(namedParam.getName().makeRef(), jsParam.getName()));
- JsExpression elseExpr;
-
DartExpression defaultValue = param.getDefaultExpr();
- if (defaultValue != null) {
- JsPrefixOperation ppDef = new JsPrefixOperation(JsUnaryOperator.INC, def.makeRef());
- elseExpr = new JsBinaryOperation(JsBinaryOperator.COMMA, ppDef,
- generateDefaultValue(defaultValue));
- } else {
- elseExpr = nulle();
- }
+ JsExpression elseExpr = (defaultValue != null)
+ ? generateDefaultValue(defaultValue)
+ : undefined();
+ JsExpression ppDef = AstUtil.preinc(null, def.makeRef());
+ elseExpr = AstUtil.comma(null, ppDef, elseExpr);
JsBinaryOperation asg = assign(
jsParam.getName().makeRef(),
@@ -2635,10 +2640,14 @@
++posUsed;
jsArgs.add((JsExpression) generate(posArgs.get(idx)));
} else if (param.getDefaultValue() != null) {
+ assert(param.isNamed());
jsArgs.add(generateDefaultValue(param.getDefaultValue()));
} else {
- // Call cannot succeed; bail out.
- return false;
+ if (param.isNamed()) {
+ jsArgs.add(undefined());
+ } else {
+ return false;
+ }
}
}
++idx;
@@ -3711,18 +3720,20 @@
}
GenerateJavascriptAST(DartUnit unit, CoreTypeProvider typeProvider, DartCompilerContext context,
- OptimizationStrategy optimizationStrategy) {
+ OptimizationStrategy optimizationStrategy,
+ boolean generateClosureCompatibleCode) {
this.unit = unit;
this.context = context;
this.optStrategy = optimizationStrategy;
this.typeProvider = typeProvider;
+ this.generateClosureCompatibleCode = generateClosureCompatibleCode;
}
public void translateNode(TranslationContext translationContext, DartNode node,
JsBlock blockStatics) {
GenerateJavascriptVisitor generator =
new GenerateJavascriptVisitor(unit, context, translationContext,
- optStrategy, typeProvider);
+ optStrategy, typeProvider, generateClosureCompatibleCode);
// Generate the Javascript AST.
node.accept(generator);
// Set aside the static initializations

Powered by Google App Engine
This is Rietveld 408576698