[Laszlo-checkins] r9273 - in openlaszlo/trunk/WEB-INF/lps: lfc/services server/src/org/openlaszlo/sc
dda@openlaszlo.org
dda at openlaszlo.org
Thu May 22 05:41:44 PDT 2008
Author: dda
Date: 2008-05-22 05:41:34 -0700 (Thu, 22 May 2008)
New Revision: 9273
Modified:
openlaszlo/trunk/WEB-INF/lps/lfc/services/LzUtils.lzs
openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/ParseTreePrinter.java
Log:
Change 20080522-dda-h by dda at lester.local on 2008-05-22 08:03:36 EDT
in /Users/dda/laszlo/src/svn/openlaszlo/trunk-c
for http://svn.openlaszlo.org/openlaszlo/trunk
Summary: Protection for Javascript 'return' snafus in unparser
New Features:
Bugs Fixed: LPP-5761
Technical Reviewer: ptw (pending)
QA Reviewer: (pending)
Doc Reviewer: (pending)
Documentation:
Release Notes:
Details:
The argument for return is checked - if it contains a newline and is not already
parenthesized, parentheses are added.
Note: this change is made and tested against r9252 -- before r9267, which would
fix the reported problem in a different way. This fix should guarantee that
problems with breaking lines in 'return' statements will not trouble us again.
Tests:
Tested againg r9252 (see Details above):
The original LzUtils.lzs compiles.
swf9 hello + (smoketest,weather,lzpix) * (swf8,dhtml)
Modified: openlaszlo/trunk/WEB-INF/lps/lfc/services/LzUtils.lzs
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/lfc/services/LzUtils.lzs 2008-05-22 12:40:08 UTC (rev 9272)
+++ openlaszlo/trunk/WEB-INF/lps/lfc/services/LzUtils.lzs 2008-05-22 12:41:34 UTC (rev 9273)
@@ -58,11 +58,10 @@
scope.__callbacks[sc] = sc;
}
lz.Utils.__scopes[sc] = scope;
- var val = function () {
+ return function () {
var s = lz.Utils.__scopes[sc];
if (s) return s[name].apply(s, args);
};
- return val;
}
public function removecallback(scope) {
Modified: openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/ParseTreePrinter.java
===================================================================
--- openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/ParseTreePrinter.java 2008-05-22 12:40:08 UTC (rev 9272)
+++ openlaszlo/trunk/WEB-INF/lps/server/src/org/openlaszlo/sc/ParseTreePrinter.java 2008-05-22 12:41:34 UTC (rev 9273)
@@ -110,19 +110,27 @@
where.println(visit(node));
}
- public String delimit(String phrase, boolean force) {
+ public String delimit(String phrase, boolean force, boolean parenMultiline) {
// Strip the phrase of annotations so we can look at the first char
String plain = unannotate(phrase);
if (plain.length() > 0) {
- return ((('(' != plain.charAt(0)) && force)?" ":SPACE) + phrase;
+ boolean hasParen = '(' == plain.charAt(0);
+ phrase = ((!hasParen && force)?" ":SPACE) + phrase;
+ if (!hasParen && parenMultiline && plain.indexOf('\n') >= 0) {
+ phrase = "(" + phrase + ")";
+ }
}
return phrase;
}
public String delimit(String phrase) {
- return delimit(phrase, true);
+ return delimit(phrase, true, false);
}
-
+
+ public String delimitWithParen(String phrase) {
+ return delimit(phrase, true, true);
+ }
+
public String elideSemi(String phrase) {
// Strip the phrase of annotations so we can look at the ending
if (unannotate(phrase).endsWith(SEMI)) {
@@ -441,7 +449,7 @@
int thisPrec = prec(((ASTOperator)node.get(1)).getOperator(), false);
assert children.length == 3;
children[2] = maybeAddParens(thisPrec, node.get(2), children[2], true);
- return children[0] + SPACE + children[1] + delimit(children [2], false);
+ return children[0] + SPACE + children[1] + delimit(children [2], false, false);
}
public String visitCallExpression(SimpleNode node, String[] children) {
int thisPrec = prec(Ops.LPAREN, true);
@@ -517,7 +525,7 @@
return children[0] + "[" + children[1] + "]";
}
public String visitReturnStatement(SimpleNode node, String[] children) {
- return "return" + delimit(children[0]);
+ return "return" + delimitWithParen(children[0]);
}
public String visitThisReference(SimpleNode node, String[] children) {
return "this";
@@ -665,7 +673,7 @@
int thisPrec = prec(isAnd ? Ops.SC_AND : Ops.SC_OR, false);
children[0] = maybeAddParens(thisPrec, node.get(0), children[0], true);
for (int i = 1; i < children.length; i++) {
- children[i] = delimit(maybeAddParens(thisPrec, node.get(i), children[i]), false);
+ children[i] = delimit(maybeAddParens(thisPrec, node.get(i), children[i]), false, false);
}
return join(isAnd ? (SPACE + "&&") : (SPACE + "||"), children);
}
@@ -710,7 +718,7 @@
sb.append(space);
sb.append(op);
// Disambiguate `a + ++b`, `a++ + b` etc.
- sb.append(delimit(child, required || opChar == unannotate(child).charAt(0)));
+ sb.append(delimit(child, required || opChar == unannotate(child).charAt(0), false));
}
return(sb.toString());
}
More information about the Laszlo-checkins
mailing list