Minor change: reformat js libs.

This commit is contained in:
Zalim Bashorov
2014-02-14 15:39:55 +04:00
parent 38d1142c39
commit bcd579acdd
3 changed files with 71 additions and 50 deletions
+28 -19
View File
@@ -58,7 +58,7 @@ String.prototype.contains = function (s) {
} }
}; };
Kotlin.arrayToString = function(a) { Kotlin.arrayToString = function (a) {
return "[" + a.join(", ") + "]"; return "[" + a.join(", ") + "]";
}; };
@@ -85,11 +85,12 @@ String.prototype.contains = function (s) {
}; };
function throwAbstractFunctionInvocationError(funName) { function throwAbstractFunctionInvocationError(funName) {
return function() { return function () {
var message; var message;
if (funName !== undefined) { if (funName !== undefined) {
message = "Function " + funName + " is abstract"; message = "Function " + funName + " is abstract";
} else { }
else {
message = "Function is abstract"; message = "Function is abstract";
} }
throw new TypeError(message); throw new TypeError(message);
@@ -147,15 +148,16 @@ String.prototype.contains = function (s) {
return this.name(); return this.name();
} }
}); });
(function (){ (function () {
function valueOf(name) { function valueOf(name) {
return this[name]; return this[name];
} }
function getValues() { function getValues() {
return this.values$; return this.values$;
} }
Kotlin.createEnumEntries = function(enumEntryList) { Kotlin.createEnumEntries = function (enumEntryList) {
var i = 0; var i = 0;
var values = []; var values = [];
for (var entryName in enumEntryList) { for (var entryName in enumEntryList) {
@@ -175,7 +177,7 @@ String.prototype.contains = function (s) {
})(); })();
Kotlin.PropertyMetadata = Kotlin.createClassNow(null, Kotlin.PropertyMetadata = Kotlin.createClassNow(null,
function(name) { function (name) {
this.name = name; this.name = name;
} }
); );
@@ -185,16 +187,17 @@ String.prototype.contains = function (s) {
var modified = false; var modified = false;
var it = collection.iterator(); var it = collection.iterator();
while (it.hasNext()) { while (it.hasNext()) {
if(this.add_za3rmp$(it.next())) if (this.add_za3rmp$(it.next())) {
modified = true; modified = true;
} }
}
return modified return modified
}, },
removeAll_xeylzf$: function (c) { removeAll_xeylzf$: function (c) {
var modified = false; var modified = false;
var it = this.iterator(); var it = this.iterator();
while (it.hasNext()) { while (it.hasNext()) {
if(c.contains_za3rmp$(it.next())) { if (c.contains_za3rmp$(it.next())) {
it.remove(); it.remove();
modified = true; modified = true;
} }
@@ -205,14 +208,14 @@ String.prototype.contains = function (s) {
var modified = false; var modified = false;
var it = this.iterator(); var it = this.iterator();
while (it.hasNext()) { while (it.hasNext()) {
if(!c.contains_za3rmp$(it.next())) { if (!c.contains_za3rmp$(it.next())) {
it.remove(); it.remove();
modified = true; modified = true;
} }
} }
return modified return modified
}, },
containsAll_xeylzf$ : function (c) { containsAll_xeylzf$: function (c) {
var it = c.iterator(); var it = c.iterator();
while (it.hasNext()) { while (it.hasNext()) {
if (!this.contains_za3rmp$(it.next())) return false; if (!this.contains_za3rmp$(it.next())) return false;
@@ -342,7 +345,7 @@ String.prototype.contains = function (s) {
toJSON: function () { toJSON: function () {
return this.array; return this.array;
}, },
checkRange: function(index) { checkRange: function (index) {
if (index < 0 || index >= this.array.length) { if (index < 0 || index >= this.array.length) {
throw new RangeError(); throw new RangeError();
} }
@@ -365,12 +368,12 @@ String.prototype.contains = function (s) {
close: throwAbstractFunctionInvocationError("Closeable#close") close: throwAbstractFunctionInvocationError("Closeable#close")
}); });
Kotlin.safeParseInt = function(str) { Kotlin.safeParseInt = function (str) {
var r = parseInt(str, 10); var r = parseInt(str, 10);
return isNaN(r) ? null : r; return isNaN(r) ? null : r;
}; };
Kotlin.safeParseDouble = function(str) { Kotlin.safeParseDouble = function (str) {
var r = parseFloat(str); var r = parseFloat(str);
return isNaN(r) ? null : r; return isNaN(r) ? null : r;
}; };
@@ -544,11 +547,11 @@ String.prototype.contains = function (s) {
function () { function () {
this.string = ""; this.string = "";
}, { }, {
append:function (obj) { append: function (obj) {
this.string = this.string + obj.toString(); this.string = this.string + obj.toString();
return this; return this;
}, },
toString:function () { toString: function () {
return this.string; return this.string;
} }
}); });
@@ -567,15 +570,21 @@ String.prototype.contains = function (s) {
}; };
Kotlin.numberArrayOfSize = function (size) { Kotlin.numberArrayOfSize = function (size) {
return Kotlin.arrayFromFun(size, function(){ return 0; }); return Kotlin.arrayFromFun(size, function () {
return 0;
});
}; };
Kotlin.charArrayOfSize = function (size) { Kotlin.charArrayOfSize = function (size) {
return Kotlin.arrayFromFun(size, function(){ return '\0'; }); return Kotlin.arrayFromFun(size, function () {
return '\0';
});
}; };
Kotlin.booleanArrayOfSize = function (size) { Kotlin.booleanArrayOfSize = function (size) {
return Kotlin.arrayFromFun(size, function(){ return false; }); return Kotlin.arrayFromFun(size, function () {
return false;
});
}; };
Kotlin.arrayFromFun = function (size, initFun) { Kotlin.arrayFromFun = function (size, initFun) {
@@ -614,7 +623,7 @@ String.prototype.contains = function (s) {
}; };
})(); })();
Kotlin.assignOwner = function(f, o) { Kotlin.assignOwner = function (f, o) {
f.o = o; f.o = o;
return f; return f;
}; };
+23 -14
View File
@@ -24,7 +24,7 @@ var Kotlin = {};
if (obj == null) { if (obj == null) {
array = []; array = [];
} }
else if(!Array.isArray(obj)) { else if (!Array.isArray(obj)) {
array = [obj]; array = [obj];
} }
else { else {
@@ -53,7 +53,7 @@ var Kotlin = {};
return null; return null;
} }
var emptyFunction = function() { var emptyFunction = function () {
return function() {}; return function() {};
}; };
@@ -65,7 +65,7 @@ var Kotlin = {};
}; };
Kotlin.classCount = 0; Kotlin.classCount = 0;
Kotlin.newClassIndex = function() { Kotlin.newClassIndex = function () {
var tmp = Kotlin.classCount; var tmp = Kotlin.classCount;
Kotlin.classCount++; Kotlin.classCount++;
return tmp; return tmp;
@@ -83,7 +83,7 @@ var Kotlin = {};
var base = baseGetter(bases[i]); var base = baseGetter(bases[i]);
for (var p in base) { for (var p in base) {
if (base.hasOwnProperty(p)) { 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]; current[p] = base[p];
} }
} }
@@ -107,7 +107,8 @@ var Kotlin = {};
property.$classIndex$ = metadata.classIndex; property.$classIndex$ = metadata.classIndex;
if (typeof property === "function") { if (typeof property === "function") {
metadata.functions[p] = property; metadata.functions[p] = property;
} else { }
else {
metadata.properties[p] = property; metadata.properties[p] = property;
} }
} }
@@ -141,7 +142,8 @@ var Kotlin = {};
var prototypeObj; var prototypeObj;
if (metadata.baseClass !== null) { if (metadata.baseClass !== null) {
prototypeObj = Object.create(metadata.baseClass.prototype); prototypeObj = Object.create(metadata.baseClass.prototype);
} else { }
else {
prototypeObj = {}; prototypeObj = {};
} }
Object.defineProperties(prototypeObj, metadata.properties); Object.defineProperties(prototypeObj, metadata.properties);
@@ -184,7 +186,8 @@ var Kotlin = {};
function getBases(basesFun) { function getBases(basesFun) {
if (typeof basesFun === "function") { if (typeof basesFun === "function") {
return basesFun(); return basesFun();
} else { }
else {
return basesFun; return basesFun;
} }
} }
@@ -195,6 +198,7 @@ var Kotlin = {};
Object.defineProperty(this, $o.className, {value: klass}); Object.defineProperty(this, $o.className, {value: klass});
return klass; return klass;
} }
$o.type = Kotlin.TYPE.INIT_FUN; $o.type = Kotlin.TYPE.INIT_FUN;
return $o; return $o;
}; };
@@ -205,6 +209,7 @@ var Kotlin = {};
Object.defineProperty(this, $o.className, {value: klass}); Object.defineProperty(this, $o.className, {value: klass});
return klass; return klass;
} }
$o.type = Kotlin.TYPE.INIT_FUN; $o.type = Kotlin.TYPE.INIT_FUN;
return $o; return $o;
}; };
@@ -213,15 +218,15 @@ var Kotlin = {};
return Kotlin.createObjectNow(getBases(basesFun), constructor, functions); 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); 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); 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) { if (isNativeClass(objConstructor) || objConstructor.$metadata$.classIndex < trait.$metadata$.classIndex) {
return false; return false;
} }
@@ -243,7 +248,8 @@ var Kotlin = {};
Kotlin.isType = function (object, klass) { Kotlin.isType = function (object, klass) {
if (object == null || klass == null) { if (object == null || klass == null) {
return false; return false;
} else { }
else {
if (object instanceof klass) { if (object instanceof klass) {
return true; return true;
} }
@@ -285,10 +291,12 @@ var Kotlin = {};
get: members[p], get: members[p],
configurable: true configurable: true
}); });
} else { }
else {
definition[p] = members[p]; definition[p] = members[p];
} }
} else { }
else {
Object.defineProperty(definition, p, members[p]); Object.defineProperty(definition, p, members[p]);
} }
} }
@@ -312,7 +320,8 @@ var Kotlin = {};
if (initializer === null) { if (initializer === null) {
definition.$initializer$ = emptyFunction(); definition.$initializer$ = emptyFunction();
} else { }
else {
definition.$initializer$ = initializer; definition.$initializer$ = initializer;
} }
return definition; return definition;
+11 -8
View File
@@ -510,13 +510,13 @@ var SetIterator = Kotlin.createClassNow(Kotlin.Iterator,
this.keys = set.toArray(); this.keys = set.toArray();
this.index = 0; this.index = 0;
}, { }, {
next: function() { next: function () {
return this.keys[this.index++]; return this.keys[this.index++];
}, },
hasNext: function() { hasNext: function () {
return this.index < this.keys.length; return this.index < this.keys.length;
}, },
remove: function() { remove: function () {
this.set.remove_za3rmp$(this.keys[this.index - 1]); this.set.remove_za3rmp$(this.keys[this.index - 1]);
} }
}); });
@@ -529,7 +529,7 @@ Kotlin.PrimitiveHashSet = Kotlin.createClassNow(Kotlin.AbstractCollection,
contains_za3rmp$: function (key) { contains_za3rmp$: function (key) {
return this.map[key] === true; return this.map[key] === true;
}, },
iterator: function() { iterator: function () {
return new SetIterator(this); return new SetIterator(this);
}, },
add_za3rmp$: function (element) { add_za3rmp$: function (element) {
@@ -618,8 +618,9 @@ Kotlin.PrimitiveHashSet = Kotlin.createClassNow(Kotlin.AbstractCollection,
var hn1 = iter1.hasNext(); var hn1 = iter1.hasNext();
var hn2 = iter2.hasNext(); var hn2 = iter2.hasNext();
if (hn1 != hn2) return false; if (hn1 != hn2) return false;
if (!hn2) if (!hn2) {
return true; return true;
}
else { else {
var o1 = iter1.next(); var o1 = iter1.next();
var o2 = iter2.next(); var o2 = iter2.next();
@@ -630,15 +631,17 @@ Kotlin.PrimitiveHashSet = Kotlin.createClassNow(Kotlin.AbstractCollection,
return false; return false;
}; };
this.toString = function() { this.toString = function () {
var builder = "["; var builder = "[";
var iter = this.iterator(); var iter = this.iterator();
var first = true; var first = true;
while (iter.hasNext()) { while (iter.hasNext()) {
if (first) if (first) {
first = false; first = false;
else }
else {
builder += ", "; builder += ", ";
}
builder += iter.next(); builder += iter.next();
} }
builder += "]"; builder += "]";