diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TObject.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TObject.java index b248f7fe5..ff36c71c8 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TObject.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TObject.java @@ -64,8 +64,9 @@ public class TObject { .getPlatformClass().getMetadata().getArrayItem() == null) { throw new TCloneNotSupportedException(); } - Platform.getPlatformObject(this).setId(Platform.nextObjectId()); - return Platform.clone(this); + Object result = Platform.clone(this); + Platform.getPlatformObject(result).setId(Platform.nextObjectId()); + return result; } @Rename("notify") diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TSystem.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TSystem.java index 6115017d3..f0a2f2a24 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TSystem.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/lang/TSystem.java @@ -47,6 +47,15 @@ public final class TSystem extends TObject { } if (srcType != targetType) { if (!srcType.isPrimitive() && !targetType.isPrimitive()) { + Object[] srcArray = (Object[])(Object)src; + int pos = srcPos; + for (int i = 0; i < length; ++i) { + Object elem = srcArray[pos++]; + if (!targetType.isInstance(elem)) { + doArrayCopy(src, srcPos, dest, destPos, i); + throw new TArrayStoreException(); + } + } doArrayCopy(src, srcPos, dest, destPos, length); return; } else if (!srcType.isPrimitive() || !targetType.isPrimitive()) { diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/THashMap.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/THashMap.java index 4c2b2973d..7237ada87 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/THashMap.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/THashMap.java @@ -35,13 +35,10 @@ package org.teavm.classlib.java.util; import java.util.Arrays; import java.util.ConcurrentModificationException; import org.teavm.classlib.java.io.TSerializable; -import org.teavm.classlib.java.lang.TCloneNotSupportedException; -import org.teavm.classlib.java.lang.TIllegalArgumentException; -import org.teavm.classlib.java.lang.TIllegalStateException; -import org.teavm.classlib.java.lang.TObject; +import org.teavm.classlib.java.lang.*; import org.teavm.javascript.spi.Rename; -public class THashMap extends TAbstractMap implements TSerializable { +public class THashMap extends TAbstractMap implements TCloneable, TSerializable { transient int elementCount; transient HashEntry[] elementData; transient int modCount = 0; diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/regex/TDecomposedCharSet.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/regex/TDecomposedCharSet.java index b1248adca..527101722 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/regex/TDecomposedCharSet.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/regex/TDecomposedCharSet.java @@ -109,7 +109,7 @@ class TDecomposedCharSet extends TJointSet { * Read testString until we met a decomposed char boundary and * decompose obtained portion of testString */ - while ((readCodePoints < TLexer.MAX_DECOMPOSITION_LENGTH) && !TLexer.isDecomposedCharBoundary(curChar)) { + while ((readCodePoints < TLexer.MAX_DECOMPOSITION_LENGTH)) { if (TLexer.hasDecompositionNonNullCanClass(curChar)) { @@ -146,30 +146,6 @@ class TDecomposedCharSet extends TJointSet { } } - /* - * Some optimization since length of decomposed char is <= 3 usually - */ - switch (readCodePoints) { - case 0: - case 1: - case 2: - break; - - case 3: - int i1 = TLexer.getCanonicalClass(decCodePoint[1]); - int i2 = TLexer.getCanonicalClass(decCodePoint[2]); - - if ((i2 != 0) && (i1 > i2)) { - i1 = decCodePoint[1]; - decCodePoint[1] = decCodePoint[2]; - decCodePoint[2] = i1; - } - break; - - default: - decCodePoint = TLexer.getCanonicalOrder(decCodePoint, readCodePoints); - } - /* * Compare decomposedChar with decomposed char that was just read from * testString diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/regex/TLexer.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/regex/TLexer.java index 4c4dde32f..4b344dae8 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/regex/TLexer.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/regex/TLexer.java @@ -146,12 +146,6 @@ class TLexer { // table that contains canonical decomposition mappings private static TIntArrHash decompTable = null; - - // table that contains canonical combining classes - private static TIntHash canonClassesTable = null; - - private static int canonClassesTableSize; - /* * Table that contains information about Unicode codepoints with single * codepoint decomposition @@ -330,51 +324,6 @@ class TLexer { return input; } - /** - * Rearrange codepoints according to canonical order. - * - * @param inputInts - * - array that contains Unicode codepoints - * @param length - * - index of last Unicode codepoint plus 1 - * - * @return array that contains rearranged codepoints. - */ - static int[] getCanonicalOrder(int[] inputInts, int length) { - int inputLength = (length < inputInts.length) ? length : inputInts.length; - - /* - * Simple bubble-sort algorithm. Note that many codepoints have 0 - * canonical class, so this algorithm works almost lineary in - * overwhelming majority of cases. This is due to specific of Unicode - * combining classes and codepoints. - */ - for (int i = 1; i < inputLength; i++) { - int j = i - 1; - int iCanonicalClass = getCanonicalClass(inputInts[i]); - int ch; - - if (iCanonicalClass == 0) { - continue; - } - - while (j > -1) { - if (getCanonicalClass(inputInts[j]) > iCanonicalClass) { - j = j - 1; - } else { - break; - } - } - - ch = inputInts[i]; - for (int k = i; k > j + 1; k--) { - inputInts[k] = inputInts[k - 1]; - } - inputInts[j + 1] = ch; - } - - return inputInts; - } /** * Reread current character, may be require if previous token changes mode @@ -1062,20 +1011,6 @@ class TLexer { } } - /** - * Gets canonical class for given codepoint from decomposition mappings - * table. - * - * @param - ch Unicode codepoint - * @return canonical class for given Unicode codepoint that is represented - * by ch. - */ - static int getCanonicalClass(int ch) { - int canClass = canonClassesTable.get(ch); - - return (canClass == canonClassesTableSize) ? 0 : canClass; - } - /** * Tests if given codepoint is a canonical decomposition of another * codepoint. @@ -1126,23 +1061,6 @@ class TLexer { return high; } - /** - * Tests Unicode codepoint if it is a boundary of decomposed Unicode - * codepoint. - * - * @param ch - * - Unicode codepoint to test - * @return true if given codepoint is a boundary. - */ - static boolean isDecomposedCharBoundary(int ch) { - int canClass = canonClassesTable.get(ch); - - // Lexer.getCanonicalClass(ch) == 0 - boolean isBoundary = (canClass == canonClassesTableSize); - - return isBoundary; - } - /** * Returns the curr. character index. */ diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/regex/TPattern.java b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/regex/TPattern.java index 34b373310..0c534a71e 100644 --- a/teavm-classlib/src/main/java/org/teavm/classlib/java/util/regex/TPattern.java +++ b/teavm-classlib/src/main/java/org/teavm/classlib/java/util/regex/TPattern.java @@ -561,8 +561,7 @@ public final class TPattern implements Serializable { } else { readCodePoints++; - while ((readCodePoints < TLexer.MAX_DECOMPOSITION_LENGTH) && !lexemes.isEmpty() && lexemes.isLetter() && - !TLexer.isDecomposedCharBoundary(lexemes.peek())) { + while ((readCodePoints < TLexer.MAX_DECOMPOSITION_LENGTH) && !lexemes.isEmpty() && lexemes.isLetter()) { codePoints[readCodePoints++] = lexemes.next(); } 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 aa30330b7..8657d88c3 100644 --- a/teavm-core/src/main/resources/org/teavm/javascript/runtime.js +++ b/teavm-core/src/main/resources/org/teavm/javascript/runtime.js @@ -383,6 +383,7 @@ function $rt_declClass(cls, data) { m.binaryName = "L" + data.name + ";"; m.enum = data.enum; m.item = null; + m.primitive = false; cls.prototype.constructor = cls; cls.classObject = null; cls.$clinit = data.clinit ? data.clinit : function() {}; diff --git a/teavm-platform/src/main/java/org/teavm/platform/PlatformConsole.java b/teavm-platform/src/main/java/org/teavm/platform/PlatformConsole.java index 2db3a7a7f..376724ff4 100644 --- a/teavm-platform/src/main/java/org/teavm/platform/PlatformConsole.java +++ b/teavm-platform/src/main/java/org/teavm/platform/PlatformConsole.java @@ -23,9 +23,9 @@ import org.teavm.jso.JSObject; * @author Alexey Andreev */ public interface PlatformConsole extends JSObject { - @JSMethod("rt_putStdout") + @JSMethod("$rt_putStdout") void output(int b); - @JSMethod("rt_putStderr") + @JSMethod("$rt_putStderr") void error(int b); } diff --git a/teavm-platform/src/main/java/org/teavm/platform/plugin/PlatformGenerator.java b/teavm-platform/src/main/java/org/teavm/platform/plugin/PlatformGenerator.java index 5d812c02f..ac744de90 100644 --- a/teavm-platform/src/main/java/org/teavm/platform/plugin/PlatformGenerator.java +++ b/teavm-platform/src/main/java/org/teavm/platform/plugin/PlatformGenerator.java @@ -38,7 +38,7 @@ public class PlatformGenerator implements Generator, Injector, DependencyPlugin method.getResult().propagate(agent.getType("java.lang.Class")); return; case "clone": - method.getVariable(0).connect(method.getResult()); + method.getVariable(1).connect(method.getResult()); break; } }