Revision: 7913
Author: sp...@google.com
Date: Tue Apr 13 06:08:53 2010
Log: Have JsInliner refuse to interpose a new expression
before a substituted argument.
Review at http://gwt-code-reviews.appspot.com/344801
Review by: sco...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=7913
Modified:
/trunk/dev/core/src/com/google/gwt/dev/js/JsInliner.java
/trunk/dev/core/test/com/google/gwt/dev/js/JsInlinerTest.java
=======================================
--- /trunk/dev/core/src/com/google/gwt/dev/js/JsInliner.java Tue Mar 23
14:56:21 2010
+++ /trunk/dev/core/src/com/google/gwt/dev/js/JsInliner.java Tue Apr 13
06:08:53 2010
@@ -673,11 +673,28 @@
maintainsOrder = false;
}
}
-
+
@Override
public void endVisit(JsNameRef x, JsContext<JsExpression> ctx) {
checkName(x.getName());
}
+
+ @Override
+ public void endVisit(JsNew x, JsContext<JsExpression> ctx) {
+ /*
+ * Unless all arguments have already been evaluated, assume
+ * that invoking the new expression might interfere with
+ * the evaluation of the argument.
+ *
+ * It would be possible to allow this if the invoked function
+ * either does nothing or does nothing that affects the
+ * remaining arguments. However, currently there is no
+ * analysis of the invoked function.
+ */
+ if (unevaluated.size() > 0) {
+ maintainsOrder = false;
+ }
+ }
@Override
public void endVisit(JsThisRef x, JsContext<JsExpression> ctx) {
=======================================
--- /trunk/dev/core/test/com/google/gwt/dev/js/JsInlinerTest.java Wed Oct
28 09:10:53 2009
+++ /trunk/dev/core/test/com/google/gwt/dev/js/JsInlinerTest.java Tue Apr
13 06:08:53 2010
@@ -79,6 +79,29 @@
+ "function c1() { return ex2 ? a1() :c1(); } c1()";
compare(expected, input);
}
+
+ /**
+ * Test that a new expression breaks argument ordering.
+ */
+ public void testOrderingNew() throws Exception {
+ StringBuffer code = new StringBuffer();
+ // A static variable x
+ code.append("var x;");
+
+ // foo() uses x
+ code.append("function foo() { alert('x = ' + x); }");
+
+ // callee does "new foo" before evaluating its argument
+ code.append("function callee(arg) { new foo(); return arg; }");
+
+ // caller invokes callee with a multi that initializes x
+ code.append("function caller() { callee((x=1,2)); }");
+
+ // bootstrap the program
+ code.append("caller();");
+
+ compare(code.toString(), code.toString());
+ }
public void testSelfRecursion() throws Exception {
String input = "function a1() { return blah && b1() }"
@@ -94,7 +117,6 @@
input = optimize(input, JsSymbolResolver.class,
FixStaticRefsVisitor.class,
JsInliner.class, JsUnusedFunctionRemover.class);
expected = optimize(expected);
- System.err.println("Input vs ");
assertEquals(expected, input);
}
}
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors
To unsubscribe, reply using "remove me" as the subject.