Fix ICE due incorrect handling of JsVarargs of native JsType.

Bug: #9544
Bug-Link: https://github.com/gwtproject/gwt/issues/9544
Change-Id: I5f151b43f2681438dee2f8134b4f050a42a0a202
diff --git a/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java b/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java
index 4e37f8b..2811ac4 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java
@@ -816,7 +816,7 @@
 
   public JField getClassLiteralField(JType type) {
     return classLiteralFieldsByType.get(
-        type.isJsoType() ? getJavaScriptObject() : type);
+        (type.isJsNative() || type.isJsoType()) ? getJavaScriptObject() : type);
   }
 
   public List<JDeclaredType> getDeclaredTypes() {
diff --git a/dev/core/src/com/google/gwt/dev/jjs/impl/ImplementJsVarargs.java b/dev/core/src/com/google/gwt/dev/jjs/impl/ImplementJsVarargs.java
index 0938544..9c86dc0 100644
--- a/dev/core/src/com/google/gwt/dev/jjs/impl/ImplementJsVarargs.java
+++ b/dev/core/src/com/google/gwt/dev/jjs/impl/ImplementJsVarargs.java
@@ -282,9 +282,15 @@
     private VarargsReplacer replacer;
     private JLocal argumentsCopyVariable;
 
+    private boolean needsVarArgsPrologue(JMethod x) {
+      // Native methods in general do not have bodies except for constructors; no code is generated
+      // from them, safe and convenient to skip here.
+      return x.isJsNative() || !x.isJsMethodVarargs();
+    }
+
     @Override
     public boolean visit(JMethod x, Context ctx) {
-      if (!x.isJsMethodVarargs()) {
+      if (needsVarArgsPrologue(x)) {
         return false;
       }
       varargsParameter = Iterables.getLast(x.getParams());
@@ -334,7 +340,7 @@
 
     @Override
     public void endVisit(JMethod x, Context ctx) {
-      if (!x.isJsMethodVarargs()) {
+      if (needsVarArgsPrologue(x)) {
         return;
       }
       // rename the varargs variable to _arguments_.
diff --git a/user/test/com/google/gwt/core/interop/JsTypeVarargsTest.java b/user/test/com/google/gwt/core/interop/JsTypeVarargsTest.java
index 1b72674..36d5172 100644
--- a/user/test/com/google/gwt/core/interop/JsTypeVarargsTest.java
+++ b/user/test/com/google/gwt/core/interop/JsTypeVarargsTest.java
@@ -103,14 +103,20 @@
 
   @JsType(isNative = true, namespace = GLOBAL, name = "Object")
   static class NativeJsType {
+    NativeJsType() { }
+    NativeJsType(int j, NativeJsType... args) { }
   }
 
   @JsType(isNative = true, namespace = GLOBAL,
       name = "JsTypeVarargsTest_MyNativeJsTypeVarargsConstructor")
-  static class NativeJsTypeWithVarargsConstructor {
+  static class NativeJsTypeWithVarargsConstructor extends NativeJsType {
     public Object a;
     public int b;
     NativeJsTypeWithVarargsConstructor(int i, Object... args) { }
+
+    NativeJsTypeWithVarargsConstructor(int i, NativeJsType... args) {
+      super(1, args);
+    }
   }
 
   static class SubclassNativeWithVarargsConstructor extends NativeJsTypeWithVarargsConstructor {
@@ -127,7 +133,7 @@
   static class SubSubclassNativeWithVarargsConstructor
       extends SubclassNativeWithVarargsConstructor {
     SubSubclassNativeWithVarargsConstructor() {
-      super(0, new Object[0]);
+      super(0, new NativeJsType[0]);
     }
 
     Object varargsMethod(int i, Object... args) {
@@ -288,6 +294,21 @@
     assertSame(1, sideEffectCount);
   }
 
+  static class SubclassNativeWithNativeVarargsConstructor
+      extends NativeJsTypeWithVarargsConstructor {
+    public NativeJsType[] ctorargs;
+    SubclassNativeWithNativeVarargsConstructor(int i, NativeJsType... args) {
+      super(i, args);
+      ctorargs = args;
+    }
+  }
+
+  public void testVarargsCall_nativeVarargs() {
+    SubclassNativeWithNativeVarargsConstructor object =
+        new SubclassNativeWithNativeVarargsConstructor(0, new NativeJsType[0]);
+    assertEquals(0, object.ctorargs.length);
+  }
+
   static class UninstantiatedClass {
   }