diff --git a/core/src/main/java/org/teavm/backend/javascript/codegen/OutputSourceWriter.java b/core/src/main/java/org/teavm/backend/javascript/codegen/OutputSourceWriter.java index 3c7000128..03e256e56 100644 --- a/core/src/main/java/org/teavm/backend/javascript/codegen/OutputSourceWriter.java +++ b/core/src/main/java/org/teavm/backend/javascript/codegen/OutputSourceWriter.java @@ -197,6 +197,20 @@ public class OutputSourceWriter extends SourceWriter implements LocationProvider return this; } + @Override + public SourceWriter sameLineWs() { + if (!minified) { + try { + innerWriter.append(' '); + } catch (IOException e) { + throw new RuntimeException(e); + } + column++; + offset++; + } + return this; + } + @Override public SourceWriter tokenBoundary() { if (column >= lineWidth) { diff --git a/core/src/main/java/org/teavm/backend/javascript/codegen/RememberedSource.java b/core/src/main/java/org/teavm/backend/javascript/codegen/RememberedSource.java index 288306885..38afa7e70 100644 --- a/core/src/main/java/org/teavm/backend/javascript/codegen/RememberedSource.java +++ b/core/src/main/java/org/teavm/backend/javascript/codegen/RememberedSource.java @@ -139,6 +139,12 @@ public class RememberedSource implements SourceFragment { } break; + case RememberingSourceWriter.SAME_LINE_WS: + if ((filter & FILTER_TEXT) != 0) { + sink.sameLineWs(); + } + break; + case RememberingSourceWriter.TOKEN_BOUNDARY: if ((filter & FILTER_TEXT) != 0) { sink.tokenBoundary(); diff --git a/core/src/main/java/org/teavm/backend/javascript/codegen/RememberingSourceWriter.java b/core/src/main/java/org/teavm/backend/javascript/codegen/RememberingSourceWriter.java index ee97fa2cd..29e67c704 100644 --- a/core/src/main/java/org/teavm/backend/javascript/codegen/RememberingSourceWriter.java +++ b/core/src/main/java/org/teavm/backend/javascript/codegen/RememberingSourceWriter.java @@ -37,6 +37,7 @@ public class RememberingSourceWriter extends SourceWriter { static final byte CLASS_INIT = 8; static final byte NEW_LINE = 9; static final byte WS = 10; + static final byte SAME_LINE_WS = 21; static final byte TOKEN_BOUNDARY = 11; static final byte SOFT_NEW_LINE = 12; static final byte INDENT = 13; @@ -184,6 +185,13 @@ public class RememberingSourceWriter extends SourceWriter { return this; } + @Override + public SourceWriter sameLineWs() { + flush(); + commands.add(SAME_LINE_WS); + return this; + } + @Override public SourceWriter tokenBoundary() { flush(); diff --git a/core/src/main/java/org/teavm/backend/javascript/codegen/SourceWriter.java b/core/src/main/java/org/teavm/backend/javascript/codegen/SourceWriter.java index d5429adb6..c18d55a05 100644 --- a/core/src/main/java/org/teavm/backend/javascript/codegen/SourceWriter.java +++ b/core/src/main/java/org/teavm/backend/javascript/codegen/SourceWriter.java @@ -111,6 +111,9 @@ public abstract class SourceWriter implements Appendable, SourceWriterSink { @Override public abstract SourceWriter ws(); + @Override + public abstract SourceWriter sameLineWs(); + @Override public abstract SourceWriter tokenBoundary(); diff --git a/core/src/main/java/org/teavm/backend/javascript/codegen/SourceWriterSink.java b/core/src/main/java/org/teavm/backend/javascript/codegen/SourceWriterSink.java index 30031bff3..6ca617597 100644 --- a/core/src/main/java/org/teavm/backend/javascript/codegen/SourceWriterSink.java +++ b/core/src/main/java/org/teavm/backend/javascript/codegen/SourceWriterSink.java @@ -68,6 +68,10 @@ public interface SourceWriterSink { return this; } + default SourceWriterSink sameLineWs() { + return this; + } + default SourceWriterSink tokenBoundary() { return this; } diff --git a/core/src/main/java/org/teavm/backend/javascript/rendering/AstWriter.java b/core/src/main/java/org/teavm/backend/javascript/rendering/AstWriter.java index de80d2a3d..d5e2503cd 100644 --- a/core/src/main/java/org/teavm/backend/javascript/rendering/AstWriter.java +++ b/core/src/main/java/org/teavm/backend/javascript/rendering/AstWriter.java @@ -738,12 +738,14 @@ public class AstWriter { if (!isArrow || node.getParams().size() != 1) { writer.append('('); printList(node.getParams()); - writer.append(')').ws(); + writer.append(')'); } else { print(node.getParams().get(0)); } if (isArrow) { - writer.append("=>").ws(); + writer.sameLineWs().append("=>").ws(); + } else { + writer.ws(); } if (node.isExpressionClosure()) { diff --git a/core/src/main/java/org/teavm/backend/javascript/rendering/MethodBodyRenderer.java b/core/src/main/java/org/teavm/backend/javascript/rendering/MethodBodyRenderer.java index 35b48231d..58e19383c 100644 --- a/core/src/main/java/org/teavm/backend/javascript/rendering/MethodBodyRenderer.java +++ b/core/src/main/java/org/teavm/backend/javascript/rendering/MethodBodyRenderer.java @@ -126,12 +126,19 @@ public class MethodBodyRenderer implements MethodNodeVisitor, GeneratorContext { if (modifiers.contains(ElementModifier.STATIC)) { startParam = 1; } + var count = reference.parameterCount() - startParam + 1; + if (count != 1) { + writer.append("("); + } for (int i = startParam; i <= reference.parameterCount(); ++i) { if (i > startParam) { writer.append(",").ws(); } writer.append(statementRenderer.variableName(i)); } + if (count != 1) { + writer.append(")"); + } parameters = writer.save(); writer.clear(); } @@ -165,7 +172,7 @@ public class MethodBodyRenderer implements MethodNodeVisitor, GeneratorContext { variableNames.add("$$je"); } if (!variableNames.isEmpty()) { - writer.append("var "); + writer.append("let "); for (int i = 0; i < variableNames.size(); ++i) { if (i > 0) { writer.append(",").ws(); @@ -227,7 +234,7 @@ public class MethodBodyRenderer implements MethodNodeVisitor, GeneratorContext { } variableNames.add(context.pointerName()); variableNames.add(context.tempVarName()); - writer.append("var "); + writer.append("let "); for (int i = 0; i < variableNames.size(); ++i) { if (i > 0) { writer.append(",").ws(); @@ -246,7 +253,7 @@ public class MethodBodyRenderer implements MethodNodeVisitor, GeneratorContext { writer.append(context.pointerName()).ws().append('=').ws().append("0;").softNewLine(); writer.append("if").ws().append("(").appendFunction("$rt_resuming").append("())").ws() .append("{").indent().softNewLine(); - writer.append("var ").append(context.threadName()).ws().append('=').ws() + writer.append("let ").append(context.threadName()).ws().append('=').ws() .appendFunction("$rt_nativeThread").append("();").softNewLine(); writer.append(context.pointerName()).ws().append('=').ws().append(context.threadName()).append(".") .append(popName).append("();"); diff --git a/core/src/main/java/org/teavm/backend/javascript/rendering/Renderer.java b/core/src/main/java/org/teavm/backend/javascript/rendering/Renderer.java index 710b163e1..a2101b8b2 100644 --- a/core/src/main/java/org/teavm/backend/javascript/rendering/Renderer.java +++ b/core/src/main/java/org/teavm/backend/javascript/rendering/Renderer.java @@ -184,7 +184,7 @@ public class Renderer implements RenderingManager { private void renderJavaStringToString() { writer.appendClass("java.lang.String").append(".prototype.toString").ws().append("=").ws().append("()") - .ws().append("=>").ws().append("{").indent().softNewLine(); + .sameLineWs().append("=>").ws().append("{").indent().softNewLine(); writer.append("return ").appendFunction("$rt_ustr").append("(this);").softNewLine(); writer.outdent().append("};").newLine(); writer.appendClass("java.lang.String").append(".prototype.valueOf").ws().append("=").ws() @@ -193,7 +193,7 @@ public class Renderer implements RenderingManager { private void renderJavaObjectToString() { writer.appendClass("java.lang.Object").append(".prototype.toString").ws().append("=").ws() - .append("()").ws().append("=>").ws().append("{").indent().softNewLine(); + .append("()").sameLineWs().append("=>").ws().append("{").indent().softNewLine(); writer.append("return ").appendFunction("$rt_ustr").append("(") .appendMethodBody(Object.class, "toString", String.class).append("(this));") .softNewLine(); @@ -274,7 +274,7 @@ public class Renderer implements RenderingManager { if (fieldName.scoped) { writer.append(naming.getScopeName()).append("."); } else { - writer.append("var "); + writer.append("let "); } writer.append(fieldName.value).ws().append("=").ws(); context.constantToString(writer, value); @@ -289,7 +289,7 @@ public class Renderer implements RenderingManager { writer.append("()").ws().append("{").indent().softNewLine(); if (nonStaticFields.size() > 1) { thisAliased = true; - writer.append("var a").ws().append("=").ws().append("this;").ws(); + writer.append("let a").ws().append("=").ws().append("this;").ws(); } if (!cls.getClassHolder().getModifiers().contains(ElementModifier.INTERFACE) && cls.getParentName() != null) { @@ -324,7 +324,7 @@ public class Renderer implements RenderingManager { if (jsName.scoped) { writer.append(naming.getScopeName()).append("."); } else { - writer.append("var "); + writer.append("let "); } writer.append(jsName.value).ws().append("=").ws().appendFunction("$rt_classWithoutFields").append("("); if (cls.getClassHolder().hasModifier(ElementModifier.INTERFACE)) { @@ -368,15 +368,15 @@ public class Renderer implements RenderingManager { String clinitCalled = (className.scoped ? naming.getScopeName() + "_" : "") + className.value + "_$clinitCalled"; if (isAsync) { - writer.append("var ").append(clinitCalled).ws().append("=").ws().append("false;").softNewLine(); + writer.append("let ").append(clinitCalled).ws().append("=").ws().append("false;").softNewLine(); } ScopedName name = naming.getNameForClassInit(cls.getName()); - renderFunctionDeclaration(name); - writer.append("()").ws().append("{").softNewLine().indent(); + renderLambdaDeclaration(name); + writer.append("()").sameLineWs().append("=>").ws().append("{").softNewLine().indent(); if (isAsync) { - writer.append("var ").append(context.pointerName()).ws().append("=").ws() + writer.append("let ").append(context.pointerName()).ws().append("=").ws() .append("0").append(";").softNewLine(); writer.append("if").ws().append("(").appendFunction("$rt_resuming").append("())").ws().append("{") .indent().softNewLine(); @@ -690,18 +690,23 @@ public class Renderer implements RenderingManager { MethodReference ref = method.reference; debugEmitter.emitMethod(ref.getDescriptor()); ScopedName name = naming.getNameForInit(ref); - renderFunctionDeclaration(name); - writer.append("("); + renderLambdaDeclaration(name); + if (ref.parameterCount() != 1) { + writer.append("("); + } for (int i = 0; i < ref.parameterCount(); ++i) { if (i > 0) { writer.append(",").ws(); } writer.append(variableNameForInitializer(i)); } - writer.append(")").ws().append("{").softNewLine().indent(); + if (ref.parameterCount() != 1) { + writer.append(")"); + } + writer.sameLineWs().append("=>").ws().append("{").softNewLine().indent(); String instanceName = variableNameForInitializer(ref.parameterCount()); - writer.append("var " + instanceName).ws().append("=").ws().append("new ").appendClass( + writer.append("let " + instanceName).ws().append("=").ws().append("new ").appendClass( ref.getClassName()).append("();").softNewLine(); writer.appendMethodBody(ref).append("(" + instanceName); for (int i = 0; i < ref.parameterCount(); ++i) { @@ -787,15 +792,14 @@ public class Renderer implements RenderingManager { debugEmitter.emitMethod(ref.getDescriptor()); ScopedName name = naming.getFullNameFor(ref); - renderFunctionDeclaration(name); - writer.append("("); + renderLambdaDeclaration(name); method.parameters.replay(writer, RememberedSource.FILTER_ALL); if (method.variables != null) { for (var variable : method.variables) { variable.emit(debugEmitter); } } - writer.append(")").ws().append("{").indent().softNewLine(); + writer.sameLineWs().append("=>").ws().append("{").indent().softNewLine(); method.body.replay(writer, RememberedSource.FILTER_ALL); writer.outdent().append("}"); @@ -807,6 +811,15 @@ public class Renderer implements RenderingManager { debugEmitter.emitMethod(null); } + private void renderLambdaDeclaration(ScopedName name) { + if (name.scoped) { + writer.append(naming.getScopeName()).append(".").append(name.value); + } else { + writer.append("let ").append(name.value); + } + writer.ws().append("=").ws(); + } + private void renderFunctionDeclaration(ScopedName name) { if (name.scoped) { writer.append(naming.getScopeName()).append(".").append(name.value).ws().append("=").ws(); diff --git a/core/src/main/resources/org/teavm/backend/javascript/array.js b/core/src/main/resources/org/teavm/backend/javascript/array.js index cd728109f..64235d3f9 100644 --- a/core/src/main/resources/org/teavm/backend/javascript/array.js +++ b/core/src/main/resources/org/teavm/backend/javascript/array.js @@ -14,11 +14,11 @@ * limitations under the License. */ -var $rt_booleanArrayCls = $rt_arraycls($rt_booleancls); -var $rt_charArrayCls = $rt_arraycls($rt_charcls); -var $rt_byteArrayCls = $rt_arraycls($rt_bytecls); -var $rt_shortArrayCls = $rt_arraycls($rt_shortcls); -var $rt_intArrayCls = $rt_arraycls($rt_intcls); -var $rt_longArrayCls = $rt_arraycls($rt_longcls); -var $rt_floatArrayCls = $rt_arraycls($rt_floatcls); -var $rt_doubleArrayCls = $rt_arraycls($rt_doublecls); \ No newline at end of file +let $rt_booleanArrayCls = $rt_arraycls($rt_booleancls); +let $rt_charArrayCls = $rt_arraycls($rt_charcls); +let $rt_byteArrayCls = $rt_arraycls($rt_bytecls); +let $rt_shortArrayCls = $rt_arraycls($rt_shortcls); +let $rt_intArrayCls = $rt_arraycls($rt_intcls); +let $rt_longArrayCls = $rt_arraycls($rt_longcls); +let $rt_floatArrayCls = $rt_arraycls($rt_floatcls); +let $rt_doubleArrayCls = $rt_arraycls($rt_doublecls); \ No newline at end of file diff --git a/core/src/main/resources/org/teavm/backend/javascript/intern.js b/core/src/main/resources/org/teavm/backend/javascript/intern.js index 1e4bccd47..dbd95c4e0 100644 --- a/core/src/main/resources/org/teavm/backend/javascript/intern.js +++ b/core/src/main/resources/org/teavm/backend/javascript/intern.js @@ -15,21 +15,21 @@ */ "use strict"; -var $rt_intern +let $rt_intern if (teavm_javaMethodExists("java.lang.String", "intern()Ljava/lang/String;")) { $rt_intern = function() { - var map = teavm_globals.Object.create(null); + let map = teavm_globals.Object.create(null); - var get; + let get; if (typeof teavm_globals.WeakRef !== 'undefined') { - var registry = new teavm_globals.FinalizationRegistry(value => { + let registry = new teavm_globals.FinalizationRegistry(value => { delete map[value]; }); - get = function (str) { - var key = $rt_ustr(str); - var ref = map[key]; - var result = typeof ref !== 'undefined' ? ref.deref() : void 0; + get = str => { + let key = $rt_ustr(str); + let ref = map[key]; + let result = typeof ref !== 'undefined' ? ref.deref() : void 0; if (typeof result !== 'object') { result = str; map[key] = new teavm_globals.WeakRef(result); @@ -38,9 +38,9 @@ if (teavm_javaMethodExists("java.lang.String", "intern()Ljava/lang/String;")) { return result; } } else { - get = function (str) { - var key = $rt_ustr(str); - var result = map[key]; + get = str => { + let key = $rt_ustr(str); + let result = map[key]; if (typeof result !== 'object') { result = str; map[key] = result; @@ -52,7 +52,5 @@ if (teavm_javaMethodExists("java.lang.String", "intern()Ljava/lang/String;")) { return get; }(); } else { - $rt_intern = function(str) { - return str; - } + $rt_intern = str => str; } \ No newline at end of file diff --git a/core/src/main/resources/org/teavm/backend/javascript/long.js b/core/src/main/resources/org/teavm/backend/javascript/long.js index b63261ad5..157198c75 100644 --- a/core/src/main/resources/org/teavm/backend/javascript/long.js +++ b/core/src/main/resources/org/teavm/backend/javascript/long.js @@ -15,167 +15,161 @@ */ "use strict"; -var Long_eq; -var Long_ne; -var Long_gt; -var Long_ge; -var Long_lt; -var Long_le; -var Long_compare; -var Long_ucompare; -var Long_add; -var Long_sub; -var Long_inc; -var Long_dec; -var Long_mul; -var Long_div; -var Long_rem; -var Long_udiv; -var Long_urem; -var Long_neg; -var Long_and; -var Long_or; -var Long_xor; -var Long_shl; -var Long_shr; -var Long_shru; -var Long_not; +let Long_eq; +let Long_ne; +let Long_gt; +let Long_ge; +let Long_lt; +let Long_le; +let Long_compare; +let Long_ucompare; +let Long_add; +let Long_sub; +let Long_inc; +let Long_dec; +let Long_mul; +let Long_div; +let Long_rem; +let Long_udiv; +let Long_urem; +let Long_neg; +let Long_and; +let Long_or; +let Long_xor; +let Long_shl; +let Long_shr; +let Long_shru; +let Long_not; if (typeof teavm_globals.BigInt !== 'function') { - Long_eq = function(a, b) { - return a.hi === b.hi && a.lo === b.lo; - } + Long_eq = (a, b) => a.hi === b.hi && a.lo === b.lo; - Long_ne = function(a, b) { - return a.hi !== b.hi || a.lo !== b.lo; - } + Long_ne = (a, b) => a.hi !== b.hi || a.lo !== b.lo; - Long_gt = function(a, b) { + Long_gt = (a, b) => { if (a.hi < b.hi) { return false; } if (a.hi > b.hi) { return true; } - var x = a.lo >>> 1; - var y = b.lo >>> 1; + let x = a.lo >>> 1; + let y = b.lo >>> 1; if (x !== y) { return x > y; } return (a.lo & 1) > (b.lo & 1); } - Long_ge = function(a, b) { + Long_ge = (a, b) => { if (a.hi < b.hi) { return false; } if (a.hi > b.hi) { return true; } - var x = a.lo >>> 1; - var y = b.lo >>> 1; + let x = a.lo >>> 1; + let y = b.lo >>> 1; if (x !== y) { return x >= y; } return (a.lo & 1) >= (b.lo & 1); } - Long_lt = function(a, b) { + Long_lt = (a, b) => { if (a.hi > b.hi) { return false; } if (a.hi < b.hi) { return true; } - var x = a.lo >>> 1; - var y = b.lo >>> 1; + let x = a.lo >>> 1; + let y = b.lo >>> 1; if (x !== y) { return x < y; } return (a.lo & 1) < (b.lo & 1); } - Long_le = function(a, b) { + Long_le = (a, b) => { if (a.hi > b.hi) { return false; } if (a.hi < b.hi) { return true; } - var x = a.lo >>> 1; - var y = b.lo >>> 1; + let x = a.lo >>> 1; + let y = b.lo >>> 1; if (x !== y) { return x <= y; } return (a.lo & 1) <= (b.lo & 1); } - Long_add = function(a, b) { + Long_add = (a, b) => { if (a.hi === (a.lo >> 31) && b.hi === (b.lo >> 31)) { return Long_fromNumber(a.lo + b.lo); } else if (Math.abs(a.hi) < Long_MAX_NORMAL && Math.abs(b.hi) < Long_MAX_NORMAL) { return Long_fromNumber(Long_toNumber(a) + Long_toNumber(b)); } - var a_lolo = a.lo & 0xFFFF; - var a_lohi = a.lo >>> 16; - var a_hilo = a.hi & 0xFFFF; - var a_hihi = a.hi >>> 16; - var b_lolo = b.lo & 0xFFFF; - var b_lohi = b.lo >>> 16; - var b_hilo = b.hi & 0xFFFF; - var b_hihi = b.hi >>> 16; + let a_lolo = a.lo & 0xFFFF; + let a_lohi = a.lo >>> 16; + let a_hilo = a.hi & 0xFFFF; + let a_hihi = a.hi >>> 16; + let b_lolo = b.lo & 0xFFFF; + let b_lohi = b.lo >>> 16; + let b_hilo = b.hi & 0xFFFF; + let b_hihi = b.hi >>> 16; - var lolo = (a_lolo + b_lolo) | 0; - var lohi = (a_lohi + b_lohi + (lolo >> 16)) | 0; - var hilo = (a_hilo + b_hilo + (lohi >> 16)) | 0; - var hihi = (a_hihi + b_hihi + (hilo >> 16)) | 0; + let lolo = (a_lolo + b_lolo) | 0; + let lohi = (a_lohi + b_lohi + (lolo >> 16)) | 0; + let hilo = (a_hilo + b_hilo + (lohi >> 16)) | 0; + let hihi = (a_hihi + b_hihi + (hilo >> 16)) | 0; return new Long((lolo & 0xFFFF) | ((lohi & 0xFFFF) << 16), (hilo & 0xFFFF) | ((hihi & 0xFFFF) << 16)); } - Long_inc = function(a) { - var lo = (a.lo + 1) | 0; - var hi = a.hi; + Long_inc = a => { + let lo = (a.lo + 1) | 0; + let hi = a.hi; if (lo === 0) { hi = (hi + 1) | 0; } return new Long(lo, hi); } - Long_dec = function(a) { - var lo = (a.lo - 1) | 0; - var hi = a.hi; + Long_dec = a => { + let lo = (a.lo - 1) | 0; + let hi = a.hi; if (lo === -1) { hi = (hi - 1) | 0; } return new Long(lo, hi); } - Long_neg = function(a) { - return Long_inc(new Long(a.lo ^ 0xFFFFFFFF, a.hi ^ 0xFFFFFFFF)); - } + Long_neg = a => Long_inc(new Long(a.lo ^ 0xFFFFFFFF, a.hi ^ 0xFFFFFFFF)) - Long_sub = function(a, b) { + Long_sub = (a, b) => { if (a.hi === (a.lo >> 31) && b.hi === (b.lo >> 31)) { return Long_fromNumber(a.lo - b.lo); } - var a_lolo = a.lo & 0xFFFF; - var a_lohi = a.lo >>> 16; - var a_hilo = a.hi & 0xFFFF; - var a_hihi = a.hi >>> 16; - var b_lolo = b.lo & 0xFFFF; - var b_lohi = b.lo >>> 16; - var b_hilo = b.hi & 0xFFFF; - var b_hihi = b.hi >>> 16; + let a_lolo = a.lo & 0xFFFF; + let a_lohi = a.lo >>> 16; + let a_hilo = a.hi & 0xFFFF; + let a_hihi = a.hi >>> 16; + let b_lolo = b.lo & 0xFFFF; + let b_lohi = b.lo >>> 16; + let b_hilo = b.hi & 0xFFFF; + let b_hihi = b.hi >>> 16; - var lolo = (a_lolo - b_lolo) | 0; - var lohi = (a_lohi - b_lohi + (lolo >> 16)) | 0; - var hilo = (a_hilo - b_hilo + (lohi >> 16)) | 0; - var hihi = (a_hihi - b_hihi + (hilo >> 16)) | 0; + let lolo = (a_lolo - b_lolo) | 0; + let lohi = (a_lohi - b_lohi + (lolo >> 16)) | 0; + let hilo = (a_hilo - b_hilo + (lohi >> 16)) | 0; + let hihi = (a_hihi - b_hihi + (hilo >> 16)) | 0; return new Long((lolo & 0xFFFF) | ((lohi & 0xFFFF) << 16), (hilo & 0xFFFF) | ((hihi & 0xFFFF) << 16)); } - Long_compare = function(a, b) { - var r = a.hi - b.hi; + Long_compare = (a, b) => { + let r = a.hi - b.hi; if (r !== 0) { return r; } @@ -186,8 +180,8 @@ if (typeof teavm_globals.BigInt !== 'function') { return (a.lo & 1) - (b.lo & 1); } - Long_ucompare = function(a, b) { - var r = $rt_ucmp(a.hi, b.hi); + Long_ucompare = (a, b) => { + let r = $rt_ucmp(a.hi, b.hi); if (r !== 0) { return r; } @@ -198,27 +192,27 @@ if (typeof teavm_globals.BigInt !== 'function') { return (a.lo & 1) - (b.lo & 1); } - Long_mul = function(a, b) { - var positive = Long_isNegative(a) === Long_isNegative(b); + Long_mul = (a, b) => { + let positive = Long_isNegative(a) === Long_isNegative(b); if (Long_isNegative(a)) { a = Long_neg(a); } if (Long_isNegative(b)) { b = Long_neg(b); } - var a_lolo = a.lo & 0xFFFF; - var a_lohi = a.lo >>> 16; - var a_hilo = a.hi & 0xFFFF; - var a_hihi = a.hi >>> 16; - var b_lolo = b.lo & 0xFFFF; - var b_lohi = b.lo >>> 16; - var b_hilo = b.hi & 0xFFFF; - var b_hihi = b.hi >>> 16; + let a_lolo = a.lo & 0xFFFF; + let a_lohi = a.lo >>> 16; + let a_hilo = a.hi & 0xFFFF; + let a_hihi = a.hi >>> 16; + let b_lolo = b.lo & 0xFFFF; + let b_lohi = b.lo >>> 16; + let b_hilo = b.hi & 0xFFFF; + let b_hihi = b.hi >>> 16; - var lolo = 0; - var lohi = 0; - var hilo = 0; - var hihi = 0; + let lolo = 0; + let lohi = 0; + let hilo = 0; + let hihi = 0; lolo = (a_lolo * b_lolo) | 0; lohi = lolo >>> 16; lohi = ((lohi & 0xFFFF) + a_lohi * b_lolo) | 0; @@ -233,43 +227,43 @@ if (typeof teavm_globals.BigInt !== 'function') { hilo = ((hilo & 0xFFFF) + a_lolo * b_hilo) | 0; hihi = (hihi + (hilo >>> 16)) | 0; hihi = (hihi + a_hihi * b_lolo + a_hilo * b_lohi + a_lohi * b_hilo + a_lolo * b_hihi) | 0; - var result = new Long((lolo & 0xFFFF) | (lohi << 16), (hilo & 0xFFFF) | (hihi << 16)); + let result = new Long((lolo & 0xFFFF) | (lohi << 16), (hilo & 0xFFFF) | (hihi << 16)); return positive ? result : Long_neg(result); } - Long_div = function(a, b) { + Long_div = (a, b) => { if (Math.abs(a.hi) < Long_MAX_NORMAL && Math.abs(b.hi) < Long_MAX_NORMAL) { return Long_fromNumber(Long_toNumber(a) / Long_toNumber(b)); } return Long_divRem(a, b)[0]; } - Long_udiv = function(a, b) { + Long_udiv = (a, b) => { if (a.hi >= 0 && a.hi < Long_MAX_NORMAL && b.hi >= 0 && b.hi < Long_MAX_NORMAL) { return Long_fromNumber(Long_toNumber(a) / Long_toNumber(b)); } return Long_udivRem(a, b)[0]; } - Long_rem = function(a, b) { + Long_rem = (a, b) => { if (Math.abs(a.hi) < Long_MAX_NORMAL && Math.abs(b.hi) < Long_MAX_NORMAL) { return Long_fromNumber(Long_toNumber(a) % Long_toNumber(b)); } return Long_divRem(a, b)[1]; } - Long_urem = function(a, b) { + Long_urem = (a, b) => { if (a.hi >= 0 && a.hi < Long_MAX_NORMAL && b.hi >= 0 && b.hi < Long_MAX_NORMAL) { return Long_fromNumber(Long_toNumber(a) / Long_toNumber(b)); } return Long_udivRem(a, b)[1]; } - function Long_divRem(a, b) { + let Long_divRem = (a, b) => { if (b.lo === 0 && b.hi === 0) { throw new teavm_globals.Error("Division by zero"); } - var positive = Long_isNegative(a) === Long_isNegative(b); + let positive = Long_isNegative(a) === Long_isNegative(b); if (Long_isNegative(a)) { a = Long_neg(a); } @@ -278,45 +272,31 @@ if (typeof teavm_globals.BigInt !== 'function') { } a = new LongInt(a.lo, a.hi, 0); b = new LongInt(b.lo, b.hi, 0); - var q = LongInt_div(a, b); + let q = LongInt_div(a, b); a = new Long(a.lo, a.hi); q = new Long(q.lo, q.hi); return positive ? [q, a] : [Long_neg(q), Long_neg(a)]; - } + }; - function Long_udivRem(a, b) { + let Long_udivRem = (a, b) => { if (b.lo === 0 && b.hi === 0) { throw new teavm_globals.Error("Division by zero"); } a = new LongInt(a.lo, a.hi, 0); b = new LongInt(b.lo, b.hi, 0); - var q = LongInt_div(a, b); + let q = LongInt_div(a, b); a = new Long(a.lo, a.hi); q = new Long(q.lo, q.hi); return [q, a]; - } + }; - function Long_shiftLeft16(a) { - return new Long(a.lo << 16, (a.lo >>> 16) | (a.hi << 16)); - } + Long_and = (a, b) => new Long(a.lo & b.lo, a.hi & b.hi) - function Long_shiftRight16(a) { - return new Long((a.lo >>> 16) | (a.hi << 16), a.hi >>> 16); - } + Long_or = (a, b) => new Long(a.lo | b.lo, a.hi | b.hi) - Long_and = function(a, b) { - return new Long(a.lo & b.lo, a.hi & b.hi); - } + Long_xor = (a, b) => new Long(a.lo ^ b.lo, a.hi ^ b.hi) - Long_or = function(a, b) { - return new Long(a.lo | b.lo, a.hi | b.hi); - } - - Long_xor = function(a, b) { - return new Long(a.lo ^ b.lo, a.hi ^ b.hi); - } - - Long_shl = function(a, b) { + Long_shl = (a, b) => { b &= 63; if (b === 0) { return a; @@ -329,7 +309,7 @@ if (typeof teavm_globals.BigInt !== 'function') { } } - Long_shr = function(a, b) { + Long_shr = (a, b) => { b &= 63; if (b === 0) { return a; @@ -342,7 +322,7 @@ if (typeof teavm_globals.BigInt !== 'function') { } } - Long_shru = function(a, b) { + Long_shru = (a, b) => { b &= 63; if (b === 0) { return a; @@ -355,9 +335,7 @@ if (typeof teavm_globals.BigInt !== 'function') { } } - Long_not = function(a) { - return new Long(~a.hi, ~a.lo); - } + Long_not = a => new Long(~a.hi, ~a.lo) // Represents a mutable 80-bit unsigned integer function LongInt(lo, hi, sup) { @@ -366,12 +344,12 @@ if (typeof teavm_globals.BigInt !== 'function') { this.sup = sup; } - function LongInt_mul(a, b) { - var a_lolo = ((a.lo & 0xFFFF) * b) | 0; - var a_lohi = ((a.lo >>> 16) * b) | 0; - var a_hilo = ((a.hi & 0xFFFF) * b) | 0; - var a_hihi = ((a.hi >>> 16) * b) | 0; - var sup = (a.sup * b) | 0; + let LongInt_mul = (a, b) => { + let a_lolo = ((a.lo & 0xFFFF) * b) | 0; + let a_lohi = ((a.lo >>> 16) * b) | 0; + let a_hilo = ((a.hi & 0xFFFF) * b) | 0; + let a_hihi = ((a.hi >>> 16) * b) | 0; + let sup = (a.sup * b) | 0; a_lohi = (a_lohi + (a_lolo >>> 16)) | 0; a_hilo = (a_hilo + (a_lohi >>> 16)) | 0; @@ -380,49 +358,49 @@ if (typeof teavm_globals.BigInt !== 'function') { a.lo = (a_lolo & 0xFFFF) | (a_lohi << 16); a.hi = (a_hilo & 0xFFFF) | (a_hihi << 16); a.sup = sup & 0xFFFF; - } + }; - function LongInt_sub(a, b) { - var a_lolo = a.lo & 0xFFFF; - var a_lohi = a.lo >>> 16; - var a_hilo = a.hi & 0xFFFF; - var a_hihi = a.hi >>> 16; - var b_lolo = b.lo & 0xFFFF; - var b_lohi = b.lo >>> 16; - var b_hilo = b.hi & 0xFFFF; - var b_hihi = b.hi >>> 16; + let LongInt_sub = (a, b) => { + let a_lolo = a.lo & 0xFFFF; + let a_lohi = a.lo >>> 16; + let a_hilo = a.hi & 0xFFFF; + let a_hihi = a.hi >>> 16; + let b_lolo = b.lo & 0xFFFF; + let b_lohi = b.lo >>> 16; + let b_hilo = b.hi & 0xFFFF; + let b_hihi = b.hi >>> 16; a_lolo = (a_lolo - b_lolo) | 0; a_lohi = (a_lohi - b_lohi + (a_lolo >> 16)) | 0; a_hilo = (a_hilo - b_hilo + (a_lohi >> 16)) | 0; a_hihi = (a_hihi - b_hihi + (a_hilo >> 16)) | 0; - var sup = (a.sup - b.sup + (a_hihi >> 16)) | 0; + let sup = (a.sup - b.sup + (a_hihi >> 16)) | 0; a.lo = (a_lolo & 0xFFFF) | (a_lohi << 16); a.hi = (a_hilo & 0xFFFF) | (a_hihi << 16); a.sup = sup; - } + }; - function LongInt_add(a, b) { - var a_lolo = a.lo & 0xFFFF; - var a_lohi = a.lo >>> 16; - var a_hilo = a.hi & 0xFFFF; - var a_hihi = a.hi >>> 16; - var b_lolo = b.lo & 0xFFFF; - var b_lohi = b.lo >>> 16; - var b_hilo = b.hi & 0xFFFF; - var b_hihi = b.hi >>> 16; + let LongInt_add = (a, b) => { + let a_lolo = a.lo & 0xFFFF; + let a_lohi = a.lo >>> 16; + let a_hilo = a.hi & 0xFFFF; + let a_hihi = a.hi >>> 16; + let b_lolo = b.lo & 0xFFFF; + let b_lohi = b.lo >>> 16; + let b_hilo = b.hi & 0xFFFF; + let b_hihi = b.hi >>> 16; a_lolo = (a_lolo + b_lolo) | 0; a_lohi = (a_lohi + b_lohi + (a_lolo >> 16)) | 0; a_hilo = (a_hilo + b_hilo + (a_lohi >> 16)) | 0; a_hihi = (a_hihi + b_hihi + (a_hilo >> 16)) | 0; - var sup = (a.sup + b.sup + (a_hihi >> 16)) | 0; + let sup = (a.sup + b.sup + (a_hihi >> 16)) | 0; a.lo = (a_lolo & 0xFFFF) | (a_lohi << 16); a.hi = (a_hilo & 0xFFFF) | (a_hihi << 16); a.sup = sup; - } + }; - function LongInt_inc(a) { + let LongInt_inc = a => { a.lo = (a.lo + 1) | 0; if (a.lo === 0) { a.hi = (a.hi + 1) | 0; @@ -430,9 +408,9 @@ if (typeof teavm_globals.BigInt !== 'function') { a.sup = (a.sup + 1) & 0xFFFF; } } - } + }; - function LongInt_dec(a) { + let LongInt_dec = a => { a.lo = (a.lo - 1) | 0; if (a.lo === -1) { a.hi = (a.hi - 1) | 0; @@ -440,10 +418,10 @@ if (typeof teavm_globals.BigInt !== 'function') { a.sup = (a.sup - 1) & 0xFFFF; } } - } + }; - function LongInt_ucompare(a, b) { - var r = (a.sup - b.sup); + let LongInt_ucompare = (a, b) => { + let r = (a.sup - b.sup); if (r !== 0) { return r; } @@ -460,11 +438,11 @@ if (typeof teavm_globals.BigInt !== 'function') { return r; } return (a.lo & 1) - (b.lo & 1); - } + }; - function LongInt_numOfLeadingZeroBits(a) { - var n = 0; - var d = 16; + let LongInt_numOfLeadingZeroBits = a => { + let n = 0; + let d = 16; while (d > 0) { if ((a >>> d) !== 0) { a >>>= d; @@ -473,9 +451,9 @@ if (typeof teavm_globals.BigInt !== 'function') { d = (d / 2) | 0; } return 31 - n; - } + }; - function LongInt_shl(a, b) { + let LongInt_shl = (a, b) => { if (b === 0) { return; } @@ -500,9 +478,9 @@ if (typeof teavm_globals.BigInt !== 'function') { a.hi = 0; a.lo = 0; } - } + }; - function LongInt_shr(a, b) { + let LongInt_shr = (a, b) => { if (b === 0) { return; } @@ -527,27 +505,25 @@ if (typeof teavm_globals.BigInt !== 'function') { a.hi = 0; a.sup = 0; } - } + }; - function LongInt_copy(a) { - return new LongInt(a.lo, a.hi, a.sup); - } + let LongInt_copy = a => new LongInt(a.lo, a.hi, a.sup); - function LongInt_div(a, b) { + let LongInt_div = (a, b) => { // Normalize divisor - var bits = b.hi !== 0 ? LongInt_numOfLeadingZeroBits(b.hi) : LongInt_numOfLeadingZeroBits(b.lo) + 32; - var sz = 1 + ((bits / 16) | 0); - var dividentBits = bits % 16; + let bits = b.hi !== 0 ? LongInt_numOfLeadingZeroBits(b.hi) : LongInt_numOfLeadingZeroBits(b.lo) + 32; + let sz = 1 + ((bits / 16) | 0); + let dividentBits = bits % 16; LongInt_shl(b, bits); LongInt_shl(a, dividentBits); - var q = new LongInt(0, 0, 0); + let q = new LongInt(0, 0, 0); while (sz-- > 0) { LongInt_shl(q, 16); // Calculate approximate q - var digitA = (a.hi >>> 16) + (0x10000 * a.sup); - var digitB = b.hi >>> 16; - var digit = (digitA / digitB) | 0; - var t = LongInt_copy(b); + let digitA = (a.hi >>> 16) + (0x10000 * a.sup); + let digitB = b.hi >>> 16; + let digit = (digitA / digitB) | 0; + let t = LongInt_copy(b); LongInt_mul(t, digit); // Adjust q either down or up if (LongInt_ucompare(t, a) >= 0) { @@ -557,7 +533,7 @@ if (typeof teavm_globals.BigInt !== 'function') { } } else { while (true) { - var nextT = LongInt_copy(t); + let nextT = LongInt_copy(t); LongInt_add(nextT, b); if (LongInt_ucompare(nextT, a) > 0) { break; @@ -572,108 +548,61 @@ if (typeof teavm_globals.BigInt !== 'function') { } LongInt_shr(a, bits + 16); return q; - } + }; } else { - Long_eq = function(a, b) { - return a === b; - } + Long_eq = (a, b) => a === b - Long_ne = function(a, b) { - return a !== b; - } + Long_ne = (a, b) => a !== b - Long_gt = function(a, b) { - return a > b; - } + Long_gt = (a, b) => a > b - Long_ge = function(a, b) { - return a >= b; - } + Long_ge = (a, b) => a >= b - Long_lt = function(a, b) { - return a < b; - } + Long_lt = (a, b) => a < b - Long_le = function(a, b) { - return a <= b; - } + Long_le = (a, b) => a <= b - Long_add = function(a, b) { - return teavm_globals.BigInt.asIntN(64, a + b); - } + Long_add = (a, b) => teavm_globals.BigInt.asIntN(64, a + b) - Long_inc = function(a) { - return teavm_globals.BigInt.asIntN(64, a + 1); - } + Long_inc = a => teavm_globals.BigInt.asIntN(64, a + 1) - Long_dec = function(a) { - return teavm_globals.BigInt.asIntN(64, a - 1); - } + Long_dec = a => teavm_globals.BigInt.asIntN(64, a - 1) - Long_neg = function(a) { - return teavm_globals.BigInt.asIntN(64, -a); - } + Long_neg = a => teavm_globals.BigInt.asIntN(64, -a) - Long_sub = function(a, b) { - return teavm_globals.BigInt.asIntN(64, a - b); - } + Long_sub = (a, b) => teavm_globals.BigInt.asIntN(64, a - b) - Long_compare = function(a, b) { - return a < b ? -1 : a > b ? 1 : 0; - } - Long_ucompare = function(a, b) { + Long_compare = (a, b) => a < b ? -1 : a > b ? 1 : 0 + Long_ucompare = (a, b) => { a = teavm_globals.BigInt.asUintN(64, a); b = teavm_globals.BigInt.asUintN(64, b); return a < b ? -1 : a > b ? 1 : 0; } - Long_mul = function(a, b) { - return teavm_globals.BigInt.asIntN(64, a * b); - } + Long_mul = (a, b) => teavm_globals.BigInt.asIntN(64, a * b) - Long_div = function(a, b) { - return teavm_globals.BigInt.asIntN(64, a / b); - } + Long_div = (a, b) => teavm_globals.BigInt.asIntN(64, a / b) - Long_udiv = function(a, b) { - return teavm_globals.BigInt.asIntN(64, teavm_globals.BigInt.asUintN(64, a) / - teavm_globals.BigInt.asUintN(64, b)); - } + Long_udiv = (a, b) => teavm_globals.BigInt.asIntN(64, teavm_globals.BigInt.asUintN(64, a) / + teavm_globals.BigInt.asUintN(64, b)) - Long_rem = function(a, b) { - return teavm_globals.BigInt.asIntN(64, a % b); - } + Long_rem = (a, b) => teavm_globals.BigInt.asIntN(64, a % b) - Long_urem = function(a, b) { - return teavm_globals.BigInt.asIntN(64, teavm_globals.BigInt.asUintN(64, a) % - teavm_globals.BigInt.asUintN(64, b)); - } + Long_urem = (a, b) => teavm_globals.BigInt.asIntN(64, teavm_globals.BigInt.asUintN(64, a) % + teavm_globals.BigInt.asUintN(64, b)) - Long_and = function(a, b) { - return teavm_globals.BigInt.asIntN(64, a & b); - } + Long_and = (a, b) => teavm_globals.BigInt.asIntN(64, a & b) - Long_or = function(a, b) { - return teavm_globals.BigInt.asIntN(64, a | b); - } + Long_or = (a, b) => teavm_globals.BigInt.asIntN(64, a | b) - Long_xor = function(a, b) { - return teavm_globals.BigInt.asIntN(64, a ^ b); - } + Long_xor = (a, b) => teavm_globals.BigInt.asIntN(64, a ^ b) - Long_shl = function(a, b) { - return teavm_globals.BigInt.asIntN(64, a << teavm_globals.BigInt(b & 63)); - } + Long_shl = (a, b) => teavm_globals.BigInt.asIntN(64, a << teavm_globals.BigInt(b & 63)) - Long_shr = function(a, b) { - return teavm_globals.BigInt.asIntN(64, a >> teavm_globals.BigInt(b & 63)); - } + Long_shr = (a, b) => teavm_globals.BigInt.asIntN(64, a >> teavm_globals.BigInt(b & 63)) - Long_shru = function(a, b) { - return teavm_globals.BigInt.asIntN(64, teavm_globals.BigInt.asUintN(64, a) >> teavm_globals.BigInt(b & 63)); - } + Long_shru = (a, b) => teavm_globals.BigInt.asIntN(64, teavm_globals.BigInt.asUintN(64, a) >> + teavm_globals.BigInt(b & 63)) - Long_not = function(a) { - return teavm_globals.BigInt.asIntN(64, ~a); - } + Long_not = a => teavm_globals.BigInt.asIntN(64, ~a) } diff --git a/core/src/main/resources/org/teavm/backend/javascript/runtime.js b/core/src/main/resources/org/teavm/backend/javascript/runtime.js index cdb6fc501..dd6149b5d 100644 --- a/core/src/main/resources/org/teavm/backend/javascript/runtime.js +++ b/core/src/main/resources/org/teavm/backend/javascript/runtime.js @@ -14,145 +14,118 @@ * limitations under the License. */ "use strict"; -var $rt_seed = 2463534242; -function $rt_nextId() { - var x = $rt_seed; +let $rt_seed = 2463534242; +let $rt_nextId = () => { + let x = $rt_seed; x ^= x << 13; x ^= x >>> 17; x ^= x << 5; $rt_seed = x; return x; } -function $rt_compare(a, b) { - return a > b ? 1 : a < b ? -1 : a === b ? 0 : 1; -} -function $rt_isInstance(obj, cls) { - return obj instanceof $rt_objcls() && !!obj.constructor.$meta && $rt_isAssignable(obj.constructor, cls); -} -function $rt_isAssignable(from, to) { +let $rt_compare = (a, b) => a > b ? 1 : a < b ? -1 : a === b ? 0 : 1; +let $rt_isInstance = (obj, cls) => obj instanceof $rt_objcls() && !!obj.constructor.$meta + && $rt_isAssignable(obj.constructor, cls); +let $rt_isAssignable = (from, to) => { if (from === to) { return true; } if (to.$meta.item !== null) { return from.$meta.item !== null && $rt_isAssignable(from.$meta.item, to.$meta.item); } - var supertypes = from.$meta.supertypes; - for (var i = 0; i < supertypes.length; i = (i + 1) | 0) { + let supertypes = from.$meta.supertypes; + for (let i = 0; i < supertypes.length; i = (i + 1) | 0) { if ($rt_isAssignable(supertypes[i], to)) { return true; } } return false; } -function $rt_castToInterface(obj, cls) { +let $rt_castToInterface = (obj, cls) => { if (obj !== null && !$rt_isInstance(obj, cls)) { $rt_throwCCE(); } return obj; } -function $rt_castToClass(obj, cls) { +let $rt_castToClass = (obj, cls) => { if (obj !== null && !(obj instanceof cls)) { $rt_throwCCE(); } return obj; } -function $rt_createArray(cls, sz) { - var data = new teavm_globals.Array(sz); +let $rt_createArray = (cls, sz) => { + let data = new teavm_globals.Array(sz); data.fill(null); return new ($rt_arraycls(cls))(data); } -function $rt_createArrayFromData(cls, init) { - return $rt_wrapArray(cls, init); -} -function $rt_wrapArray(cls, data) { - return new ($rt_arraycls(cls))(data); -} -function $rt_createUnfilledArray(cls, sz) { - return new ($rt_arraycls(cls))(new teavm_globals.Array(sz)); -} -var $rt_createLongArray; -var $rt_createLongArrayFromData; +let $rt_createArrayFromData = (cls, init) => $rt_wrapArray(cls, init); +let $rt_wrapArray = (cls, data) => new ($rt_arraycls(cls))(data); +let $rt_createUnfilledArray = (cls, sz) => new ($rt_arraycls(cls))(new teavm_globals.Array(sz)); +let $rt_createLongArray; +let $rt_createLongArrayFromData; if (typeof teavm_globals.BigInt64Array !== 'function') { - $rt_createLongArray = function(sz) { - var data = new teavm_globals.Array(sz); - var arr = new $rt_longArrayCls(data); + $rt_createLongArray = sz => { + let data = new teavm_globals.Array(sz); + let arr = new $rt_longArrayCls(data); data.fill(Long_ZERO); return arr; } - $rt_createLongArrayFromData = function(init) { - return new $rt_longArrayCls(init); - } + $rt_createLongArrayFromData = init => new $rt_longArrayCls(init); } else { - $rt_createLongArray = function (sz) { - return new $rt_longArrayCls(new teavm_globals.BigInt64Array(sz)); - } - $rt_createLongArrayFromData = function(data) { - var buffer = new teavm_globals.BigInt64Array(data.length); + $rt_createLongArray = sz => new $rt_longArrayCls(new teavm_globals.BigInt64Array(sz)); + $rt_createLongArrayFromData = data => { + let buffer = new teavm_globals.BigInt64Array(data.length); buffer.set(data); return new $rt_longArrayCls(buffer); } } -function $rt_createCharArray(sz) { - return new $rt_charArrayCls(new teavm_globals.Uint16Array(sz)); -} -function $rt_createCharArrayFromData(data) { - var buffer = new teavm_globals.Uint16Array(data.length); +let $rt_createCharArray = sz => new $rt_charArrayCls(new teavm_globals.Uint16Array(sz)); +let $rt_createCharArrayFromData = data => { + let buffer = new teavm_globals.Uint16Array(data.length); buffer.set(data); return new $rt_charArrayCls(buffer); } -function $rt_createByteArray(sz) { - return new $rt_byteArrayCls(new teavm_globals.Int8Array(sz)); -} -function $rt_createByteArrayFromData(data) { - var buffer = new teavm_globals.Int8Array(data.length); +let $rt_createByteArray = sz => new $rt_byteArrayCls(new teavm_globals.Int8Array(sz)); +let $rt_createByteArrayFromData = data => { + let buffer = new teavm_globals.Int8Array(data.length); buffer.set(data); return new $rt_byteArrayCls(buffer); } -function $rt_createShortArray(sz) { - return new $rt_shortArrayCls(new teavm_globals.Int16Array(sz)); -} -function $rt_createShortArrayFromData(data) { - var buffer = new teavm_globals.Int16Array(data.length); +let $rt_createShortArray = sz => new $rt_shortArrayCls(new teavm_globals.Int16Array(sz)); +let $rt_createShortArrayFromData = data => { + let buffer = new teavm_globals.Int16Array(data.length); buffer.set(data); return new $rt_shortArrayCls(buffer); } -function $rt_createIntArray(sz) { - return new $rt_intArrayCls(new teavm_globals.Int32Array(sz)); -} -function $rt_createIntArrayFromData(data) { - var buffer = new teavm_globals.Int32Array(data.length); +let $rt_createIntArray = sz => new $rt_intArrayCls(new teavm_globals.Int32Array(sz)); +let $rt_createIntArrayFromData = data => { + let buffer = new teavm_globals.Int32Array(data.length); buffer.set(data); return new $rt_intArrayCls(buffer); } -function $rt_createBooleanArray(sz) { - return new $rt_booleanArrayCls(new teavm_globals.Int8Array(sz)); -} -function $rt_createBooleanArrayFromData(data) { - var buffer = new teavm_globals.Int8Array(data.length); +let $rt_createBooleanArray = sz => new $rt_booleanArrayCls(new teavm_globals.Int8Array(sz)); +let $rt_createBooleanArrayFromData = data => { + let buffer = new teavm_globals.Int8Array(data.length); buffer.set(data); return new $rt_booleanArrayCls(buffer); } -function $rt_createFloatArray(sz) { - return new $rt_floatArrayCls(new teavm_globals.Float32Array(sz)); -} -function $rt_createFloatArrayFromData(data) { - var buffer = new teavm_globals.Float32Array(data.length); +let $rt_createFloatArray = sz => new $rt_floatArrayCls(new teavm_globals.Float32Array(sz)); +let $rt_createFloatArrayFromData = data => { + let buffer = new teavm_globals.Float32Array(data.length); buffer.set(data); return new $rt_floatArrayCls(buffer); } -function $rt_createDoubleArray(sz) { - return new $rt_doubleArrayCls(new teavm_globals.Float64Array(sz)); -} -function $rt_createDoubleArrayFromData(data) { - var buffer = new teavm_globals.Float64Array(data.length); +let $rt_createDoubleArray = sz => new $rt_doubleArrayCls(new teavm_globals.Float64Array(sz)); +let $rt_createDoubleArrayFromData = data => { + let buffer = new teavm_globals.Float64Array(data.length); buffer.set(data); return new $rt_doubleArrayCls(buffer); } -function $rt_arraycls(cls) { - var result = cls.$array; +let $rt_arraycls = cls => { + let result = cls.$array; if (result === null) { function JavaArray(data) { $rt_objcls().call(this); @@ -162,8 +135,8 @@ function $rt_arraycls(cls) { JavaArray.prototype.type = cls; JavaArray.prototype.constructor = JavaArray; JavaArray.prototype.toString = function() { - var str = "["; - for (var i = 0; i < this.data.length; ++i) { + let str = "["; + for (let i = 0; i < this.data.length; ++i) { if (i > 0) { str += ", "; } @@ -172,19 +145,19 @@ function $rt_arraycls(cls) { str += "]"; return str; }; - $rt_setCloneMethod(JavaArray.prototype, function () { - var dataCopy; + $rt_setCloneMethod(JavaArray.prototype, function() { + let dataCopy; if ('slice' in this.data) { dataCopy = this.data.slice(); } else { dataCopy = new this.data.constructor(this.data.length); - for (var i = 0; i < dataCopy.length; ++i) { + for (let i = 0; i < dataCopy.length; ++i) { dataCopy[i] = this.data[i]; } } return new ($rt_arraycls(this.type))(dataCopy); }); - var name = "[" + cls.$meta.binaryName; + let name = "[" + cls.$meta.binaryName; JavaArray.$meta = { item: cls, supertypes: [$rt_objcls()], @@ -205,7 +178,7 @@ function $rt_arraycls(cls) { } return result; } -function $rt_createcls() { +let $rt_createcls = () => { return { $array : null, classObject : null, @@ -215,8 +188,8 @@ function $rt_createcls() { } }; } -function $rt_createPrimitiveCls(name, binaryName) { - var cls = $rt_createcls(); +let $rt_createPrimitiveCls = (name, binaryName) => { + let cls = $rt_createcls(); cls.$meta.primitive = true; cls.$meta.name = name; cls.$meta.binaryName = binaryName; @@ -227,25 +200,25 @@ function $rt_createPrimitiveCls(name, binaryName) { cls.$meta.enclosingClass = null; return cls; } -var $rt_booleancls = $rt_createPrimitiveCls("boolean", "Z"); -var $rt_charcls = $rt_createPrimitiveCls("char", "C"); -var $rt_bytecls = $rt_createPrimitiveCls("byte", "B"); -var $rt_shortcls = $rt_createPrimitiveCls("short", "S"); -var $rt_intcls = $rt_createPrimitiveCls("int", "I"); -var $rt_longcls = $rt_createPrimitiveCls("long", "J"); -var $rt_floatcls = $rt_createPrimitiveCls("float", "F"); -var $rt_doublecls = $rt_createPrimitiveCls("double", "D"); -var $rt_voidcls = $rt_createPrimitiveCls("void", "V"); -function $rt_throw(ex) { - throw $rt_exception(ex); -} -var $rt_javaExceptionProp = teavm_globals.Symbol("javaException") -function $rt_exception(ex) { - var err = ex.$jsException; +let $rt_booleancls = $rt_createPrimitiveCls("boolean", "Z"); +let $rt_charcls = $rt_createPrimitiveCls("char", "C"); +let $rt_bytecls = $rt_createPrimitiveCls("byte", "B"); +let $rt_shortcls = $rt_createPrimitiveCls("short", "S"); +let $rt_intcls = $rt_createPrimitiveCls("int", "I"); +let $rt_longcls = $rt_createPrimitiveCls("long", "J"); +let $rt_floatcls = $rt_createPrimitiveCls("float", "F"); +let $rt_doublecls = $rt_createPrimitiveCls("double", "D"); +let $rt_voidcls = $rt_createPrimitiveCls("void", "V"); +let $rt_throw = ex => { + throw $rt_exception(ex) +}; +let $rt_javaExceptionProp = teavm_globals.Symbol("javaException") +let $rt_exception = ex => { + let err = ex.$jsException; if (!err) { - var javaCause = $rt_throwableCause(ex); - var jsCause = javaCause !== null ? javaCause.$jsException : void 0; - var cause = typeof jsCause === "object" ? { cause : jsCause } : void 0; + let javaCause = $rt_throwableCause(ex); + let jsCause = javaCause !== null ? javaCause.$jsException : void 0; + let cause = typeof jsCause === "object" ? { cause : jsCause } : void 0; err = new JavaError("Java exception thrown", cause); if (typeof teavm_globals.Error.captureStackTrace === "function") { teavm_globals.Error.captureStackTrace(err); @@ -256,14 +229,14 @@ function $rt_exception(ex) { } return err; } -function $rt_fillStack(err, ex) { +let $rt_fillStack = (err, ex) => { if (typeof $rt_decodeStack === "function" && err.stack) { - var stack = $rt_decodeStack(err.stack); - var javaStack = $rt_createArray($rt_stecls(), stack.length); - var elem; - var noStack = false; - for (var i = 0; i < stack.length; ++i) { - var element = stack[i]; + let stack = $rt_decodeStack(err.stack); + let javaStack = $rt_createArray($rt_stecls(), stack.length); + let elem; + let noStack = false; + for (let i = 0; i < stack.length; ++i) { + let element = stack[i]; elem = $rt_createStackElement($rt_str(element.className), $rt_str(element.methodName), $rt_str(element.fileName), element.lineNumber); if (elem == null) { @@ -277,120 +250,120 @@ function $rt_fillStack(err, ex) { } } } -function $rt_createMultiArray(cls, dimensions) { - var first = 0; - for (var i = dimensions.length - 1; i >= 0; i = (i - 1) | 0) { +let $rt_createMultiArray = (cls, dimensions) => { + let first = 0; + for (let i = dimensions.length - 1; i >= 0; i = (i - 1) | 0) { if (dimensions[i] === 0) { first = i; break; } } if (first > 0) { - for (i = 0; i < first; i = (i + 1) | 0) { + for (let i = 0; i < first; i = (i + 1) | 0) { cls = $rt_arraycls(cls); } if (first === dimensions.length - 1) { return $rt_createArray(cls, dimensions[first]); } } - var arrays = new teavm_globals.Array($rt_primitiveArrayCount(dimensions, first)); - var firstDim = dimensions[first] | 0; - for (i = 0; i < arrays.length; i = (i + 1) | 0) { + let arrays = new teavm_globals.Array($rt_primitiveArrayCount(dimensions, first)); + let firstDim = dimensions[first] | 0; + for (let i = 0; i < arrays.length; i = (i + 1) | 0) { arrays[i] = $rt_createArray(cls, firstDim); } return $rt_createMultiArrayImpl(cls, arrays, dimensions, first); } -function $rt_createByteMultiArray(dimensions) { - var arrays = new teavm_globals.Array($rt_primitiveArrayCount(dimensions, 0)); +let $rt_createByteMultiArray = dimensions => { + let arrays = new teavm_globals.Array($rt_primitiveArrayCount(dimensions, 0)); if (arrays.length === 0) { return $rt_createMultiArray($rt_bytecls, dimensions); } - var firstDim = dimensions[0] | 0; - for (var i = 0; i < arrays.length; i = (i + 1) | 0) { + let firstDim = dimensions[0] | 0; + for (let i = 0; i < arrays.length; i = (i + 1) | 0) { arrays[i] = $rt_createByteArray(firstDim); } return $rt_createMultiArrayImpl($rt_bytecls, arrays, dimensions); } -function $rt_createCharMultiArray(dimensions) { - var arrays = new teavm_globals.Array($rt_primitiveArrayCount(dimensions, 0)); +let $rt_createCharMultiArray = dimensions => { + let arrays = new teavm_globals.Array($rt_primitiveArrayCount(dimensions, 0)); if (arrays.length === 0) { return $rt_createMultiArray($rt_charcls, dimensions); } - var firstDim = dimensions[0] | 0; - for (var i = 0; i < arrays.length; i = (i + 1) | 0) { + let firstDim = dimensions[0] | 0; + for (let i = 0; i < arrays.length; i = (i + 1) | 0) { arrays[i] = $rt_createCharArray(firstDim); } return $rt_createMultiArrayImpl($rt_charcls, arrays, dimensions, 0); } -function $rt_createBooleanMultiArray(dimensions) { - var arrays = new teavm_globals.Array($rt_primitiveArrayCount(dimensions, 0)); +let $rt_createBooleanMultiArray = dimensions => { + let arrays = new teavm_globals.Array($rt_primitiveArrayCount(dimensions, 0)); if (arrays.length === 0) { return $rt_createMultiArray($rt_booleancls, dimensions); } - var firstDim = dimensions[0] | 0; - for (var i = 0; i < arrays.length; i = (i + 1) | 0) { + let firstDim = dimensions[0] | 0; + for (let i = 0; i < arrays.length; i = (i + 1) | 0) { arrays[i] = $rt_createBooleanArray(firstDim); } return $rt_createMultiArrayImpl($rt_booleancls, arrays, dimensions, 0); } -function $rt_createShortMultiArray(dimensions) { - var arrays = new teavm_globals.Array($rt_primitiveArrayCount(dimensions, 0)); +let $rt_createShortMultiArray = dimensions => { + let arrays = new teavm_globals.Array($rt_primitiveArrayCount(dimensions, 0)); if (arrays.length === 0) { return $rt_createMultiArray($rt_shortcls, dimensions); } - var firstDim = dimensions[0] | 0; - for (var i = 0; i < arrays.length; i = (i + 1) | 0) { + let firstDim = dimensions[0] | 0; + for (let i = 0; i < arrays.length; i = (i + 1) | 0) { arrays[i] = $rt_createShortArray(firstDim); } return $rt_createMultiArrayImpl($rt_shortcls, arrays, dimensions, 0); } -function $rt_createIntMultiArray(dimensions) { - var arrays = new teavm_globals.Array($rt_primitiveArrayCount(dimensions, 0)); +let $rt_createIntMultiArray = dimensions => { + let arrays = new teavm_globals.Array($rt_primitiveArrayCount(dimensions, 0)); if (arrays.length === 0) { return $rt_createMultiArray($rt_intcls, dimensions); } - var firstDim = dimensions[0] | 0; - for (var i = 0; i < arrays.length; i = (i + 1) | 0) { + let firstDim = dimensions[0] | 0; + for (let i = 0; i < arrays.length; i = (i + 1) | 0) { arrays[i] = $rt_createIntArray(firstDim); } return $rt_createMultiArrayImpl($rt_intcls, arrays, dimensions, 0); } -function $rt_createLongMultiArray(dimensions) { - var arrays = new teavm_globals.Array($rt_primitiveArrayCount(dimensions, 0)); +let $rt_createLongMultiArray = dimensions => { + let arrays = new teavm_globals.Array($rt_primitiveArrayCount(dimensions, 0)); if (arrays.length === 0) { return $rt_createMultiArray($rt_longcls, dimensions); } - var firstDim = dimensions[0] | 0; - for (var i = 0; i < arrays.length; i = (i + 1) | 0) { + let firstDim = dimensions[0] | 0; + for (let i = 0; i < arrays.length; i = (i + 1) | 0) { arrays[i] = $rt_createLongArray(firstDim); } return $rt_createMultiArrayImpl($rt_longcls, arrays, dimensions, 0); } -function $rt_createFloatMultiArray(dimensions) { - var arrays = new teavm_globals.Array($rt_primitiveArrayCount(dimensions, 0)); +let $rt_createFloatMultiArray = dimensions => { + let arrays = new teavm_globals.Array($rt_primitiveArrayCount(dimensions, 0)); if (arrays.length === 0) { return $rt_createMultiArray($rt_floatcls, dimensions); } - var firstDim = dimensions[0] | 0; - for (var i = 0; i < arrays.length; i = (i + 1) | 0) { + let firstDim = dimensions[0] | 0; + for (let i = 0; i < arrays.length; i = (i + 1) | 0) { arrays[i] = $rt_createFloatArray(firstDim); } return $rt_createMultiArrayImpl($rt_floatcls, arrays, dimensions, 0); } -function $rt_createDoubleMultiArray(dimensions) { - var arrays = new teavm_globals.Array($rt_primitiveArrayCount(dimensions, 0)); +let $rt_createDoubleMultiArray = dimensions => { + let arrays = new teavm_globals.Array($rt_primitiveArrayCount(dimensions, 0)); if (arrays.length === 0) { return $rt_createMultiArray($rt_doublecls, dimensions); } - var firstDim = dimensions[0] | 0; - for (var i = 0; i < arrays.length; i = (i + 1) | 0) { + let firstDim = dimensions[0] | 0; + for (let i = 0; i < arrays.length; i = (i + 1) | 0) { arrays[i] = $rt_createDoubleArray(firstDim); } return $rt_createMultiArrayImpl($rt_doublecls, arrays, dimensions, 0); } -function $rt_primitiveArrayCount(dimensions, start) { - var val = dimensions[start + 1] | 0; - for (var i = start + 2; i < dimensions.length; i = (i + 1) | 0) { +let $rt_primitiveArrayCount = (dimensions, start) => { + let val = dimensions[start + 1] | 0; + for (let i = start + 2; i < dimensions.length; i = (i + 1) | 0) { val = (val * (dimensions[i] | 0)) | 0; if (val === 0) { break; @@ -398,16 +371,16 @@ function $rt_primitiveArrayCount(dimensions, start) { } return val; } -function $rt_createMultiArrayImpl(cls, arrays, dimensions, start) { - var limit = arrays.length; - for (var i = (start + 1) | 0; i < dimensions.length; i = (i + 1) | 0) { +let $rt_createMultiArrayImpl = (cls, arrays, dimensions, start) => { + let limit = arrays.length; + for (let i = (start + 1) | 0; i < dimensions.length; i = (i + 1) | 0) { cls = $rt_arraycls(cls); - var dim = dimensions[i]; - var index = 0; - var packedIndex = 0; + let dim = dimensions[i]; + let index = 0; + let packedIndex = 0; while (index < limit) { - var arr = $rt_createUnfilledArray(cls, dim); - for (var j = 0; j < dim; j = (j + 1) | 0) { + let arr = $rt_createUnfilledArray(cls, dim); + for (let j = 0; j < dim; j = (j + 1) | 0) { arr.data[j] = arrays[index]; index = (index + 1) | 0; } @@ -418,18 +391,18 @@ function $rt_createMultiArrayImpl(cls, arrays, dimensions, start) { } return arrays[0]; } -function $rt_assertNotNaN(value) { +let $rt_assertNotNaN = value => { if (typeof value === 'number' && isNaN(value)) { throw "NaN"; } return value; } -function $rt_createOutputFunction(printFunction) { - var buffer = ""; - var utf8Buffer = 0; - var utf8Remaining = 0; +let $rt_createOutputFunction = printFunction => { + let buffer = ""; + let utf8Buffer = 0; + let utf8Remaining = 0; - function putCodePoint(ch) { + let putCodePoint = ch =>{ if (ch === 0xA) { printFunction(buffer); buffer = ""; @@ -437,13 +410,13 @@ function $rt_createOutputFunction(printFunction) { buffer += String.fromCharCode(ch); } else { ch = (ch - 0x10000) | 0; - var hi = (ch >> 10) + 0xD800; - var lo = (ch & 0x3FF) + 0xDC00; + let hi = (ch >> 10) + 0xD800; + let lo = (ch & 0x3FF) + 0xDC00; buffer += String.fromCharCode(hi, lo); } } - return function(ch) { + return ch => { if ((ch & 0x80) === 0) { putCodePoint(ch); } else if ((ch & 0xC0) === 0x80) { @@ -467,43 +440,43 @@ function $rt_createOutputFunction(printFunction) { }; } -var $rt_putStdout = typeof $rt_putStdoutCustom === "function" - ? $rt_putStdoutCustom +let $rt_putStdout = typeof teavm_globals.$rt_putStdoutCustom === "function" + ? teavm_globals.$rt_putStdoutCustom : typeof console === "object" ? $rt_createOutputFunction(function(msg) { console.info(msg); }) : function() {}; -var $rt_putStderr = typeof $rt_putStderrCustom === "function" - ? $rt_putStderrCustom +let $rt_putStderr = typeof teavm_globals.$rt_putStderrCustom === "function" + ? teavm_globals.$rt_putStderrCustom : typeof console === "object" ? $rt_createOutputFunction(function(msg) { console.error(msg); }) : function() {}; -var $rt_packageData = null; -function $rt_packages(data) { - var i = 0; - var packages = new teavm_globals.Array(data.length); - for (var j = 0; j < data.length; ++j) { - var prefixIndex = data[i++]; - var prefix = prefixIndex >= 0 ? packages[prefixIndex] : ""; +let $rt_packageData = null; +let $rt_packages = data => { + let i = 0; + let packages = new teavm_globals.Array(data.length); + for (let j = 0; j < data.length; ++j) { + let prefixIndex = data[i++]; + let prefix = prefixIndex >= 0 ? packages[prefixIndex] : ""; packages[j] = prefix + data[i++] + "."; } $rt_packageData = packages; } -function $rt_metadata(data) { - var packages = $rt_packageData; - var i = 0; +let $rt_metadata = data => { + let packages = $rt_packageData; + let i = 0; while (i < data.length) { - var cls = data[i++]; + let cls = data[i++]; cls.$meta = {}; - var m = cls.$meta; - var className = data[i++]; + let m = cls.$meta; + let className = data[i++]; m.name = className !== 0 ? className : null; if (m.name !== null) { - var packageIndex = data[i++]; + let packageIndex = data[i++]; if (packageIndex >= 0) { m.name = packages[packageIndex] + m.name; } } m.binaryName = "L" + m.name + ";"; - var superclass = data[i++]; + let superclass = data[i++]; m.superclass = superclass !== 0 ? superclass : null; m.supertypes = data[i++]; if (m.superclass) { @@ -512,7 +485,7 @@ function $rt_metadata(data) { } else { cls.prototype = {}; } - var flags = data[i++]; + let flags = data[i++]; m.enum = (flags & 8) !== 0; m.flags = flags; m.primitive = false; @@ -522,32 +495,32 @@ function $rt_metadata(data) { m.accessLevel = data[i++]; - var innerClassInfo = data[i++]; + let innerClassInfo = data[i++]; if (innerClassInfo === 0) { m.simpleName = null; m.declaringClass = null; m.enclosingClass = null; } else { - var enclosingClass = innerClassInfo[0]; + let enclosingClass = innerClassInfo[0]; m.enclosingClass = enclosingClass !== 0 ? enclosingClass : null; - var declaringClass = innerClassInfo[1]; + let declaringClass = innerClassInfo[1]; m.declaringClass = declaringClass !== 0 ? declaringClass : null; - var simpleName = innerClassInfo[2]; + let simpleName = innerClassInfo[2]; m.simpleName = simpleName !== 0 ? simpleName : null; } - var clinit = data[i++]; + let clinit = data[i++]; cls.$clinit = clinit !== 0 ? clinit : function() {}; - var virtualMethods = data[i++]; + let virtualMethods = data[i++]; if (virtualMethods !== 0) { - for (var j = 0; j < virtualMethods.length; j += 2) { - var name = virtualMethods[j]; - var func = virtualMethods[j + 1]; + for (let j = 0; j < virtualMethods.length; j += 2) { + let name = virtualMethods[j]; + let func = virtualMethods[j + 1]; if (typeof name === 'string') { name = [name]; } - for (var k = 0; k < name.length; ++k) { + for (let k = 0; k < name.length; ++k) { cls.prototype[name[k]] = func; } } @@ -556,120 +529,102 @@ function $rt_metadata(data) { cls.$array = null; } } -function $rt_wrapFunction0(f) { - return function() { - return f(this); - } +let $rt_wrapFunction0 = f => function() { + return f(this); } -function $rt_wrapFunction1(f) { - return function(p1) { - return f(this, p1); - } +let $rt_wrapFunction1 = f => function(p1) { + return f(this, p1); } -function $rt_wrapFunction2(f) { - return function(p1, p2) { - return f(this, p1, p2); - } +let $rt_wrapFunction2 = f => function (p1, p2) { + return f(this, p1, p2); } -function $rt_wrapFunction3(f) { - return function(p1, p2, p3) { - return f(this, p1, p2, p3, p3); - } +let $rt_wrapFunction3 = f => function(p1, p2, p3) { + return f(this, p1, p2, p3, p3); } -function $rt_wrapFunction4(f) { - return function(p1, p2, p3, p4) { - return f(this, p1, p2, p3, p4); - } +let $rt_wrapFunction4 = f => function(p1, p2, p3, p4) { + return f(this, p1, p2, p3, p4); } -function $rt_threadStarter(f) { - return function() { - var args = teavm_globals.Array.prototype.slice.apply(arguments); - $rt_startThread(function() { - f.apply(this, args); - }); - } +let $rt_threadStarter = f => function() { + let args = teavm_globals.Array.prototype.slice.apply(arguments); + $rt_startThread(function() { + f.apply(this, args); + }); } -function $rt_mainStarter(f) { - return function(args, callback) { - if (!args) { - args = []; - } - var javaArgs = $rt_createArray($rt_objcls(), args.length); - for (var i = 0; i < args.length; ++i) { - javaArgs.data[i] = $rt_str(args[i]); - } - $rt_startThread(function() { f.call(null, javaArgs); }, callback); +let $rt_mainStarter = f => (args, callback) => { + if (!args) { + args = []; } + let javaArgs = $rt_createArray($rt_objcls(), args.length); + for (let i = 0; i < args.length; ++i) { + javaArgs.data[i] = $rt_str(args[i]); + } + $rt_startThread(() => { f.call(null, javaArgs); }, callback); } -var $rt_stringPool_instance; -function $rt_stringPool(strings) { +let $rt_stringPool_instance; +let $rt_stringPool = strings => { $rt_stringClassInit(); $rt_stringPool_instance = new teavm_globals.Array(strings.length); - for (var i = 0; i < strings.length; ++i) { + for (let i = 0; i < strings.length; ++i) { $rt_stringPool_instance[i] = $rt_intern($rt_str(strings[i])); } } -function $rt_s(index) { - return $rt_stringPool_instance[index]; -} -function $rt_eraseClinit(target) { - return target.$clinit = function() {}; -} +let $rt_s = index => $rt_stringPool_instance[index]; +let $rt_eraseClinit = target => target.$clinit = () => {}; -var $rt_numberConversionBuffer = new teavm_globals.ArrayBuffer(16); -var $rt_numberConversionView = new teavm_globals.DataView($rt_numberConversionBuffer); -var $rt_numberConversionFloatArray = new teavm_globals.Float32Array($rt_numberConversionBuffer); -var $rt_numberConversionDoubleArray = new teavm_globals.Float64Array($rt_numberConversionBuffer); -var $rt_numberConversionIntArray = new teavm_globals.Int32Array($rt_numberConversionBuffer); +let $rt_numberConversionBuffer = new teavm_globals.ArrayBuffer(16); +let $rt_numberConversionView = new teavm_globals.DataView($rt_numberConversionBuffer); +let $rt_numberConversionFloatArray = new teavm_globals.Float32Array($rt_numberConversionBuffer); +let $rt_numberConversionDoubleArray = new teavm_globals.Float64Array($rt_numberConversionBuffer); +let $rt_numberConversionIntArray = new teavm_globals.Int32Array($rt_numberConversionBuffer); -var $rt_doubleToRawLongBits; -var $rt_longBitsToDouble; +let $rt_doubleToRawLongBits; +let $rt_longBitsToDouble; if (typeof teavm_globals.BigInt !== 'function') { - $rt_doubleToRawLongBits = function(n) { + $rt_doubleToRawLongBits = n => { $rt_numberConversionView.setFloat64(0, n, true); return new Long($rt_numberConversionView.getInt32(0, true), $rt_numberConversionView.getInt32(4, true)); } - $rt_longBitsToDouble = function(n) { + $rt_longBitsToDouble = n => { $rt_numberConversionView.setInt32(0, n.lo, true); $rt_numberConversionView.setInt32(4, n.hi, true); return $rt_numberConversionView.getFloat64(0, true); } } else if (typeof teavm_globals.BigInt64Array !== 'function') { - $rt_doubleToRawLongBits = function(n) { + $rt_doubleToRawLongBits = n => { $rt_numberConversionView.setFloat64(0, n, true); - var lo = $rt_numberConversionView.getInt32(0, true); - var hi = $rt_numberConversionView.getInt32(4, true); + let lo = $rt_numberConversionView.getInt32(0, true); + let hi = $rt_numberConversionView.getInt32(4, true); return teavm_globals.BigInt.asIntN(64, teavm_globals.BigInt.asUintN(32, teavm_globals.BigInt(lo)) | (teavm_globals.BigInt(hi) << teavm_globals.BigInt(32))); } - $rt_longBitsToDouble = function(n) { + $rt_longBitsToDouble = n => { $rt_numberConversionView.setFloat64(0, n, true); - var lo = $rt_numberConversionView.getInt32(0, true); - var hi = $rt_numberConversionView.getInt32(4, true); + let lo = $rt_numberConversionView.getInt32(0, true); + let hi = $rt_numberConversionView.getInt32(4, true); return teavm_globals.BigInt.asIntN(64, teavm_globals.BigInt.asUintN(32, teavm_globals.BigInt(lo)) | (teavm_globals.BigInt(hi) << teavm_globals.BigInt(32))); } } else { - var $rt_numberConversionLongArray = new teavm_globals.BigInt64Array($rt_numberConversionBuffer); - $rt_doubleToRawLongBits = function(n) { + let $rt_numberConversionLongArray = new teavm_globals.BigInt64Array($rt_numberConversionBuffer); + $rt_doubleToRawLongBits = n => { $rt_numberConversionDoubleArray[0] = n; return $rt_numberConversionLongArray[0]; } - $rt_longBitsToDouble = function(n) { + $rt_longBitsToDouble = n => { $rt_numberConversionLongArray[0] = n; return $rt_numberConversionDoubleArray[0]; } } -function $rt_floatToRawIntBits(n) { +let $rt_floatToRawIntBits = n => { $rt_numberConversionFloatArray[0] = n; return $rt_numberConversionIntArray[0]; } -function $rt_intBitsToFloat(n) { +let $rt_intBitsToFloat = n => { $rt_numberConversionIntArray[0] = n; return $rt_numberConversionFloatArray[0]; } -function $rt_equalDoubles(a, b) { +let $rt_equalDoubles = (a, b) => { if (a !== a) { return b !== b; } @@ -679,11 +634,11 @@ function $rt_equalDoubles(a, b) { && $rt_numberConversionIntArray[1] === $rt_numberConversionIntArray[3]; } -var JavaError; +let JavaError; if (typeof Reflect === 'object') { - var defaultMessage = teavm_globals.Symbol("defaultMessage"); + let defaultMessage = teavm_globals.Symbol("defaultMessage"); JavaError = function JavaError(message, cause) { - var self = teavm_globals.Reflect.construct(teavm_globals.Error, [void 0, cause], JavaError); + let self = teavm_globals.Reflect.construct(teavm_globals.Error, [void 0, cause], JavaError); teavm_globals.Object.setPrototypeOf(self, JavaError.prototype); self[defaultMessage] = message; return self; @@ -695,11 +650,11 @@ if (typeof Reflect === 'object') { value: JavaError }, message: { - get: function() { + get: () => { try { - var javaException = this[$rt_javaExceptionProp]; + let javaException = this[$rt_javaExceptionProp]; if (typeof javaException === 'object') { - var javaMessage = $rt_throwableMessage(javaException); + let javaMessage = $rt_throwableMessage(javaException); if (typeof javaMessage === "object") { return javaMessage !== null ? javaMessage.toString() : null; } @@ -715,16 +670,13 @@ if (typeof Reflect === 'object') { JavaError = teavm_globals.Error; } -function $rt_javaException(e) { - return e instanceof teavm_globals.Error && typeof e[$rt_javaExceptionProp] === 'object' +let $rt_javaException = e => e instanceof teavm_globals.Error && typeof e[$rt_javaExceptionProp] === 'object' ? e[$rt_javaExceptionProp] : null; -} -function $rt_jsException(e) { - return typeof e.$jsException === 'object' ? e.$jsException : null; -} -function $rt_wrapException(err) { - var ex = err[$rt_javaExceptionProp]; + +let $rt_jsException = e => typeof e.$jsException === 'object' ? e.$jsException : null; +let $rt_wrapException = err => { + let ex = err[$rt_javaExceptionProp]; if (!ex) { ex = $rt_createException($rt_str("(JavaScript) " + err.toString())); err[$rt_javaExceptionProp] = ex; @@ -734,14 +686,14 @@ function $rt_wrapException(err) { return ex; } -function $dbg_class(obj) { - var cls = obj.constructor; - var arrayDegree = 0; +let $dbg_class = obj => { + let cls = obj.constructor; + let arrayDegree = 0; while (cls.$meta && cls.$meta.item) { ++arrayDegree; cls = cls.$meta.item; } - var clsName = ""; + let clsName = ""; if (cls === $rt_booleancls) { clsName = "boolean"; } else if (cls === $rt_bytecls) { @@ -771,35 +723,31 @@ function Long(lo, hi) { this.lo = lo | 0; this.hi = hi | 0; } -Long.prototype.__teavm_class__ = function() { +Long.prototype.__teavm_class__ = () => { return "long"; }; -function Long_isPositive(a) { - return (a.hi & 0x80000000) === 0; -} -function Long_isNegative(a) { - return (a.hi & 0x80000000) !== 0; -} +let Long_isPositive = a => (a.hi & 0x80000000) === 0; +let Long_isNegative = a => (a.hi & 0x80000000) !== 0; -var Long_MAX_NORMAL = 1 << 18; -var Long_ZERO; -var Long_create; -var Long_fromInt; -var Long_fromNumber; -var Long_toNumber; -var Long_hi; -var Long_lo; +let Long_MAX_NORMAL = 1 << 18; +let Long_ZERO; +let Long_create; +let Long_fromInt; +let Long_fromNumber; +let Long_toNumber; +let Long_hi; +let Long_lo; if (typeof teavm_globals.BigInt !== "function") { Long.prototype.toString = function() { - var result = []; - var n = this; - var positive = Long_isPositive(n); + let result = []; + let n = this; + let positive = Long_isPositive(n); if (!positive) { n = Long_neg(n); } - var radix = new Long(10, 0); + let radix = new Long(10, 0); do { - var divRem = Long_divRem(n, radix); + let divRem = Long_divRem(n, radix); result.push(teavm_globals.String.fromCharCode(48 + divRem[1].lo)); n = divRem[0]; } while (n.lo !== 0 || n.hi !== 0); @@ -811,88 +759,59 @@ if (typeof teavm_globals.BigInt !== "function") { }; Long_ZERO = new Long(0, 0); - Long_fromInt = function(val) { - return new Long(val, (-(val < 0)) | 0); - } - Long_fromNumber = function(val) { - if (val >= 0) { - return new Long(val | 0, (val / 0x100000000) | 0); - } else { - return Long_neg(new Long(-val | 0, (-val / 0x100000000) | 0)); - } - } - Long_create = function(lo, hi) { - return new Long(lo, hi); - } - Long_toNumber = function(val) { - return 0x100000000 * val.hi + (val.lo >>> 0); - } - Long_hi = function(val) { - return val.hi; - } - Long_lo = function(val) { - return val.lo; - } + Long_fromInt = val =>new Long(val, (-(val < 0)) | 0); + Long_fromNumber = val => val >= 0 + ? new Long(val | 0, (val / 0x100000000) | 0) + : Long_neg(new Long(-val | 0, (-val / 0x100000000) | 0)); + + Long_create = (lo, hi) => new Long(lo, hi); + Long_toNumber = val => 0x100000000 * val.hi + (val.lo >>> 0); + Long_hi = val => val.hi; + Long_lo = val => val.lo; } else { Long_ZERO = teavm_globals.BigInt(0); - Long_create = function(lo, hi) { - return teavm_globals.BigInt.asIntN(64, teavm_globals.BigInt.asUintN(64, teavm_globals.BigInt(lo)) + Long_create = (lo, hi) => teavm_globals.BigInt.asIntN(64, teavm_globals.BigInt.asUintN(64, teavm_globals.BigInt(lo)) | teavm_globals.BigInt.asUintN(64, (teavm_globals.BigInt(hi) << teavm_globals.BigInt(32)))); - } - Long_fromInt = function(val) { - return teavm_globals.BigInt.asIntN(64, teavm_globals.BigInt(val | 0)); - } - Long_fromNumber = function(val) { - return teavm_globals.BigInt.asIntN(64, teavm_globals.BigInt( + Long_fromInt = val => teavm_globals.BigInt.asIntN(64, teavm_globals.BigInt(val | 0)); + Long_fromNumber = val => teavm_globals.BigInt.asIntN(64, teavm_globals.BigInt( val >= 0 ? teavm_globals.Math.floor(val) : teavm_globals.Math.ceil(val))); - } - Long_toNumber = function(val) { - return teavm_globals.Number(val); - } - Long_hi = function(val) { - return teavm_globals.Number(teavm_globals.BigInt.asIntN(64, val >> teavm_globals.BigInt(32))) | 0; - } - Long_lo = function(val) { - return teavm_globals.Number(teavm_globals.BigInt.asIntN(32, val)) | 0; - } + Long_toNumber = val => teavm_globals.Number(val); + Long_hi = val => teavm_globals.Number(teavm_globals.BigInt.asIntN(64, val >> teavm_globals.BigInt(32))) | 0; + Long_lo = val => teavm_globals.Number(teavm_globals.BigInt.asIntN(32, val)) | 0; } -var $rt_imul = teavm_globals.Math.imul || function(a, b) { - var ah = (a >>> 16) & 0xFFFF; - var al = a & 0xFFFF; - var bh = (b >>> 16) & 0xFFFF; - var bl = b & 0xFFFF; +let $rt_imul = teavm_globals.Math.imul || function(a, b) { + let ah = (a >>> 16) & 0xFFFF; + let al = a & 0xFFFF; + let bh = (b >>> 16) & 0xFFFF; + let bl = b & 0xFFFF; return (al * bl + (((ah * bl + al * bh) << 16) >>> 0)) | 0; }; -var $rt_udiv = function(a, b) { - return ((a >>> 0) / (b >>> 0)) >>> 0; -}; -var $rt_umod = function(a, b) { - return ((a >>> 0) % (b >>> 0)) >>> 0; -}; -var $rt_ucmp = function(a, b) { +let $rt_udiv = (a, b) => ((a >>> 0) / (b >>> 0)) >>> 0; +let $rt_umod = (a, b) => ((a >>> 0) % (b >>> 0)) >>> 0; +let $rt_ucmp = (a, b) => { a >>>= 0; b >>>= 0; return a < b ? -1 : a > b ? 1 : 0; }; -function $rt_checkBounds(index, array) { +let $rt_checkBounds = (index, array) => { if (index < 0 || index >= array.length) { $rt_throwAIOOBE(); } return index; } -function $rt_checkUpperBound(index, array) { +let $rt_checkUpperBound = (index, array) => { if (index >= array.length) { $rt_throwAIOOBE(); } return index; } -function $rt_checkLowerBound(index) { +let $rt_checkLowerBound = index => { if (index < 0) { $rt_throwAIOOBE(); } return index; } -function $rt_classWithoutFields(superclass) { +let $rt_classWithoutFields = superclass => { if (superclass === 0) { return function() {}; } @@ -903,109 +822,78 @@ function $rt_classWithoutFields(superclass) { superclass.call(this); }; } -function $rt_charArrayToString(array, offset, count) { - var result = ""; - var limit = offset + count; - for (var i = offset; i < limit; i = (i + 1024) | 0) { - var next = teavm_globals.Math.min(limit, (i + 1024) | 0); +let $rt_charArrayToString = (array, offset, count) => { + let result = ""; + let limit = offset + count; + for (let i = offset; i < limit; i = (i + 1024) | 0) { + let next = teavm_globals.Math.min(limit, (i + 1024) | 0); result += teavm_globals.String.fromCharCode.apply(null, array.subarray(i, next)); } return result; } -function $rt_fullArrayToString(array) { - return $rt_charArrayToString(array, 0, array.length); -} -function $rt_stringToCharArray(string, begin, dst, dstBegin, count) { - for (var i = 0; i < count; i = (i + 1) | 0) { +let $rt_fullArrayToString = (array) => $rt_charArrayToString(array, 0, array.length); +let $rt_stringToCharArray = (string, begin, dst, dstBegin, count) => { + for (let i = 0; i < count; i = (i + 1) | 0) { dst[dstBegin + i] = string.charCodeAt(begin + i); } } -function $rt_fastStringToCharArray(string) { - var array = new teavm_globals.Uint16Array(string.length); - for (var i = 0; i < array.length; ++i) { +let $rt_fastStringToCharArray = string => { + let array = new teavm_globals.Uint16Array(string.length); + for (let i = 0; i < array.length; ++i) { array[i] = string.charCodeAt(i); } return new $rt_charArrayCls(array); } -function $rt_substring(string, start, end) { +let $rt_substring = (string, start, end) => { if (start === 0 && end === string.length) { return string; } - var result = start.substring(start, end - 1) + start.substring(end - 1, end); + let result = start.substring(start, end - 1) + start.substring(end - 1, end); $rt_substringSink = ($rt_substringSink + result.charCodeAt(result.length - 1)) | 0; } -var $rt_substringSink = 0; +let $rt_substringSink = 0; -function $rt_setCloneMethod(target, method) { - target[teavm_javaVirtualMethod('clone()Ljava/lang/Object;')] = method; -} -function $rt_cls(cls) { - return teavm_javaMethod("java.lang.Class", +let $rt_setCloneMethod = (target, method) => target[teavm_javaVirtualMethod('clone()Ljava/lang/Object;')] = method; + +let $rt_cls = (cls) => teavm_javaMethod("java.lang.Class", "getClass(Lorg/teavm/platform/PlatformClass;)Ljava/lang/Class;")(cls); -} -function $rt_str(str) { - if (str === null) { - return null; - } - return teavm_javaConstructor("java.lang.String", "(Ljava/lang/Object;)V")(str); -} -function $rt_ustr(str) { - return str === null ? null : str[teavm_javaField("java.lang.String", "nativeString")]; -} -function $rt_nullCheck(val) { +let $rt_str = str => str === null ? null : teavm_javaConstructor("java.lang.String", "(Ljava/lang/Object;)V")(str); +let $rt_ustr = str => str === null ? null : str[teavm_javaField("java.lang.String", "nativeString")]; +let $rt_nullCheck = val => { if (val === null) { $rt_throw(teavm_javaConstructor("java.lang.NullPointerException", "()V")()); } return val; } -function $rt_stringClassInit() { - teavm_javaClassInit("java.lang.String")(); -} -function $rt_objcls() { - return teavm_javaClass("java.lang.Object"); -} -function $rt_createException(message) { - return teavm_javaConstructor("java.lang.RuntimeException", "(Ljava/lang/String;)V")(message); -} -function $rt_throwableMessage(t) { - return teavm_javaMethod("java.lang.Throwable", "getMessage()Ljava/lang/String;")(t); -} -function $rt_throwableCause(t) { - return teavm_javaMethod("java.lang.Throwable", "getCause()Ljava/lang/Throwable;")(t); -} -function $rt_stecls() { - if (teavm_javaClassExists("java.lang.StackTraceElement")) { - return teavm_javaClass("java.lang.StackTraceElement"); - } else { - return $rt_objcls(); - } -} -function $rt_throwAIOOBE() { - if (teavm_javaConstructorExists("java.lang.ArrayIndexOutOfBoundsException", "()V")) { - $rt_throw(teavm_javaConstructor("java.lang.ArrayIndexOutOfBoundsException", "()V")()); - } else { - $rt_throw($rt_createException($rt_str(""))); - } -} -function $rt_throwCCE() { - if (teavm_javaConstructorExists("java.lang.ClassCastException", "()V")) { - $rt_throw(teavm_javaConstructor("java.lang.ClassCastException", "()V")()); - } else { - $rt_throw($rt_createException($rt_str(""))); - } -} +let $rt_stringClassInit = () => teavm_javaClassInit("java.lang.String")(); +let $rt_objcls = () => teavm_javaClass("java.lang.Object"); +let $rt_createException = message => teavm_javaConstructor("java.lang.RuntimeException", + "(Ljava/lang/String;)V")(message); +let $rt_throwableMessage = t => teavm_javaMethod("java.lang.Throwable", "getMessage()Ljava/lang/String;")(t); +let $rt_throwableCause = t => teavm_javaMethod("java.lang.Throwable", "getCause()Ljava/lang/Throwable;")(t); +let $rt_stecls = () => teavm_javaClassExists("java.lang.StackTraceElement") + ? teavm_javaClass("java.lang.StackTraceElement") + : $rt_objcls(); -function $rt_getThread() { +let $rt_throwAIOOBE = () => teavm_javaConstructorExists("java.lang.ArrayIndexOutOfBoundsException", "()V") + ? $rt_throw(teavm_javaConstructor("java.lang.ArrayIndexOutOfBoundsException", "()V")()) + : $rt_throw($rt_createException($rt_str(""))); + +let $rt_throwCCE = () => teavm_javaConstructorExists("java.lang.ClassCastException", "()V") + ? $rt_throw(teavm_javaConstructor("java.lang.ClassCastException", "()V")()) + : $rt_throw($rt_createException($rt_str(""))); + +let $rt_getThread = () => { if (teavm_javaMethodExists("java.lang.Thread", "currentThread()Ljava/lang/Thread;")) { return teavm_javaMethod("java.lang.Thread", "currentThread()Ljava/lang/Thread;")(); } } -function $rt_setThread(t) { +let $rt_setThread = t => { if (teavm_javaMethodExists("java.lang.Thread", "setCurrentThread(Ljava/lang/Thread;)V")) { return teavm_javaMethod("java.lang.Thread", "setCurrentThread(Ljava/lang/Thread;)V")(t); } } -function $rt_createStackElement(className, methodName, fileName, lineNumber) { +let $rt_createStackElement = (className, methodName, fileName, lineNumber) => { if (teavm_javaConstructorExists("java.lang.StackTraceElement", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V")) { return teavm_javaConstructor("java.lang.StackTraceElement", @@ -1014,7 +902,7 @@ function $rt_createStackElement(className, methodName, fileName, lineNumber) { return null; } } -function $rt_setStack(e, stack) { +let $rt_setStack = (e, stack) => { if (teavm_javaMethodExists("java.lang.Throwable", "setStackTrace([Ljava/lang/StackTraceElement;)V")) { teavm_javaMethod("java.lang.Throwable", "setStackTrace([Ljava/lang/StackTraceElement;)V")(e, stack); } diff --git a/core/src/main/resources/org/teavm/backend/javascript/simpleThread.js b/core/src/main/resources/org/teavm/backend/javascript/simpleThread.js index 4c1fa99e9..647a2cd4e 100644 --- a/core/src/main/resources/org/teavm/backend/javascript/simpleThread.js +++ b/core/src/main/resources/org/teavm/backend/javascript/simpleThread.js @@ -15,8 +15,8 @@ */ "use strict"; -function $rt_startThread(runner, callback) { - var result; +let $rt_startThread = (runner, callback) => { + let result; try { result = runner(); } catch (e) { @@ -28,14 +28,7 @@ function $rt_startThread(runner, callback) { throw result; } } -function $rt_suspending() { - return false; -} -function $rt_resuming() { - return false; -} -function $rt_nativeThread() { - return null; -} -function $rt_invalidPointer() { -} \ No newline at end of file +let $rt_suspending = () => false; +let $rt_resuming = () => false; +let $rt_nativeThread = () => null; +let $rt_invalidPointer = () => {}; \ No newline at end of file diff --git a/core/src/main/resources/org/teavm/backend/javascript/thread.js b/core/src/main/resources/org/teavm/backend/javascript/thread.js index e5ea89f9c..8f19d2ec8 100644 --- a/core/src/main/resources/org/teavm/backend/javascript/thread.js +++ b/core/src/main/resources/org/teavm/backend/javascript/thread.js @@ -24,7 +24,7 @@ function TeaVMThread(runner) { this.completeCallback = null; } TeaVMThread.prototype.push = function() { - for (var i = 0; i < arguments.length; ++i) { + for (let i = 0; i < arguments.length; ++i) { this.stack.push(arguments[i]); } return this; @@ -68,7 +68,7 @@ TeaVMThread.prototype.resume = function() { }; TeaVMThread.prototype.run = function() { $rt_currentNativeThread = this; - var result; + let result; try { result = this.runner(); } catch (e) { @@ -77,8 +77,8 @@ TeaVMThread.prototype.run = function() { $rt_currentNativeThread = null; } if (this.suspendCallback !== null) { - var self = this; - var callback = this.suspendCallback; + let self = this; + let callback = this.suspendCallback; this.suspendCallback = null; callback(() => self.resume()); } else if (this.status === 0) { @@ -86,28 +86,24 @@ TeaVMThread.prototype.run = function() { } }; -function $rt_suspending() { - var thread = $rt_nativeThread(); +let $rt_suspending = () => { + let thread = $rt_nativeThread(); return thread != null && thread.isSuspending(); } -function $rt_resuming() { - var thread = $rt_nativeThread(); +let $rt_resuming = () => { + let thread = $rt_nativeThread(); return thread != null && thread.isResuming(); } -function $rt_suspend(callback) { - var nativeThread = $rt_nativeThread(); +let $rt_suspend = callback => { + let nativeThread = $rt_nativeThread(); if (nativeThread === null) { throw new teavm_globals.Error("Suspension point reached from non-threading context (perhaps, from native JS method)."); } return nativeThread.suspend(callback); } -function $rt_startThread(runner, callback) { - new TeaVMThread(runner).start(callback); -} -var $rt_currentNativeThread = null; -function $rt_nativeThread() { - return $rt_currentNativeThread; -} -function $rt_invalidPointer() { +let $rt_startThread = (runner, callback) => new TeaVMThread(runner).start(callback); +let $rt_currentNativeThread = null; +let $rt_nativeThread = () => $rt_currentNativeThread; +let $rt_invalidPointer = () => { throw new teavm_globals.Error("Invalid recorded state"); } \ No newline at end of file diff --git a/platform/src/main/java/org/teavm/platform/plugin/PlatformGenerator.java b/platform/src/main/java/org/teavm/platform/plugin/PlatformGenerator.java index ee0c358e9..daaf05db5 100644 --- a/platform/src/main/java/org/teavm/platform/plugin/PlatformGenerator.java +++ b/platform/src/main/java/org/teavm/platform/plugin/PlatformGenerator.java @@ -166,7 +166,7 @@ public class PlatformGenerator implements Generator, Injector, DependencyPlugin MethodReference selfRef = new MethodReference(Platform.class, "getEnumConstants", PlatformClass.class, Enum[].class); - writer.appendMethodBody(selfRef).ws().append("=").ws().append("cls").ws().append("=>").ws() + writer.appendMethodBody(selfRef).ws().append("=").ws().append("cls").sameLineWs().append("=>").ws() .append("{").softNewLine().indent(); writer.append("if").ws().append("(!cls.hasOwnProperty(c))").ws().append("{").indent().softNewLine(); writer.append("return null;").softNewLine(); @@ -196,7 +196,7 @@ public class PlatformGenerator implements Generator, Injector, DependencyPlugin MethodReference selfRef = new MethodReference(Platform.class, "getAnnotations", PlatformClass.class, Annotation[].class); - writer.appendMethodBody(selfRef).ws().append("=").ws().append("cls").ws().append("=>").ws() + writer.appendMethodBody(selfRef).ws().append("=").ws().append("cls").sameLineWs().append("=>").ws() .append("{").softNewLine().indent(); writer.append("if").ws().append("(!cls.hasOwnProperty(c))").ws().append("{").indent().softNewLine(); writer.append("return null;").softNewLine();