Reviewers: jat,
Please review this at http://gwt-code-reviews.appspot.com/1620805/
Affected files:
M dev/core/src/com/google/gwt/dev/javac/JsniCollector.java
M dev/core/src/com/google/gwt/dev/javac/JsniMethod.java
M dev/core/src/com/google/gwt/dev/shell/Jsni.java
M dev/core/src/com/google/gwt/dev/shell/ModuleSpaceOOPHM.java
Index: dev/core/src/com/google/gwt/dev/javac/JsniCollector.java
diff --git a/dev/core/src/com/google/gwt/dev/javac/JsniCollector.java
b/dev/core/src/com/google/gwt/dev/javac/JsniCollector.java
index
e00e9ba8acd96f7c9c8e4cefe85266593bbd51f1..0d772dfc5dc11a2c8909c2a649bbd4a7a5205e91
100644
--- a/dev/core/src/com/google/gwt/dev/javac/JsniCollector.java
+++ b/dev/core/src/com/google/gwt/dev/javac/JsniCollector.java
@@ -72,13 +72,15 @@ public class JsniCollector {
private static final class JsniMethodImpl extends JsniMethod implements
Serializable {
private final JsFunction func;
+ private boolean isInstance;
private boolean isScriptOnly;
private final String name;
- public JsniMethodImpl(String name, JsFunction func, boolean
isScriptOnly) {
+ public JsniMethodImpl(String name, JsFunction func, boolean
isScriptOnly, boolean isInstance) {
this.name = name;
this.func = func;
this.isScriptOnly = isScriptOnly;
+ this.isInstance = isInstance;
}
@Override
@@ -87,6 +89,11 @@ public class JsniCollector {
}
@Override
+ public boolean isInstance() {
+ return isInstance;
+ }
+
+ @Override
public boolean isScriptOnly() {
return isScriptOnly;
}
@@ -171,7 +178,7 @@ public class JsniCollector {
if (jsFunction != null) {
String jsniSignature = getJsniSignature(enclosingType, method);
jsniMethods.put((MethodDeclaration) method, new JsniMethodImpl(
- jsniSignature, jsFunction, isScriptOnly(method)));
+ jsniSignature, jsFunction,
isScriptOnly(method), !method.isStatic()));
}
}
}
Index: dev/core/src/com/google/gwt/dev/javac/JsniMethod.java
diff --git a/dev/core/src/com/google/gwt/dev/javac/JsniMethod.java
b/dev/core/src/com/google/gwt/dev/javac/JsniMethod.java
index
616ff108a73c4a052f23a766224c8df537e1c057..e59c8f33d67c5ffdd1063e37a9a3b5f862375594
100644
--- a/dev/core/src/com/google/gwt/dev/javac/JsniMethod.java
+++ b/dev/core/src/com/google/gwt/dev/javac/JsniMethod.java
@@ -28,6 +28,11 @@ public abstract class JsniMethod {
public abstract JsFunction function();
/**
+ * If the JSNI method has a "this" parameter.
+ */
+ public abstract boolean isInstance();
+
+ /**
* Returns true if this JSNI function should only be used from script.
* See {@link com.google.gwt.core.client.GwtScriptOnly GwtScriptOnly}.
*/
@@ -52,4 +57,5 @@ public abstract class JsniMethod {
* The parameter names.
*/
public abstract String[] paramNames();
+
}
Index: dev/core/src/com/google/gwt/dev/shell/Jsni.java
diff --git a/dev/core/src/com/google/gwt/dev/shell/Jsni.java
b/dev/core/src/com/google/gwt/dev/shell/Jsni.java
index
24a3962ad1392a61661edc8d69d490e9d360b256..cb3c9df4faab478d0a24715bfb5a572a6145e2e9
100644
--- a/dev/core/src/com/google/gwt/dev/shell/Jsni.java
+++ b/dev/core/src/com/google/gwt/dev/shell/Jsni.java
@@ -22,10 +22,13 @@ import com.google.gwt.dev.js.ast.JsContext;
import com.google.gwt.dev.js.ast.JsExpression;
import com.google.gwt.dev.js.ast.JsFunction;
import com.google.gwt.dev.js.ast.JsInvocation;
+import com.google.gwt.dev.js.ast.JsName;
import com.google.gwt.dev.js.ast.JsNameRef;
import com.google.gwt.dev.js.ast.JsNode;
import com.google.gwt.dev.js.ast.JsNullLiteral;
import com.google.gwt.dev.js.ast.JsNumberLiteral;
+import com.google.gwt.dev.js.ast.JsThisRef;
+import com.google.gwt.dev.js.ast.JsVars.JsVar;
import com.google.gwt.dev.util.DefaultTextOutput;
import com.google.gwt.dev.util.TextOutput;
@@ -157,6 +160,12 @@ public class Jsni {
return super.visit(x, ctx);
}
+ @Override
+ public boolean visit(JsThisRef x, JsContext ctx) {
+ out.print("THIS");
+ return false;
+ }
+
/**
* Handles immediate invocations of JSNI method references. This has
to be
* done through a wonky method "__gwt_makeJavaInvoke" to handle
exceptions
Index: dev/core/src/com/google/gwt/dev/shell/ModuleSpaceOOPHM.java
diff --git a/dev/core/src/com/google/gwt/dev/shell/ModuleSpaceOOPHM.java
b/dev/core/src/com/google/gwt/dev/shell/ModuleSpaceOOPHM.java
index
6b2f32318bb7c6c2cf5725bc9383066bf94f73e2..8da44632def0b0def4438779c0da846acb210184
100644
--- a/dev/core/src/com/google/gwt/dev/shell/ModuleSpaceOOPHM.java
+++ b/dev/core/src/com/google/gwt/dev/shell/ModuleSpaceOOPHM.java
@@ -66,6 +66,15 @@ public class ModuleSpaceOOPHM extends ModuleSpace {
jsni.append(paramNames[i]);
}
jsni.append(") ");
+ String fun;
+ if (jsniMethod.isInstance()
&& !jsniMethod.name().startsWith("@com.google.gwt.user.client.Window::")) {
+ // Undo null->window conversion, see Issue 3069
+ fun = "var THIS = (this == window) ? null : this;";
+ } else {
+ fun = "var THIS = this;";
+ }
+ int i = body.indexOf("{");
+ body = body.substring(0, i + 1) + fun + body.substring(i + 1);
jsni.append(body);
jsni.append(";\n\n");
}
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors