Fix first-time instantiation via reflection.

In 7fc035f, a general fix to instantiation via reflection was made and a
test case added. The test case fails due to a separate issue, solved in
this commit, which affects only the first instantiation via reflection.
This commit is contained in:
Davin McCall 2017-02-09 14:53:26 +00:00
parent 7fc035fd8a
commit 3d0dee98be
2 changed files with 6 additions and 4 deletions
platform/src/main/java/org/teavm/platform

View File

@ -33,6 +33,8 @@ public final class Platform {
private Platform() {
}
private static boolean newInstancePrepared;
@InjectedBy(PlatformGenerator.class)
public static native PlatformObject getPlatformObject(Object obj);
@ -85,7 +87,10 @@ public final class Platform {
public static native int nextObjectId();
public static <T> T newInstance(PlatformClass cls) {
prepareNewInstance();
if (!newInstancePrepared) {
prepareNewInstance();
newInstancePrepared = true;
}
return newInstanceImpl(cls);
}

View File

@ -117,9 +117,6 @@ public class PlatformGenerator implements Generator, Injector, DependencyPlugin
.appendMethodBody(method.getReference()).append(";").softNewLine();
}
}
writer.appendMethodBody(Platform.class, "newInstance", PlatformClass.class, Object.class).ws().append('=').ws()
.appendMethodBody(Platform.class, "newInstanceImpl", PlatformClass.class, Object.class)
.append(";").softNewLine();
}
private void generateNewInstance(GeneratorContext context, SourceWriter writer) throws IOException {