diff --git a/teavm-classlib/pom.xml b/teavm-classlib/pom.xml
index a6a1a620b..ba62e29b3 100644
--- a/teavm-classlib/pom.xml
+++ b/teavm-classlib/pom.xml
@@ -85,8 +85,6 @@
process-test-classes
false
- true
- true
en, en_US, en_GB, ru, ru_RU
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLPlugin.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLPlugin.java
index 4f13a986d..4d3d853bb 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLPlugin.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/JCLPlugin.java
@@ -15,10 +15,9 @@
*/
package org.teavm.classlib.impl;
+import java.util.ServiceLoader;
import org.teavm.classlib.impl.unicode.CLDRReader;
-import org.teavm.model.MethodDescriptor;
import org.teavm.model.MethodReference;
-import org.teavm.model.ValueType;
import org.teavm.vm.spi.TeaVMHost;
import org.teavm.vm.spi.TeaVMPlugin;
@@ -36,9 +35,8 @@ public class JCLPlugin implements TeaVMPlugin {
host.add(new ObjectEnrichRenderer());
ServiceLoaderSupport serviceLoaderSupp = new ServiceLoaderSupport(host.getClassLoader());
host.add(serviceLoaderSupp);
- MethodReference loadServicesMethod = new MethodReference("java.util.ServiceLoader", new MethodDescriptor(
- "loadServices", ValueType.object("java.lang.Class"),
- ValueType.arrayOf(ValueType.object("java.lang.Object"))));
+ MethodReference loadServicesMethod = new MethodReference(ServiceLoader.class, "loadServices",
+ Class.class, Object[].class);
host.add(loadServicesMethod, serviceLoaderSupp);
JavacSupport javacSupport = new JavacSupport();
host.add(javacSupport);
diff --git a/teavm-classlib/src/main/java/org/teavm/classlib/impl/ServiceLoaderSupport.java b/teavm-classlib/src/main/java/org/teavm/classlib/impl/ServiceLoaderSupport.java
index 6510d90c6..3e96d4208 100644
--- a/teavm-classlib/src/main/java/org/teavm/classlib/impl/ServiceLoaderSupport.java
+++ b/teavm-classlib/src/main/java/org/teavm/classlib/impl/ServiceLoaderSupport.java
@@ -47,7 +47,7 @@ public class ServiceLoaderSupport implements Generator, DependencyListener {
public void generate(GeneratorContext context, SourceWriter writer, MethodReference methodRef) throws IOException {
writer.append("if (!").appendClass("java.util.ServiceLoader").append(".$$services$$) {").indent()
.softNewLine();
- writer.appendClass("java.util.ServiceLoader").append("$$services$$ = true;").softNewLine();
+ writer.appendClass("java.util.ServiceLoader").append(".$$services$$ = true;").softNewLine();
for (Map.Entry> entry : serviceMap.entrySet()) {
writer.appendClass(entry.getKey()).append(".$$serviceList$$ = [");
List implementations = entry.getValue();
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 442d54826..a7c2f917b 100644
--- a/teavm-core/src/main/java/org/teavm/javascript/Renderer.java
+++ b/teavm-core/src/main/java/org/teavm/javascript/Renderer.java
@@ -540,16 +540,23 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
for (int var : method.getVariables()) {
variableCount = Math.max(variableCount, var + 1);
}
- boolean hasVars = variableCount > ref.parameterCount() + 1;
- if (hasVars) {
+ TryCatchFinder tryCatchFinder = new TryCatchFinder();
+ method.getBody().acceptVisitor(tryCatchFinder);
+ boolean hasTryCatch = tryCatchFinder.tryCatchFound;
+ List variableNames = new ArrayList<>();
+ for (int i = ref.parameterCount() + 1; i < variableCount; ++i) {
+ variableNames.add(variableName(i));
+ }
+ if (hasTryCatch) {
+ variableNames.add("$je");
+ }
+ if (!variableNames.isEmpty()) {
writer.append("var ");
- boolean first = true;
- for (int i = ref.parameterCount() + 1; i < variableCount; ++i) {
- if (!first) {
+ for (int i = 0; i < variableNames.size(); ++i) {
+ if (i > 0) {
writer.append(",").ws();
}
- first = false;
- writer.append(variableName(i));
+ writer.append(variableNames.get(i));
}
writer.append(";").softNewLine();
}
diff --git a/teavm-core/src/main/java/org/teavm/javascript/TryCatchFinder.java b/teavm-core/src/main/java/org/teavm/javascript/TryCatchFinder.java
new file mode 100644
index 000000000..1c53f647f
--- /dev/null
+++ b/teavm-core/src/main/java/org/teavm/javascript/TryCatchFinder.java
@@ -0,0 +1,113 @@
+/*
+ * Copyright 2014 Alexey Andreev.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.teavm.javascript;
+
+import java.util.List;
+import org.teavm.javascript.ast.*;
+
+/**
+ *
+ * @author Alexey Andreev
+ */
+class TryCatchFinder implements StatementVisitor {
+ public boolean tryCatchFound;
+
+ @Override
+ public void visit(AssignmentStatement statement) {
+ }
+
+ private void visitSequence(List statements) {
+ if (tryCatchFound) {
+ return;
+ }
+ for (Statement statement : statements) {
+ statement.acceptVisitor(this);
+ if (tryCatchFound) {
+ return;
+ }
+ }
+ }
+
+ @Override
+ public void visit(SequentialStatement statement) {
+ if (tryCatchFound) {
+ return;
+ }
+ visitSequence(statement.getSequence());
+ }
+
+ @Override
+ public void visit(ConditionalStatement statement) {
+ if (tryCatchFound) {
+ return;
+ }
+ visitSequence(statement.getConsequent());
+ visitSequence(statement.getAlternative());
+ }
+
+ @Override
+ public void visit(SwitchStatement statement) {
+ if (tryCatchFound) {
+ return;
+ }
+ for (SwitchClause clause : statement.getClauses()) {
+ visitSequence(clause.getBody());
+ if (tryCatchFound) {
+ return;
+ }
+ }
+ visitSequence(statement.getDefaultClause());
+ }
+
+ @Override
+ public void visit(WhileStatement statement) {
+ if (!tryCatchFound) {
+ visitSequence(statement.getBody());
+ }
+ }
+
+ @Override
+ public void visit(BlockStatement statement) {
+ if (!tryCatchFound) {
+ visitSequence(statement.getBody());
+ }
+ }
+
+ @Override
+ public void visit(BreakStatement statement) {
+ }
+
+ @Override
+ public void visit(ContinueStatement statement) {
+ }
+
+ @Override
+ public void visit(ReturnStatement statement) {
+ }
+
+ @Override
+ public void visit(ThrowStatement statement) {
+ }
+
+ @Override
+ public void visit(InitClassStatement statement) {
+ }
+
+ @Override
+ public void visit(TryCatchStatement statement) {
+ tryCatchFound = true;
+ }
+}
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 bdc6a4fcd..812a78191 100644
--- a/teavm-core/src/main/java/org/teavm/vm/TeaVM.java
+++ b/teavm-core/src/main/java/org/teavm/vm/TeaVM.java
@@ -434,10 +434,10 @@ public class TeaVM implements TeaVMHost, ServiceRepository {
renderer.addInjector(entry.getKey(), entry.getValue());
}
try {
- sourceWriter.append("\"use strict\"").newLine();
for (RendererListener listener : rendererListeners) {
listener.begin(renderer, target);
}
+ sourceWriter.append("\"use strict\";").newLine();
renderer.renderRuntime();
for (ClassNode clsNode : clsNodes) {
ClassReader cls = classSet.get(clsNode.getName());
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 493b3760b..9b5300490 100644
--- a/teavm-core/src/main/resources/org/teavm/javascript/runtime.js
+++ b/teavm-core/src/main/resources/org/teavm/javascript/runtime.js
@@ -72,7 +72,7 @@ if (ArrayBuffer) {
return new ($rt_arraycls(cls))(nativeArray);
};
$rt_createCharArray = function(sz) {
- return $rt_createNumericArray($rt_bytecls(), new Uint16Array(new ArrayBuffer(sz << 1)), 0);
+ return $rt_createNumericArray($rt_charcls(), new Uint16Array(new ArrayBuffer(sz << 1)), 0);
};
$rt_createByteArray = function(sz) {
return $rt_createNumericArray($rt_bytecls(), new Int8Array(new ArrayBuffer(sz)), 0);
diff --git a/teavm-platform/src/main/java/org/teavm/platform/plugin/MetadataProviderNativeGenerator.java b/teavm-platform/src/main/java/org/teavm/platform/plugin/MetadataProviderNativeGenerator.java
index da0dd8740..6ddda44ca 100644
--- a/teavm-platform/src/main/java/org/teavm/platform/plugin/MetadataProviderNativeGenerator.java
+++ b/teavm-platform/src/main/java/org/teavm/platform/plugin/MetadataProviderNativeGenerator.java
@@ -77,7 +77,7 @@ public class MetadataProviderNativeGenerator implements Generator {
Resource resource = generator.generateMetadata(metadataContext, methodRef);
writer.append("if (!window.hasOwnProperty(\"").appendMethodBody(methodRef).append("$$resource\")) {")
.indent().softNewLine();
- writer.appendMethodBody(methodRef).append("$$resource = ");
+ writer.append("window.").appendMethodBody(methodRef).append("$$resource = ");
ResourceWriterHelper.write(writer, resource);
writer.append(';').softNewLine();
writer.outdent().append('}').softNewLine();