diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ClassNativeGenerator.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ClassNativeGenerator.java index 86b7f8e9e..a6ac2a177 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ClassNativeGenerator.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/ClassNativeGenerator.java @@ -12,14 +12,14 @@ import org.teavm.model.MethodReference; public class ClassNativeGenerator implements Generator { @Override public void generate(GeneratorContext context, SourceWriter writer, MethodReference methodRef) { - switch (methodRef.getClassName()) { + switch (methodRef.getName()) { case "isInstance": generateIsInstance(context, writer); break; case "isAssignable": generateIsAssignableFrom(context, writer); break; - case "getComponentType": + case "getComponentType0": generateGetComponentType(context, writer); break; } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TClassTests.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TClassTests.java index ead653df2..6a8a88e06 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TClassTests.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TClassTests.java @@ -33,6 +33,11 @@ class TClassTests { assertEquals(Object.class, Object[].class.getComponentType()); } + @Test + public void arrayOfArraysComponentTypeDetected() { + assertEquals(Object[].class, Object[][].class.getComponentType()); + } + @Test public void nonArrayComponentTypeIsNull() { assertNull(Object.class.getComponentType()); diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TStringTests.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TStringTests.java new file mode 100644 index 000000000..bc7a58873 --- /dev/null +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TStringTests.java @@ -0,0 +1,24 @@ +package org.teavm.classlib.java.lang; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; + +/** + * + * @author Alexey Andreev + */ +class TStringTests { + @Test + public void charsExtracted() { + String str = "123"; + assertEquals('1', str.charAt(0)); + assertEquals('2', str.charAt(1)); + assertEquals('3', str.charAt(2)); + } + + @Test + public void lengthComputed() { + String str = "123"; + assertEquals(3, str.length()); + } +} diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TSystemTests.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TSystemTests.java index 4598b8029..a5e3e484b 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TSystemTests.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TSystemTests.java @@ -29,4 +29,14 @@ class TSystemTests { public void failsToCopyArraysWithIncompatibleElements() { TSystem.arraycopy(TObject.wrap(new TObject[1]), 0, TObject.wrap(new int[1]), 0, 1); } + + @Test(expected = NullPointerException.class) + public void failsToCopyFromNullSource() { + TSystem.arraycopy(null, 0, TObject.wrap(new int[1]), 0, 1); + } + + @Test(expected = NullPointerException.class) + public void failsToCopyToNullTarget() { + TSystem.arraycopy(TObject.wrap(new TObject[1]), 0, null, 0, 1); + } } diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/org/junit/Assert.java b/teavm-classlib/src/main/java/org/teavm/classlib/org/junit/Assert.java index 76784965d..9c09b919d 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/org/junit/Assert.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/org/junit/Assert.java @@ -34,6 +34,18 @@ public class Assert { } } + public static void assertEquals(long expected, long actual) { + if (expected != actual) { + fail(); + } + } + + public static void assertNotEquals(long expected, long actual) { + if (expected == actual) { + fail(); + } + } + public static void assertNotNull(Object object) { if (object == null) { fail(); diff --git a/teavm-classlib/src/main/java/org/teavm/classlibgen/ClasslibTestGenerator.java b/teavm-classlib/src/main/java/org/teavm/classlibgen/ClasslibTestGenerator.java index 7ea8a2382..39df36501 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlibgen/ClasslibTestGenerator.java +++ b/teavm-classlib/src/main/java/org/teavm/classlibgen/ClasslibTestGenerator.java @@ -32,7 +32,7 @@ public class ClasslibTestGenerator { private static List testMethods = new ArrayList<>(); private static Map> groupedMethods = new HashMap<>(); private static String[] testClasses = { "java.lang.ObjectTests", "java.lang.SystemTests", - "java.lang.StringBuilderTests", "java.lang.ClassTests" }; + "java.lang.StringBuilderTests", "java.lang.ClassTests", "java.lang.StringTests" }; public static void main(String[] args) throws IOException { out = System.out; diff --git a/teavm-core/src/main/java/org/teavm/dependency/DependencyChecker.java b/teavm-core/src/main/java/org/teavm/dependency/DependencyChecker.java index 868340fe5..a4a888387 100644 --- a/teavm-core/src/main/java/org/teavm/dependency/DependencyChecker.java +++ b/teavm-core/src/main/java/org/teavm/dependency/DependencyChecker.java @@ -170,7 +170,7 @@ public class DependencyChecker { if (method != null) { return methodCache.map(new MethodReference(cls.getName(), methodRef.getDescriptor())); } - cls = classSource.getClassHolder(cls.getParent()); + cls = cls.getParent() != null ? classSource.getClassHolder(cls.getParent()) : null; } throw new RuntimeException("Method not found: " + methodRef); } diff --git a/teavm-core/src/main/resources/org/teavm/javascript/runtime.js b/teavm-core/src/main/resources/org/teavm/javascript/runtime.js index ea0971f17..0ca011d44 100644 --- a/teavm-core/src/main/resources/org/teavm/javascript/runtime.js +++ b/teavm-core/src/main/resources/org/teavm/javascript/runtime.js @@ -218,17 +218,17 @@ Long = function(lo, hi) { this.lo = lo | 0; this.hi = hi | 0; } -Long.ZERO = new Long(0, 0); -Long.fromInt = function(val) { +Long_ZERO = new Long(0, 0); +Long_fromInt = function(val) { return new Long(val, 0); } -Long.fromNumber = function(val) { +Long_fromNumber = function(val) { return new Long(val | 0, (val / 0x100000000) | 0); } -Long.toNumber = function(val) { +Long_toNumber = function(val) { return val.lo + 0x100000000 * val.hi; } -Long.add = function(a, b) { +Long_add = function(a, b) { var a_lolo = a.lo & 0xFFFF; var a_lohi = a.lo >>> 16; var a_hilo = a.hi & 0xFFFF; @@ -245,7 +245,7 @@ Long.add = function(a, b) { return new Long((lolo & 0xFFFF) | ((lohi & 0xFFFF) << 16), (hilo & 0xFFFF) | ((hihi & 0xFFFF) << 16)); } -Long.inc = function(a) { +Long_inc = function(a) { var lo = (a.lo + 1) | 0; var hi = a.hi; if (lo === 0) { @@ -253,7 +253,7 @@ Long.inc = function(a) { } return new Long(lo, hi); } -Long.dec = function(a) { +Long_dec = function(a) { var lo = (a.lo - 1) | 0; var hi = a.hi; if (lo === -1) { @@ -261,10 +261,10 @@ Long.dec = function(a) { } return new Long(lo, hi); } -Long.neg = function(a) { +Long_neg = function(a) { return Long.inc(new Long(a.lo ^ 0xFFFFFFFF, a.hi ^ 0xFFFFFFFF)); } -Long.sub = function(a, b) { +Long_sub = function(a, b) { var a_lolo = a.lo & 0xFFFF; var a_lohi = a.lo >>> 16; var a_hilo = a.hi & 0xFFFF; @@ -281,17 +281,17 @@ Long.sub = function(a, b) { return new Long((lolo & 0xFFFF) | ((lohi & 0xFFFF) << 16), (hilo & 0xFFFF) | ((hihi & 0xFFFF) << 16)); } -Long.compare = function(a, b) { +Long_compare = function(a, b) { var r = a.hi - a.hi; if (r != 0) { return r; } return a.lo - b.lo; } -Long.isNegative = function(a) { +Long_isNegative = function(a) { return a.hi < 0; } -Long.mul = function(a, b) { +Long_mul = function(a, b) { var a_lolo = a.lo & 0xFFFF; var a_lohi = a.lo >>> 16; var a_hilo = a.hi & 0xFFFF; @@ -309,38 +309,38 @@ Long.mul = function(a, b) { return new Long((lolo & 0xFFFF) | ((lohi & 0xFFFF) << 16), (hilo & 0xFFFF) | ((hihi & 0xFFFF) << 16)); } -Long.div = function(a, b) { +Long_div = function(a, b) { var result = (a.hi * 0x100000000 + a.lo) / (b.hi * 0x100000000 + b.lo); return new Long(result | 0, (result / 0x100000000) | 0); } -Long.rem = function(a, b) { +Long_rem = function(a, b) { var result = (a.hi * 0x100000000 + a.lo) % (b.hi * 0x100000000 + b.lo); return new Long(result | 0, (result / 0x100000000) | 0); } -Long.and = function(a, b) { +Long_and = function(a, b) { return new Long(a.lo & b.lo, a.hi & b.hi); } -Long.or = function(a, b) { +Long_or = function(a, b) { return new Long(a.lo | b.lo, a.hi | b.hi); } -Long.xor = function(a, b) { +Long_xor = function(a, b) { return new Long(a.lo ^ b.lo, a.hi ^ b.hi); } -Long.shl = function(a, b) { +Long_shl = function(a, b) { if (b < 32) { return new Long(a.lo << b, (a.lo >>> (32 - b)) | (a.hi << b)); } else { return new Long(0, a.lo << (b - 32)); } } -Long.shr = function(a, b) { +Long_shr = function(a, b) { if (b < 32) { return new Long((a.lo >>> b) | (a.hi << (32 - b)), a.hi >> b); } else { return new Long((a.hi >> (b - 32)), -1); } } -Long.shru = function(a, b) { +Long_shru = function(a, b) { if (b < 32) { return new Long((a.lo >>> b) | (a.hi << (32 - b)), a.hi >>> b); } else {