Fix potential error scenario where the web-mode backref ident can be determined incorrectly.
Patch by: bobv
Review by: rjrjr
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@5980 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/user/src/com/google/gwt/rpc/client/impl/CommandClientSerializationStreamReader.java b/user/src/com/google/gwt/rpc/client/impl/CommandClientSerializationStreamReader.java
index 3096d85..83586a0 100644
--- a/user/src/com/google/gwt/rpc/client/impl/CommandClientSerializationStreamReader.java
+++ b/user/src/com/google/gwt/rpc/client/impl/CommandClientSerializationStreamReader.java
@@ -29,6 +29,12 @@
public class CommandClientSerializationStreamReader implements
SerializationStreamReader {
+ /**
+ * An identifier in the payload evaluation context that is used to hold
+ * backreferences.
+ */
+ public static final String BACKREF_IDENT = "_";
+
private static native JsArray<JavaScriptObject> eval(String payload) /*-{
return eval(payload);
}-*/;
@@ -80,7 +86,7 @@
public void prepareToRead(String js) throws RemoteException {
try {
- payload = eval("(function(){var _={};" + js + "})()");
+ payload = eval("(function(){var " + BACKREF_IDENT + "={};" + js + "})()");
assert payload != null : "Payload evaluated to null";
} catch (JavaScriptException e) {
throw new IncompatibleRemoteServiceException(
diff --git a/user/src/com/google/gwt/rpc/server/WebModePayloadSink.java b/user/src/com/google/gwt/rpc/server/WebModePayloadSink.java
index 3edbec8..6a7994c 100644
--- a/user/src/com/google/gwt/rpc/server/WebModePayloadSink.java
+++ b/user/src/com/google/gwt/rpc/server/WebModePayloadSink.java
@@ -15,6 +15,8 @@
*/
package com.google.gwt.rpc.server;
+import static com.google.gwt.rpc.client.impl.CommandClientSerializationStreamReader.BACKREF_IDENT;
+
import com.google.gwt.rpc.client.ast.ArrayValueCommand;
import com.google.gwt.rpc.client.ast.BooleanValueCommand;
import com.google.gwt.rpc.client.ast.ByteValueCommand;
@@ -862,7 +864,6 @@
}
private final ClientOracle clientOracle;
- private final String backRefIdent;
private boolean finished = false;
private final OutputStream out;
private final Map<ValueCommand, byte[]> valueBackRefs = new HashMap<ValueCommand, byte[]>();
@@ -873,7 +874,6 @@
public WebModePayloadSink(ClientOracle clientOracle, OutputStream out) {
this.clientOracle = clientOracle;
this.out = out;
- backRefIdent = clientOracle.createUnusedIdent("_");
}
@Override
@@ -920,7 +920,7 @@
if (toReturn == null) {
if (freeBackRefs.isEmpty()) {
int idx = valueBackRefs.size();
- toReturn = getBytes(backRefIdent + "._"
+ toReturn = getBytes(BACKREF_IDENT + "._"
+ Integer.toString(idx, Character.MAX_RADIX));
} else {
toReturn = freeBackRefs.pop();