From b4c3bc47f0a4e90b912d98ba0f98bb033b12c255 Mon Sep 17 00:00:00 2001 From: konsoletyper Date: Sun, 15 Feb 2015 19:40:49 +0400 Subject: [PATCH] Fix tests --- teavm-core/src/main/java/org/teavm/vm/TeaVM.java | 2 +- .../main/resources/org/teavm/javascript/runtime.js | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/teavm-core/src/main/java/org/teavm/vm/TeaVM.java b/teavm-core/src/main/java/org/teavm/vm/TeaVM.java index d451337b7..08b119247 100644 --- a/teavm-core/src/main/java/org/teavm/vm/TeaVM.java +++ b/teavm-core/src/main/java/org/teavm/vm/TeaVM.java @@ -438,7 +438,7 @@ public class TeaVM implements TeaVMHost, ServiceRepository { sourceWriter.append("var ").append(entry.getKey()).ws().append("=").ws(); boolean wrapAsync = !asyncMethods.contains(entry.getValue().reference) && entry.getValue().isAsync(); if (wrapAsync) { - sourceWriter.append("$rt_asyncAdapter("); + sourceWriter.append("$rt_staticAsyncAdapter("); } sourceWriter.appendMethodBody(entry.getValue().reference); if (wrapAsync) { 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 d81aeb0fa..8b358abe8 100644 --- a/teavm-core/src/main/resources/org/teavm/javascript/runtime.js +++ b/teavm-core/src/main/resources/org/teavm/javascript/runtime.js @@ -459,6 +459,19 @@ function $rt_asyncError(e) { throw e; } } +function $rt_staticAsyncAdapter(f) { + return function() { + var result; + var args = Array.prototype.slice.apply(arguments); + var $return = args.pop(); + try { + result = f.apply(this, args); + } catch (e) { + return $return($rt_asyncError(e)); + } + return $return($rt_asyncResult(result)); + } +} function $rt_asyncAdapter(f) { return function() { var result;