Make JavaScriptObject work in tests that are not GWTTestCase.

JavaScriptObject and subclasses can be used in a pure jvm environment,
(as is the case for some heavily mocked tests) as long as native methods
are not called.

Now that equals and hashCode perform calls to native methods, those
calls need to be guarded for the pure jvm scenario.

Change-Id: I1d0906fdeab6bde4d062060a0573e2ab6ccab6a7
diff --git a/user/src/com/google/gwt/core/client/JavaScriptObject.java b/user/src/com/google/gwt/core/client/JavaScriptObject.java
index b78735d..c4e2538 100644
--- a/user/src/com/google/gwt/core/client/JavaScriptObject.java
+++ b/user/src/com/google/gwt/core/client/JavaScriptObject.java
@@ -132,7 +132,10 @@
    */
   @Override
   public final boolean equals(Object other) {
-    return hasEquals() ? callEquals(other) : super.equals(other);
+    if (!GWT.isClient()) {
+      return super.equals(other);
+    }
+    return hasEquals(this) ? callEquals(this, other) : super.equals(other);
   }
 
   /**
@@ -144,7 +147,10 @@
    */
   @Override
   public final int hashCode() {
-    return hasHashCode() ? callHashCode() : super.hashCode();
+    if (!GWT.isClient()) {
+      return super.hashCode();
+    }
+    return hasHashCode(this) ? callHashCode(this) : super.hashCode();
   };
 
   /**
@@ -168,19 +174,19 @@
         toStringVerbose(this) : toStringSimple(this);
   }
 
-  private native boolean hasEquals() /*-{
-    return !!this.equals;
+  private static native boolean hasEquals(Object object) /*-{
+    return !!object && !!object.equals;
   }-*/;
 
-  private native boolean hasHashCode() /*-{
-    return !!this.hashCode;
+  private static native boolean hasHashCode(Object object) /*-{
+    return !!object && !!object.hashCode;
   }-*/;
 
-  private native boolean callEquals(Object other) /*-{
-    return this.equals(other);
+  private static native boolean callEquals(Object thisObject, Object thatObject) /*-{
+    return thisObject.equals(thatObject);
   }-*/;
 
-  private native int callHashCode() /*-{
-    return this.hashCode();
+  private static native int callHashCode(Object object) /*-{
+    return object.hashCode();
   }-*/;
-}
+}
\ No newline at end of file