Skip to content

Commit f1c61c0

Browse files
committed
Fix ICE due incorrect handling of JsVarargs of native JsType.
Bug: #9544 Bug-Link: #9544 Change-Id: I5f151b43f2681438dee2f8134b4f050a42a0a202
1 parent 8aee6c2 commit f1c61c0

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

dev/core/src/com/google/gwt/dev/jjs/ast/JProgram.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ public JCastMap getCastMap(JReferenceType referenceType) {
816816

817817
public JField getClassLiteralField(JType type) {
818818
return classLiteralFieldsByType.get(
819-
type.isJsoType() ? getJavaScriptObject() : type);
819+
(type.isJsNative() || type.isJsoType()) ? getJavaScriptObject() : type);
820820
}
821821

822822
public List<JDeclaredType> getDeclaredTypes() {

dev/core/src/com/google/gwt/dev/jjs/impl/ImplementJsVarargs.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,15 @@ private class VarargsMethodNormalizer extends JModVisitor {
282282
private VarargsReplacer replacer;
283283
private JLocal argumentsCopyVariable;
284284

285+
private boolean needsVarArgsPrologue(JMethod x) {
286+
// Native methods in general do not have bodies except for constructors; no code is generated
287+
// from them, safe and convenient to skip here.
288+
return x.isJsNative() || !x.isJsMethodVarargs();
289+
}
290+
285291
@Override
286292
public boolean visit(JMethod x, Context ctx) {
287-
if (!x.isJsMethodVarargs()) {
293+
if (needsVarArgsPrologue(x)) {
288294
return false;
289295
}
290296
varargsParameter = Iterables.getLast(x.getParams());
@@ -334,7 +340,7 @@ public void endVisit(JArrayLength x, Context ctx) {
334340

335341
@Override
336342
public void endVisit(JMethod x, Context ctx) {
337-
if (!x.isJsMethodVarargs()) {
343+
if (needsVarArgsPrologue(x)) {
338344
return;
339345
}
340346
// rename the varargs variable to _arguments_.

user/test/com/google/gwt/core/interop/JsTypeVarargsTest.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,20 @@ private static native Object callGetVarargsSlotUsingJsName() /*-{
103103

104104
@JsType(isNative = true, namespace = GLOBAL, name = "Object")
105105
static class NativeJsType {
106+
NativeJsType() { }
107+
NativeJsType(int j, NativeJsType... args) { }
106108
}
107109

108110
@JsType(isNative = true, namespace = GLOBAL,
109111
name = "JsTypeVarargsTest_MyNativeJsTypeVarargsConstructor")
110-
static class NativeJsTypeWithVarargsConstructor {
112+
static class NativeJsTypeWithVarargsConstructor extends NativeJsType {
111113
public Object a;
112114
public int b;
113115
NativeJsTypeWithVarargsConstructor(int i, Object... args) { }
116+
117+
NativeJsTypeWithVarargsConstructor(int i, NativeJsType... args) {
118+
super(1, args);
119+
}
114120
}
115121

116122
static class SubclassNativeWithVarargsConstructor extends NativeJsTypeWithVarargsConstructor {
@@ -127,7 +133,7 @@ Object varargsMethod(int i, Object... args) {
127133
static class SubSubclassNativeWithVarargsConstructor
128134
extends SubclassNativeWithVarargsConstructor {
129135
SubSubclassNativeWithVarargsConstructor() {
130-
super(0, new Object[0]);
136+
super(0, new NativeJsType[0]);
131137
}
132138

133139
Object varargsMethod(int i, Object... args) {
@@ -288,6 +294,21 @@ public void testVarargsCall_sideEffectingInstance() {
288294
assertSame(1, sideEffectCount);
289295
}
290296

297+
static class SubclassNativeWithNativeVarargsConstructor
298+
extends NativeJsTypeWithVarargsConstructor {
299+
public NativeJsType[] ctorargs;
300+
SubclassNativeWithNativeVarargsConstructor(int i, NativeJsType... args) {
301+
super(i, args);
302+
ctorargs = args;
303+
}
304+
}
305+
306+
public void testVarargsCall_nativeVarargs() {
307+
SubclassNativeWithNativeVarargsConstructor object =
308+
new SubclassNativeWithNativeVarargsConstructor(0, new NativeJsType[0]);
309+
assertEquals(0, object.ctorargs.length);
310+
}
311+
291312
static class UninstantiatedClass {
292313
}
293314

0 commit comments

Comments
 (0)