Switches InternalJsMap to jsinterop.

Change-Id: I024f3ee63752d06354f7752eb456422cde19b0a6
diff --git a/user/super/com/google/gwt/emul/java/util/InternalHashCodeMap.java b/user/super/com/google/gwt/emul/java/util/InternalHashCodeMap.java
index cc1c8ca..2aa14c2 100644
--- a/user/super/com/google/gwt/emul/java/util/InternalHashCodeMap.java
+++ b/user/super/com/google/gwt/emul/java/util/InternalHashCodeMap.java
@@ -104,7 +104,7 @@
   @Override
   public Iterator<Entry<K, V>> iterator() {
     return new Iterator<Map.Entry<K,V>>() {
-      final InternalJsIterator<Object> chains = backingMap.entries();
+      final InternalJsMap.Iterator<Object> chains = backingMap.entries();
       int itemIndex = 0;
       Entry<K, V>[] chain = newEntryChain();
       Entry<K, V> lastEntry = null;
@@ -114,8 +114,8 @@
         if (itemIndex < chain.length) {
           return true;
         }
-        InternalJsIteratorEntry<Object> current = chains.next();
-        if (!current.done()) {
+        InternalJsMap.IteratorEntry<Object> current = chains.next();
+        if (!current.done) {
           // Move to the beginning of next chain
           chain = unsafeCastToArray(current.getValue());
           itemIndex = 0;
diff --git a/user/super/com/google/gwt/emul/java/util/InternalJsIterator.java b/user/super/com/google/gwt/emul/java/util/InternalJsIterator.java
deleted file mode 100644
index accaee5..0000000
--- a/user/super/com/google/gwt/emul/java/util/InternalJsIterator.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*
- * Copyright 2015 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package java.util;
-
-import com.google.gwt.core.client.JavaScriptObject;
-
-class InternalJsIterator<V> extends JavaScriptObject {
-  protected InternalJsIterator() { }
-  public final native InternalJsIteratorEntry<V> next() /*-{ return this.next(); }-*/;
-}
\ No newline at end of file
diff --git a/user/super/com/google/gwt/emul/java/util/InternalJsIteratorEntry.java b/user/super/com/google/gwt/emul/java/util/InternalJsIteratorEntry.java
deleted file mode 100644
index 129ece5..0000000
--- a/user/super/com/google/gwt/emul/java/util/InternalJsIteratorEntry.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright 2015 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package java.util;
-
-import com.google.gwt.core.client.JavaScriptObject;
-
-class InternalJsIteratorEntry<V> extends JavaScriptObject {
-  protected InternalJsIteratorEntry() { }
-  public final native boolean done() /*-{ return this.done; }-*/;
-  public final native String getKey() /*-{ return this.value[0]; }-*/;
-  public final native V getValue() /*-{ return this.value[1]; }-*/;
-}
\ No newline at end of file
diff --git a/user/super/com/google/gwt/emul/java/util/InternalJsMap.java b/user/super/com/google/gwt/emul/java/util/InternalJsMap.java
index e7a1ab1..5dfbfe3 100644
--- a/user/super/com/google/gwt/emul/java/util/InternalJsMap.java
+++ b/user/super/com/google/gwt/emul/java/util/InternalJsMap.java
@@ -15,16 +15,43 @@
  */
 package java.util;
 
-import com.google.gwt.core.client.JavaScriptObject;
+import javaemul.internal.JsUtils;
+import jsinterop.annotations.JsOverlay;
+import jsinterop.annotations.JsPackage;
+import jsinterop.annotations.JsType;
 
-class InternalJsMap<V> extends JavaScriptObject {
-  protected InternalJsMap() { }
-  public final native V get(int key) /*-{ return this.get(key); }-*/;
-  public final native V get(String key) /*-{ return this.get(key); }-*/;
-  public final native void set(int key, V value) /*-{ this.set(key, value); }-*/;
-  public final native void set(String key, V value) /*-{ this.set(key, value); }-*/;
-  // Calls delete via brackets to be workable with polyfills
-  public final native void delete(int key) /*-{ this['delete'](key); }-*/;
-  public final native void delete(String key) /*-{ this['delete'](key); }-*/;
-  public final native InternalJsIterator<V> entries() /*-{ return this.entries(); }-*/;
-}
\ No newline at end of file
+// TODO(goktug): These classes should be interfaces with defender methods instead.
+@JsType(isNative = true, name = "Object", namespace = JsPackage.GLOBAL)
+class InternalJsMap<V> {
+
+  @JsType(isNative = true, name = "Object", namespace = JsPackage.GLOBAL)
+  static class Iterator<V> {
+    public native IteratorEntry<V> next();
+  }
+
+  @JsType(isNative = true, name = "Object", namespace = JsPackage.GLOBAL)
+  static class IteratorEntry<V> {
+    private Object[] value;
+    public boolean done;
+    @JsOverlay
+    public final String getKey() { return JsUtils.unsafeCastToString(value[0]); }
+    @JsOverlay
+    public final V getValue() { return (V) value[1]; }
+  }
+
+  public native V get(int key);
+  public native V get(String key);
+  public native void set(int key, V value);
+  public native void set(String key, V value);
+  @JsOverlay
+  public final void delete(int key) { JsHelper.delete(this, key); }
+  @JsOverlay
+  public final void delete(String key) { JsHelper.delete(this, key); }
+  public native Iterator<V> entries();
+
+  // Calls to delete are via brackets to be compatible with old browsers where delete is keyword.
+  private static class JsHelper {
+    static native void delete(InternalJsMap obj, int key) /*-{ obj["delete"](key); }-*/;
+    static native void delete(InternalJsMap obj, String key) /*-{ obj["delete"](key); }-*/;
+  }
+}
diff --git a/user/super/com/google/gwt/emul/java/util/InternalStringMap.java b/user/super/com/google/gwt/emul/java/util/InternalStringMap.java
index c1db5d8..3daa2af 100644
--- a/user/super/com/google/gwt/emul/java/util/InternalStringMap.java
+++ b/user/super/com/google/gwt/emul/java/util/InternalStringMap.java
@@ -83,13 +83,13 @@
   @Override
   public Iterator<Entry<K, V>> iterator() {
     return new Iterator<Map.Entry<K,V>>() {
-      InternalJsIterator<V> entries = backingMap.entries();
-      InternalJsIteratorEntry<V> current = entries.next();
-      InternalJsIteratorEntry<V> last;
+      InternalJsMap.Iterator<V> entries = backingMap.entries();
+      InternalJsMap.IteratorEntry<V> current = entries.next();
+      InternalJsMap.IteratorEntry<V> last;
 
       @Override
       public boolean hasNext() {
-        return !current.done();
+        return !current.done;
       }
       @Override
       public Entry<K, V> next() {
@@ -104,7 +104,8 @@
     };
   }
 
-  private Entry<K, V> newMapEntry(final InternalJsIteratorEntry<V> entry, final int lastValueMod) {
+  private Entry<K, V> newMapEntry(final InternalJsMap.IteratorEntry<V> entry,
+      final int lastValueMod) {
     return new AbstractMapEntry<K, V>() {
       @SuppressWarnings("unchecked")
       @Override