JS backend: KotlinNew => Kotlin
This commit is contained in:
@@ -72,13 +72,13 @@ String.prototype.contains = function (s) {
|
|||||||
|
|
||||||
Kotlin.modules = {};
|
Kotlin.modules = {};
|
||||||
|
|
||||||
Kotlin.RuntimeException = KotlinNew.createClass();
|
Kotlin.RuntimeException = Kotlin.createClass();
|
||||||
Kotlin.NullPointerException = KotlinNew.createClass();
|
Kotlin.NullPointerException = Kotlin.createClass();
|
||||||
Kotlin.NoSuchElementException = KotlinNew.createClass();
|
Kotlin.NoSuchElementException = Kotlin.createClass();
|
||||||
Kotlin.IllegalArgumentException = KotlinNew.createClass();
|
Kotlin.IllegalArgumentException = Kotlin.createClass();
|
||||||
Kotlin.IllegalStateException = KotlinNew.createClass();
|
Kotlin.IllegalStateException = Kotlin.createClass();
|
||||||
Kotlin.UnsupportedOperationException = KotlinNew.createClass();
|
Kotlin.UnsupportedOperationException = Kotlin.createClass();
|
||||||
Kotlin.IOException = KotlinNew.createClass();
|
Kotlin.IOException = Kotlin.createClass();
|
||||||
|
|
||||||
Kotlin.throwNPE = function () {
|
Kotlin.throwNPE = function () {
|
||||||
throw new Kotlin.NullPointerException();
|
throw new Kotlin.NullPointerException();
|
||||||
@@ -96,12 +96,12 @@ String.prototype.contains = function (s) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Kotlin.Iterator = KotlinNew.createClass(null, null, {
|
Kotlin.Iterator = Kotlin.createClass(null, null, {
|
||||||
next: throwAbstractFunctionInvocationError("Iterator#next"),
|
next: throwAbstractFunctionInvocationError("Iterator#next"),
|
||||||
hasNext: throwAbstractFunctionInvocationError("Iterator#hasNext")
|
hasNext: throwAbstractFunctionInvocationError("Iterator#hasNext")
|
||||||
});
|
});
|
||||||
|
|
||||||
var ArrayIterator = KotlinNew.createClass(Kotlin.Iterator,
|
var ArrayIterator = Kotlin.createClass(Kotlin.Iterator,
|
||||||
function (array) {
|
function (array) {
|
||||||
this.array = array;
|
this.array = array;
|
||||||
this.size = array.length;
|
this.size = array.length;
|
||||||
@@ -115,7 +115,7 @@ String.prototype.contains = function (s) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var ListIterator = KotlinNew.createClass(ArrayIterator,
|
var ListIterator = Kotlin.createClass(ArrayIterator,
|
||||||
function (list) {
|
function (list) {
|
||||||
this.list = list;
|
this.list = list;
|
||||||
this.size = list.size();
|
this.size = list.size();
|
||||||
@@ -126,9 +126,9 @@ String.prototype.contains = function (s) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Kotlin.Collection = KotlinNew.createClass();
|
Kotlin.Collection = Kotlin.createClass();
|
||||||
|
|
||||||
Kotlin.Enum = KotlinNew.createClass(null,
|
Kotlin.Enum = Kotlin.createClass(null,
|
||||||
function () {
|
function () {
|
||||||
this.name$ = undefined;
|
this.name$ = undefined;
|
||||||
this.ordinal$ = undefined;
|
this.ordinal$ = undefined;
|
||||||
@@ -170,13 +170,13 @@ String.prototype.contains = function (s) {
|
|||||||
};
|
};
|
||||||
})();
|
})();
|
||||||
|
|
||||||
Kotlin.PropertyMetadata = KotlinNew.createClass(null,
|
Kotlin.PropertyMetadata = Kotlin.createClass(null,
|
||||||
function(name) {
|
function(name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
Kotlin.AbstractCollection = KotlinNew.createClass(Kotlin.Collection, null, {
|
Kotlin.AbstractCollection = Kotlin.createClass(Kotlin.Collection, null, {
|
||||||
size: function () {
|
size: function () {
|
||||||
return this.$size;
|
return this.$size;
|
||||||
},
|
},
|
||||||
@@ -229,7 +229,7 @@ String.prototype.contains = function (s) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Kotlin.AbstractList = KotlinNew.createClass(Kotlin.AbstractCollection, null, {
|
Kotlin.AbstractList = Kotlin.createClass(Kotlin.AbstractCollection, null, {
|
||||||
iterator: function () {
|
iterator: function () {
|
||||||
return new ListIterator(this);
|
return new ListIterator(this);
|
||||||
},
|
},
|
||||||
@@ -245,7 +245,7 @@ String.prototype.contains = function (s) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
//TODO: should be JS Array-like (https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Predefined_Core_Objects#Working_with_Array-like_objects)
|
//TODO: should be JS Array-like (https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Predefined_Core_Objects#Working_with_Array-like_objects)
|
||||||
Kotlin.ArrayList = KotlinNew.createClass(Kotlin.AbstractList,
|
Kotlin.ArrayList = Kotlin.createClass(Kotlin.AbstractList,
|
||||||
function () {
|
function () {
|
||||||
this.array = [];
|
this.array = [];
|
||||||
this.$size = 0;
|
this.$size = 0;
|
||||||
@@ -312,19 +312,19 @@ String.prototype.contains = function (s) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Kotlin.Runnable = KotlinNew.createClass(null, null, {
|
Kotlin.Runnable = Kotlin.createClass(null, null, {
|
||||||
run: throwAbstractFunctionInvocationError("Runnable#run")
|
run: throwAbstractFunctionInvocationError("Runnable#run")
|
||||||
});
|
});
|
||||||
|
|
||||||
Kotlin.Comparable = KotlinNew.createClass(null, null, {
|
Kotlin.Comparable = Kotlin.createClass(null, null, {
|
||||||
compareTo: throwAbstractFunctionInvocationError("Comparable#compareTo")
|
compareTo: throwAbstractFunctionInvocationError("Comparable#compareTo")
|
||||||
});
|
});
|
||||||
|
|
||||||
Kotlin.Appendable = KotlinNew.createClass(null, null, {
|
Kotlin.Appendable = Kotlin.createClass(null, null, {
|
||||||
append: throwAbstractFunctionInvocationError("Appendable#append")
|
append: throwAbstractFunctionInvocationError("Appendable#append")
|
||||||
});
|
});
|
||||||
|
|
||||||
Kotlin.Closeable = KotlinNew.createClass(null, null, {
|
Kotlin.Closeable = Kotlin.createClass(null, null, {
|
||||||
close: throwAbstractFunctionInvocationError("Closeable#close")
|
close: throwAbstractFunctionInvocationError("Closeable#close")
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -396,7 +396,7 @@ String.prototype.contains = function (s) {
|
|||||||
Kotlin.System.out().print(s);
|
Kotlin.System.out().print(s);
|
||||||
};
|
};
|
||||||
|
|
||||||
Kotlin.RangeIterator = KotlinNew.createClass(Kotlin.Iterator,
|
Kotlin.RangeIterator = Kotlin.createClass(Kotlin.Iterator,
|
||||||
function (start, end, increment) {
|
function (start, end, increment) {
|
||||||
this.start = start;
|
this.start = start;
|
||||||
this.end = end;
|
this.end = end;
|
||||||
@@ -413,7 +413,7 @@ String.prototype.contains = function (s) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Kotlin.NumberRange = KotlinNew.createClass(null,
|
Kotlin.NumberRange = Kotlin.createClass(null,
|
||||||
function (start, end) {
|
function (start, end) {
|
||||||
this.start = start;
|
this.start = start;
|
||||||
this.end = end;
|
this.end = end;
|
||||||
@@ -427,7 +427,7 @@ String.prototype.contains = function (s) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Kotlin.Progression = KotlinNew.createClass(null,
|
Kotlin.Progression = Kotlin.createClass(null,
|
||||||
function (start, end, increment) {
|
function (start, end, increment) {
|
||||||
this.start = start;
|
this.start = start;
|
||||||
this.end = end;
|
this.end = end;
|
||||||
@@ -438,11 +438,11 @@ String.prototype.contains = function (s) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Kotlin.Comparator = KotlinNew.createClass(null, null, {
|
Kotlin.Comparator = Kotlin.createClass(null, null, {
|
||||||
compare: throwAbstractFunctionInvocationError("Comparator#compare")
|
compare: throwAbstractFunctionInvocationError("Comparator#compare")
|
||||||
});
|
});
|
||||||
|
|
||||||
var ComparatorImpl = KotlinNew.createClass(Kotlin.Comparator,
|
var ComparatorImpl = Kotlin.createClass(Kotlin.Comparator,
|
||||||
function (comparator) {
|
function (comparator) {
|
||||||
this.compare = comparator;
|
this.compare = comparator;
|
||||||
}
|
}
|
||||||
@@ -493,7 +493,7 @@ String.prototype.contains = function (s) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
Kotlin.StringBuilder = KotlinNew.createClass(null,
|
Kotlin.StringBuilder = Kotlin.createClass(null,
|
||||||
function () {
|
function () {
|
||||||
this.string = "";
|
this.string = "";
|
||||||
}, {
|
}, {
|
||||||
|
|||||||
@@ -72,7 +72,7 @@
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
var KotlinNew = {};
|
var Kotlin = {};
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
|
|
||||||
@@ -103,7 +103,7 @@ var KotlinNew = {};
|
|||||||
|
|
||||||
function getClass(basesArray) {
|
function getClass(basesArray) {
|
||||||
for (var i = 0; i < basesArray.length; i++) {
|
for (var i = 0; i < basesArray.length; i++) {
|
||||||
if (isNativeClass(basesArray[i]) || basesArray[i].$metadata$.type === KotlinNew.TYPE.CLASS) {
|
if (isNativeClass(basesArray[i]) || basesArray[i].$metadata$.type === Kotlin.TYPE.CLASS) {
|
||||||
return basesArray[i];
|
return basesArray[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -112,16 +112,16 @@ var KotlinNew = {};
|
|||||||
|
|
||||||
var emptyFunction = function() {};
|
var emptyFunction = function() {};
|
||||||
|
|
||||||
KotlinNew.TYPE = {
|
Kotlin.TYPE = {
|
||||||
CLASS: "class",
|
CLASS: "class",
|
||||||
TRAIT: "trait",
|
TRAIT: "trait",
|
||||||
OBJECT: "object"
|
OBJECT: "object"
|
||||||
};
|
};
|
||||||
|
|
||||||
KotlinNew.classCount = 0;
|
Kotlin.classCount = 0;
|
||||||
KotlinNew.newClassIndex = function() {
|
Kotlin.newClassIndex = function() {
|
||||||
var tmp = KotlinNew.classCount;
|
var tmp = Kotlin.classCount;
|
||||||
KotlinNew.classCount++;
|
Kotlin.classCount++;
|
||||||
return tmp;
|
return tmp;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -150,7 +150,7 @@ var KotlinNew = {};
|
|||||||
|
|
||||||
metadata.baseClasses = toArray(bases);
|
metadata.baseClasses = toArray(bases);
|
||||||
metadata.baseClass = getClass(metadata.baseClasses);
|
metadata.baseClass = getClass(metadata.baseClasses);
|
||||||
metadata.classIndex = KotlinNew.newClassIndex();
|
metadata.classIndex = Kotlin.newClassIndex();
|
||||||
metadata.functions = {};
|
metadata.functions = {};
|
||||||
metadata.properties = {};
|
metadata.properties = {};
|
||||||
|
|
||||||
@@ -194,12 +194,12 @@ var KotlinNew = {};
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
KotlinNew.createClass = function (bases, initializer, properties, staticProperties) {
|
Kotlin.createClass = function (bases, initializer, properties, staticProperties) {
|
||||||
var constructor = createConstructor();
|
var constructor = createConstructor();
|
||||||
copyProperties(constructor, staticProperties);
|
copyProperties(constructor, staticProperties);
|
||||||
|
|
||||||
var metadata = computeMetadata(bases, properties);
|
var metadata = computeMetadata(bases, properties);
|
||||||
metadata.type = KotlinNew.TYPE.CLASS;
|
metadata.type = Kotlin.TYPE.CLASS;
|
||||||
|
|
||||||
var prototypeObj;
|
var prototypeObj;
|
||||||
if (metadata.baseClass !== null) {
|
if (metadata.baseClass !== null) {
|
||||||
@@ -228,27 +228,27 @@ var KotlinNew = {};
|
|||||||
return constructor;
|
return constructor;
|
||||||
};
|
};
|
||||||
|
|
||||||
KotlinNew.createObject = function (bases, initializer, functions) {
|
Kotlin.createObject = function (bases, initializer, functions) {
|
||||||
var noNameClass = KotlinNew.createClass(bases, initializer, functions);
|
var noNameClass = Kotlin.createClass(bases, initializer, functions);
|
||||||
var obj = new noNameClass();
|
var obj = new noNameClass();
|
||||||
obj.$metadata$ = {
|
obj.$metadata$ = {
|
||||||
type: KotlinNew.TYPE.OBJECT
|
type: Kotlin.TYPE.OBJECT
|
||||||
};
|
};
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
KotlinNew.createTrait = function (bases, properties, staticProperties) {
|
Kotlin.createTrait = function (bases, properties, staticProperties) {
|
||||||
var obj = function () {};
|
var obj = function () {};
|
||||||
copyProperties(obj, staticProperties);
|
copyProperties(obj, staticProperties);
|
||||||
|
|
||||||
obj.$metadata$ = computeMetadata(bases, properties);
|
obj.$metadata$ = computeMetadata(bases, properties);
|
||||||
obj.$metadata$.type = KotlinNew.TYPE.TRAIT;
|
obj.$metadata$.type = Kotlin.TYPE.TRAIT;
|
||||||
return obj;
|
return obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
KotlinNew.keys = Object.keys; // TODO drop
|
Kotlin.keys = Object.keys; // TODO drop
|
||||||
|
|
||||||
KotlinNew.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 {
|
||||||
@@ -288,7 +288,7 @@ var KotlinNew = {};
|
|||||||
return definition;
|
return definition;
|
||||||
}
|
}
|
||||||
|
|
||||||
KotlinNew.definePackage = function (initializer, members) {
|
Kotlin.definePackage = function (initializer, members) {
|
||||||
var definition = createDefinition(members);
|
var definition = createDefinition(members);
|
||||||
if (initializer === null) {
|
if (initializer === null) {
|
||||||
return {value: definition};
|
return {value: definition};
|
||||||
@@ -299,7 +299,7 @@ var KotlinNew = {};
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
KotlinNew.defineRootPackage = function (initializer, members) {
|
Kotlin.defineRootPackage = function (initializer, members) {
|
||||||
var definition = createDefinition(members);
|
var definition = createDefinition(members);
|
||||||
|
|
||||||
if (initializer === null) {
|
if (initializer === null) {
|
||||||
@@ -310,7 +310,7 @@ var KotlinNew = {};
|
|||||||
return definition;
|
return definition;
|
||||||
};
|
};
|
||||||
|
|
||||||
KotlinNew.defineModule = function (id, module) {
|
Kotlin.defineModule = function (id, module) {
|
||||||
if (id in Kotlin.modules) {
|
if (id in Kotlin.modules) {
|
||||||
throw new Kotlin.IllegalArgumentException();
|
throw new Kotlin.IllegalArgumentException();
|
||||||
}
|
}
|
||||||
@@ -321,54 +321,3 @@ var KotlinNew = {};
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Be aware — Google Chrome has serious issue — you can rewrite READ-ONLY property (if it is defined in prototype). Firefox and Safari work correct.
|
|
||||||
// Always test property access issues in Firefox, but not in Chrome.
|
|
||||||
var Kotlin = Object.create(null);
|
|
||||||
|
|
||||||
(function () {
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
Kotlin.keys = KotlinNew.keys;
|
|
||||||
|
|
||||||
Kotlin.isType = function (object, type) {
|
|
||||||
return KotlinNew.isType(object, type);
|
|
||||||
};
|
|
||||||
|
|
||||||
Kotlin.createTrait = function (bases, properties, staticProperties) {
|
|
||||||
return KotlinNew.createTrait(bases, properties, staticProperties);
|
|
||||||
};
|
|
||||||
|
|
||||||
Kotlin.createClass = function (bases, initializer, properties, staticProperties) {
|
|
||||||
return KotlinNew.createClass(bases, initializer, properties, staticProperties);
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
Kotlin.createObject = function (bases, initializer, properties) {
|
|
||||||
return KotlinNew.createObject(bases, initializer, properties)
|
|
||||||
};
|
|
||||||
|
|
||||||
Kotlin.definePackage = function (initializer, members) {
|
|
||||||
return KotlinNew.definePackage(initializer, members);
|
|
||||||
};
|
|
||||||
|
|
||||||
Kotlin.defineRootPackage = function (initializer, members) {
|
|
||||||
return KotlinNew.defineRootPackage(initializer, members);
|
|
||||||
};
|
|
||||||
|
|
||||||
Kotlin.defineModule = function (id, module) {
|
|
||||||
KotlinNew.defineModule(id, module);
|
|
||||||
};
|
|
||||||
|
|
||||||
})();
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -385,9 +385,9 @@
|
|||||||
Kotlin.HashTable = Hashtable;
|
Kotlin.HashTable = Hashtable;
|
||||||
})();
|
})();
|
||||||
|
|
||||||
Kotlin.Map = KotlinNew.createClass();
|
Kotlin.Map = Kotlin.createClass();
|
||||||
|
|
||||||
Kotlin.HashMap = KotlinNew.createClass(Kotlin.Map,
|
Kotlin.HashMap = Kotlin.createClass(Kotlin.Map,
|
||||||
function () {
|
function () {
|
||||||
Kotlin.HashTable.call(this);
|
Kotlin.HashTable.call(this);
|
||||||
}
|
}
|
||||||
@@ -396,7 +396,7 @@ Kotlin.HashMap = KotlinNew.createClass(Kotlin.Map,
|
|||||||
Kotlin.ComplexHashMap = Kotlin.HashMap;
|
Kotlin.ComplexHashMap = Kotlin.HashMap;
|
||||||
|
|
||||||
(function () {
|
(function () {
|
||||||
var PrimitiveHashMapValuesIterator = KotlinNew.createClass(Kotlin.Iterator,
|
var PrimitiveHashMapValuesIterator = Kotlin.createClass(Kotlin.Iterator,
|
||||||
function (map, keys) {
|
function (map, keys) {
|
||||||
this.map = map;
|
this.map = map;
|
||||||
this.keys = keys;
|
this.keys = keys;
|
||||||
@@ -411,7 +411,7 @@ Kotlin.ComplexHashMap = Kotlin.HashMap;
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
var PrimitiveHashMapValues = KotlinNew.createClass(Kotlin.Collection,
|
var PrimitiveHashMapValues = Kotlin.createClass(Kotlin.Collection,
|
||||||
function (map) {
|
function (map) {
|
||||||
this.map = map;
|
this.map = map;
|
||||||
}, {
|
}, {
|
||||||
@@ -426,7 +426,7 @@ Kotlin.ComplexHashMap = Kotlin.HashMap;
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Kotlin.PrimitiveHashMap = KotlinNew.createClass(Kotlin.Map,
|
Kotlin.PrimitiveHashMap = Kotlin.createClass(Kotlin.Map,
|
||||||
function () {
|
function () {
|
||||||
this.$size = 0;
|
this.$size = 0;
|
||||||
this.map = {};
|
this.map = {};
|
||||||
@@ -502,9 +502,9 @@ Kotlin.ComplexHashMap = Kotlin.HashMap;
|
|||||||
});
|
});
|
||||||
}());
|
}());
|
||||||
|
|
||||||
Kotlin.Set = KotlinNew.createClass(Kotlin.Collection);
|
Kotlin.Set = Kotlin.createClass(Kotlin.Collection);
|
||||||
|
|
||||||
Kotlin.PrimitiveHashSet = KotlinNew.createClass(Kotlin.AbstractCollection,
|
Kotlin.PrimitiveHashSet = Kotlin.createClass(Kotlin.AbstractCollection,
|
||||||
function () {
|
function () {
|
||||||
this.$size = 0;
|
this.$size = 0;
|
||||||
this.map = {};
|
this.map = {};
|
||||||
@@ -662,7 +662,7 @@ Kotlin.PrimitiveHashSet = KotlinNew.createClass(Kotlin.AbstractCollection,
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Kotlin.HashSet = KotlinNew.createClass(Kotlin.Set,
|
Kotlin.HashSet = Kotlin.createClass(Kotlin.Set,
|
||||||
function () {
|
function () {
|
||||||
HashSet.call(this);
|
HashSet.call(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
(function () {
|
(function () {
|
||||||
var c = 0;
|
var c = 0;
|
||||||
|
|
||||||
Kotlin.A = KotlinNew.createClass(null,
|
Kotlin.A = Kotlin.createClass(null,
|
||||||
function () {
|
function () {
|
||||||
this.f = function(i) {
|
this.f = function(i) {
|
||||||
if (i === undefined && c === 0) {
|
if (i === undefined && c === 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user