diff --git a/core/src/main/java/org/teavm/model/util/AsyncMethodFinder.java b/core/src/main/java/org/teavm/model/util/AsyncMethodFinder.java index 6ba1a3027..17578f62e 100644 --- a/core/src/main/java/org/teavm/model/util/AsyncMethodFinder.java +++ b/core/src/main/java/org/teavm/model/util/AsyncMethodFinder.java @@ -72,18 +72,8 @@ public class AsyncMethodFinder { if (asyncMethods.contains(method.getReference()) || method.getProgram() == null) { continue; } - if (method.hasModifier(ElementModifier.SYNCHRONIZED)) { + if (hasMonitor(method)) { add(method.getReference()); - continue; - } - ProgramReader program = method.getProgram(); - AsyncInstructionReader insnReader = new AsyncInstructionReader(); - for (int i = 0; i < program.basicBlockCount(); ++i) { - program.basicBlockAt(i).readAllInstructions(insnReader); - if (insnReader.async) { - add(method.getReference()); - break; - } } } } @@ -105,21 +95,36 @@ public class AsyncMethodFinder { } private boolean hasAsyncMethods() { - int count = asyncMethods.size(); - if (asyncMethods.contains(new MethodReference(Object.class, "monitorEnter", Object.class, void.class))) { - --count; - } - if (asyncMethods.contains(new MethodReference(Object.class, "monitorEnter", Object.class, - int.class, void.class))) { - --count; - } - if (asyncMethods.contains(new MethodReference(Object.class, "monitorEnterWait", Object.class, - int.class, void.class))) { - --count; + boolean result = false; + loop: for (String clsName : classSource.getClassNames()) { + ClassReader cls = classSource.get(clsName); + for (MethodReader method : cls.getMethods()) { + if (!asyncMethods.contains(method.getReference()) || method.getProgram() == null) { + continue; + } + if (hasMonitor(method)) { + break loop; + } + } } ClassReader cls = classSource.get("java.lang.Thread"); MethodReader method = cls != null ? cls.getMethod(new MethodDescriptor("start", void.class)) : null; - return count > 0 && method != null; + return result && method != null; + } + + private boolean hasMonitor(MethodReader method) { + if (method.hasModifier(ElementModifier.SYNCHRONIZED)) { + return true; + } + ProgramReader program = method.getProgram(); + AsyncInstructionReader insnReader = new AsyncInstructionReader(); + for (int i = 0; i < program.basicBlockCount(); ++i) { + program.basicBlockAt(i).readAllInstructions(insnReader); + if (insnReader.async) { + return true; + } + } + return false; } private void add(MethodReference methodRef) { diff --git a/html4j/src/main/java/org/teavm/html4j/JavaScriptConvGenerator.java b/html4j/src/main/java/org/teavm/html4j/JavaScriptConvGenerator.java index d3d462bda..d6efb07c7 100644 --- a/html4j/src/main/java/org/teavm/html4j/JavaScriptConvGenerator.java +++ b/html4j/src/main/java/org/teavm/html4j/JavaScriptConvGenerator.java @@ -138,7 +138,7 @@ public class JavaScriptConvGenerator implements Generator { writer.outdent().append("} else if (" + type + " === ").appendClass("java.lang.Character") .append(") {").indent().softNewLine(); writer.append("return ").appendMethodBody(valueOfCharMethod).append("(typeof " + obj + " === 'number' ? " - + obj + "0xFFFF : " + obj + ".charCodeAt(0));").softNewLine(); + + obj + " & 0xFFFF : " + obj + ".charCodeAt(0));").softNewLine(); writer.outdent().append("} else if (" + type + " === ").appendClass("java.lang.Byte") .append(") {").indent().softNewLine(); @@ -186,7 +186,7 @@ public class JavaScriptConvGenerator implements Generator { writer.append("return $rt_str(" + obj + ");").softNewLine(); writer.outdent().append("} else if (typeof " + obj + " === 'number') {").indent().softNewLine(); - writer.append("if (" + obj + "|0 === " + obj + ") {").indent().softNewLine(); + writer.append("if ((" + obj + "|0) === " + obj + ") {").indent().softNewLine(); writer.append("return ").appendMethodBody(valueOfIntMethod).append("(" + obj + ");").softNewLine(); writer.outdent().append("} else {").indent().softNewLine(); writer.append("return ").appendMethodBody(valueOfDoubleMethod).append("(" + obj + ");").softNewLine(); diff --git a/jso/apis/src/main/java/org/teavm/jso/browser/Window.java b/jso/apis/src/main/java/org/teavm/jso/browser/Window.java index 1309721f9..95c0ac276 100644 --- a/jso/apis/src/main/java/org/teavm/jso/browser/Window.java +++ b/jso/apis/src/main/java/org/teavm/jso/browser/Window.java @@ -93,7 +93,7 @@ public abstract class Window implements JSObject, WindowEventTarget, StorageProv return prompt(message, ""); } - @JSBody(params = { "message", "default" }, script = "prompt(message, default);") + @JSBody(params = { "message", "defaultValue" }, script = "prompt(message, defaultValue);") public static native String prompt(String message, String defaultValue); @JSBody(params = { "handler", "delay" }, script = "return setTimeout(handler, delay);")