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 ebad4005b..cf2cd483e 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 @@ -216,6 +216,9 @@ public class TObject { @Rename("wait") public final void wait0(long timeout, int nanos, final AsyncCallback callback) { + if (!holdsLock(this)) { + throw new TIllegalMonitorStateException(); + } final NotifyListenerImpl listener = new NotifyListenerImpl(this, callback, monitor.count); monitor.notifyListeners.add(listener); if (timeout > 0 || nanos > 0) { diff --git a/teavm-core/src/main/java/org/teavm/javascript/Renderer.java b/teavm-core/src/main/java/org/teavm/javascript/Renderer.java index b28568e48..195cf3041 100644 --- a/teavm-core/src/main/java/org/teavm/javascript/Renderer.java +++ b/teavm-core/src/main/java/org/teavm/javascript/Renderer.java @@ -76,7 +76,7 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext try { MethodReference monitorEnterRef = new MethodReference( Object.class, "monitorEnter", Object.class, void.class); - writer.appendMethodBody(monitorEnterRef).append("("); + writer.append("return ").appendMethodBody(monitorEnterRef).append("("); statement.getObjectRef().acceptVisitor(this); writer.append(",").ws(); writer.append("$rt_continue($part_").append(statement.getAsyncTarget()).append(')'); diff --git a/teavm-platform/src/main/java/org/teavm/platform/plugin/AsyncMethodGenerator.java b/teavm-platform/src/main/java/org/teavm/platform/plugin/AsyncMethodGenerator.java index 68ae8a10a..d81151af1 100644 --- a/teavm-platform/src/main/java/org/teavm/platform/plugin/AsyncMethodGenerator.java +++ b/teavm-platform/src/main/java/org/teavm/platform/plugin/AsyncMethodGenerator.java @@ -39,12 +39,12 @@ public class AsyncMethodGenerator implements Generator, DependencyPlugin { public void generate(GeneratorContext context, SourceWriter writer, MethodReference methodRef) throws IOException { MethodReference asyncRef = getAsyncReference(methodRef); writer.append("var callback").ws().append("=").ws().append("function()").ws().append("{};").softNewLine(); - writer.append("callback.").appendMethod(completeMethod).ws().append("=").ws().append("function($this,").ws() - .append("val)").ws().append("{").indent().softNewLine(); + writer.append("callback.").appendMethod(completeMethod).ws().append("=").ws().append("function(val)").ws() + .append("{").indent().softNewLine(); writer.append("return $return($rt_asyncResult(val));").softNewLine(); writer.outdent().append("};").softNewLine(); - writer.append("callback.").appendMethod(errorMethod).ws().append("=").ws().append("function($this,").ws() - .append("e)").ws().append("{").indent().softNewLine(); + writer.append("callback.").appendMethod(errorMethod).ws().append("=").ws().append("function(e)").ws() + .append("{").indent().softNewLine(); writer.append("return $return($rt_asyncError(e));").softNewLine(); writer.outdent().append("};").softNewLine(); writer.append("try").ws().append("{").indent().softNewLine();