diff --git a/js/js.translator/testFiles/kotlin_lib.js b/js/js.translator/testFiles/kotlin_lib.js index 7b44d3e7acd..5c26e732d91 100644 --- a/js/js.translator/testFiles/kotlin_lib.js +++ b/js/js.translator/testFiles/kotlin_lib.js @@ -18,15 +18,15 @@ // todo inlined String.prototype.startsWith = function (s) { - return this.indexOf(s) === 0; + return this.indexOf(s) === 0; }; String.prototype.endsWith = function (s) { - return this.indexOf(s, this.length - s.length) !== -1; + return this.indexOf(s, this.length - s.length) !== -1; }; String.prototype.contains = function (s) { - return this.indexOf(s) !== -1; + return this.indexOf(s) !== -1; }; (function () { @@ -57,8 +57,8 @@ String.prototype.contains = function (s) { return o.toString(); } }; - - Kotlin.arrayToString = function(a) { + + Kotlin.arrayToString = function (a) { return "[" + a.join(", ") + "]"; }; @@ -85,11 +85,12 @@ String.prototype.contains = function (s) { }; function throwAbstractFunctionInvocationError(funName) { - return function() { + return function () { var message; if (funName !== undefined) { message = "Function " + funName + " is abstract"; - } else { + } + else { message = "Function is abstract"; } throw new TypeError(message); @@ -147,15 +148,16 @@ String.prototype.contains = function (s) { return this.name(); } }); - (function (){ + (function () { function valueOf(name) { return this[name]; } + function getValues() { return this.values$; } - Kotlin.createEnumEntries = function(enumEntryList) { + Kotlin.createEnumEntries = function (enumEntryList) { var i = 0; var values = []; for (var entryName in enumEntryList) { @@ -175,7 +177,7 @@ String.prototype.contains = function (s) { })(); Kotlin.PropertyMetadata = Kotlin.createClassNow(null, - function(name) { + function (name) { this.name = name; } ); @@ -185,8 +187,9 @@ String.prototype.contains = function (s) { var modified = false; var it = collection.iterator(); while (it.hasNext()) { - if(this.add_za3rmp$(it.next())) + if (this.add_za3rmp$(it.next())) { modified = true; + } } return modified }, @@ -194,7 +197,7 @@ String.prototype.contains = function (s) { var modified = false; var it = this.iterator(); while (it.hasNext()) { - if(c.contains_za3rmp$(it.next())) { + if (c.contains_za3rmp$(it.next())) { it.remove(); modified = true; } @@ -205,14 +208,14 @@ String.prototype.contains = function (s) { var modified = false; var it = this.iterator(); while (it.hasNext()) { - if(!c.contains_za3rmp$(it.next())) { + if (!c.contains_za3rmp$(it.next())) { it.remove(); modified = true; } } return modified }, - containsAll_xeylzf$ : function (c) { + containsAll_xeylzf$: function (c) { var it = c.iterator(); while (it.hasNext()) { if (!this.contains_za3rmp$(it.next())) return false; @@ -342,7 +345,7 @@ String.prototype.contains = function (s) { toJSON: function () { return this.array; }, - checkRange: function(index) { + checkRange: function (index) { if (index < 0 || index >= this.array.length) { throw new RangeError(); } @@ -365,12 +368,12 @@ String.prototype.contains = function (s) { close: throwAbstractFunctionInvocationError("Closeable#close") }); - Kotlin.safeParseInt = function(str) { + Kotlin.safeParseInt = function (str) { var r = parseInt(str, 10); return isNaN(r) ? null : r; }; - Kotlin.safeParseDouble = function(str) { + Kotlin.safeParseDouble = function (str) { var r = parseFloat(str); return isNaN(r) ? null : r; }; @@ -544,11 +547,11 @@ String.prototype.contains = function (s) { function () { this.string = ""; }, { - append:function (obj) { + append: function (obj) { this.string = this.string + obj.toString(); return this; }, - toString:function () { + toString: function () { return this.string; } }); @@ -567,15 +570,21 @@ String.prototype.contains = function (s) { }; Kotlin.numberArrayOfSize = function (size) { - return Kotlin.arrayFromFun(size, function(){ return 0; }); + return Kotlin.arrayFromFun(size, function () { + return 0; + }); }; Kotlin.charArrayOfSize = function (size) { - return Kotlin.arrayFromFun(size, function(){ return '\0'; }); + return Kotlin.arrayFromFun(size, function () { + return '\0'; + }); }; Kotlin.booleanArrayOfSize = function (size) { - return Kotlin.arrayFromFun(size, function(){ return false; }); + return Kotlin.arrayFromFun(size, function () { + return false; + }); }; Kotlin.arrayFromFun = function (size, initFun) { @@ -614,7 +623,7 @@ String.prototype.contains = function (s) { }; })(); -Kotlin.assignOwner = function(f, o) { - f.o = o; - return f; +Kotlin.assignOwner = function (f, o) { + f.o = o; + return f; }; diff --git a/js/js.translator/testFiles/kotlin_lib_ecma5.js b/js/js.translator/testFiles/kotlin_lib_ecma5.js index 40d5f0a6053..e1cef37718c 100644 --- a/js/js.translator/testFiles/kotlin_lib_ecma5.js +++ b/js/js.translator/testFiles/kotlin_lib_ecma5.js @@ -24,7 +24,7 @@ var Kotlin = {}; if (obj == null) { array = []; } - else if(!Array.isArray(obj)) { + else if (!Array.isArray(obj)) { array = [obj]; } else { @@ -53,7 +53,7 @@ var Kotlin = {}; return null; } - var emptyFunction = function() { + var emptyFunction = function () { return function() {}; }; @@ -65,7 +65,7 @@ var Kotlin = {}; }; Kotlin.classCount = 0; - Kotlin.newClassIndex = function() { + Kotlin.newClassIndex = function () { var tmp = Kotlin.classCount; Kotlin.classCount++; return tmp; @@ -83,7 +83,7 @@ var Kotlin = {}; var base = baseGetter(bases[i]); for (var p in base) { if (base.hasOwnProperty(p)) { - if(!current.hasOwnProperty(p) || current[p].$classIndex$ < base[p].$classIndex$) { + if (!current.hasOwnProperty(p) || current[p].$classIndex$ < base[p].$classIndex$) { current[p] = base[p]; } } @@ -107,7 +107,8 @@ var Kotlin = {}; property.$classIndex$ = metadata.classIndex; if (typeof property === "function") { metadata.functions[p] = property; - } else { + } + else { metadata.properties[p] = property; } } @@ -141,7 +142,8 @@ var Kotlin = {}; var prototypeObj; if (metadata.baseClass !== null) { prototypeObj = Object.create(metadata.baseClass.prototype); - } else { + } + else { prototypeObj = {}; } Object.defineProperties(prototypeObj, metadata.properties); @@ -184,7 +186,8 @@ var Kotlin = {}; function getBases(basesFun) { if (typeof basesFun === "function") { return basesFun(); - } else { + } + else { return basesFun; } } @@ -195,6 +198,7 @@ var Kotlin = {}; Object.defineProperty(this, $o.className, {value: klass}); return klass; } + $o.type = Kotlin.TYPE.INIT_FUN; return $o; }; @@ -205,6 +209,7 @@ var Kotlin = {}; Object.defineProperty(this, $o.className, {value: klass}); return klass; } + $o.type = Kotlin.TYPE.INIT_FUN; return $o; }; @@ -213,15 +218,15 @@ var Kotlin = {}; return Kotlin.createObjectNow(getBases(basesFun), constructor, functions); }; - Kotlin.callGetter = function(thisObject, klass, propertyName) { + Kotlin.callGetter = function (thisObject, klass, propertyName) { return klass.$metadata$.properties[propertyName].get.call(thisObject); }; - Kotlin.callSetter = function(thisObject, klass, propertyName, value) { + Kotlin.callSetter = function (thisObject, klass, propertyName, value) { klass.$metadata$.properties[propertyName].set.call(thisObject, value); }; - function isInheritanceFromTrait (objConstructor, trait) { + function isInheritanceFromTrait(objConstructor, trait) { if (isNativeClass(objConstructor) || objConstructor.$metadata$.classIndex < trait.$metadata$.classIndex) { return false; } @@ -243,7 +248,8 @@ var Kotlin = {}; Kotlin.isType = function (object, klass) { if (object == null || klass == null) { return false; - } else { + } + else { if (object instanceof klass) { return true; } @@ -282,13 +288,15 @@ var Kotlin = {}; if (members[p].type === Kotlin.TYPE.INIT_FUN) { members[p].className = p; Object.defineProperty(definition, p, { - get: members[p], - configurable: true + get: members[p], + configurable: true }); - } else { + } + else { definition[p] = members[p]; } - } else { + } + else { Object.defineProperty(definition, p, members[p]); } } @@ -312,11 +320,12 @@ var Kotlin = {}; if (initializer === null) { definition.$initializer$ = emptyFunction(); - } else { + } + else { definition.$initializer$ = initializer; } return definition; - }; + }; Kotlin.defineModule = function (id, declaration) { if (id in Kotlin.modules) { diff --git a/js/js.translator/testFiles/maps.js b/js/js.translator/testFiles/maps.js index 7db55c9ed77..20f8bc7db14 100644 --- a/js/js.translator/testFiles/maps.js +++ b/js/js.translator/testFiles/maps.js @@ -510,13 +510,13 @@ var SetIterator = Kotlin.createClassNow(Kotlin.Iterator, this.keys = set.toArray(); this.index = 0; }, { - next: function() { + next: function () { return this.keys[this.index++]; }, - hasNext: function() { + hasNext: function () { return this.index < this.keys.length; }, - remove: function() { + remove: function () { this.set.remove_za3rmp$(this.keys[this.index - 1]); } }); @@ -529,7 +529,7 @@ Kotlin.PrimitiveHashSet = Kotlin.createClassNow(Kotlin.AbstractCollection, contains_za3rmp$: function (key) { return this.map[key] === true; }, - iterator: function() { + iterator: function () { return new SetIterator(this); }, add_za3rmp$: function (element) { @@ -618,8 +618,9 @@ Kotlin.PrimitiveHashSet = Kotlin.createClassNow(Kotlin.AbstractCollection, var hn1 = iter1.hasNext(); var hn2 = iter2.hasNext(); if (hn1 != hn2) return false; - if (!hn2) + if (!hn2) { return true; + } else { var o1 = iter1.next(); var o2 = iter2.next(); @@ -630,15 +631,17 @@ Kotlin.PrimitiveHashSet = Kotlin.createClassNow(Kotlin.AbstractCollection, return false; }; - this.toString = function() { + this.toString = function () { var builder = "["; var iter = this.iterator(); var first = true; while (iter.hasNext()) { - if (first) + if (first) { first = false; - else + } + else { builder += ", "; + } builder += iter.next(); } builder += "]";