JS backend: KotlinNew => Kotlin
This commit is contained in:
@@ -72,13 +72,13 @@ String.prototype.contains = function (s) {
|
||||
|
||||
Kotlin.modules = {};
|
||||
|
||||
Kotlin.RuntimeException = KotlinNew.createClass();
|
||||
Kotlin.NullPointerException = KotlinNew.createClass();
|
||||
Kotlin.NoSuchElementException = KotlinNew.createClass();
|
||||
Kotlin.IllegalArgumentException = KotlinNew.createClass();
|
||||
Kotlin.IllegalStateException = KotlinNew.createClass();
|
||||
Kotlin.UnsupportedOperationException = KotlinNew.createClass();
|
||||
Kotlin.IOException = KotlinNew.createClass();
|
||||
Kotlin.RuntimeException = Kotlin.createClass();
|
||||
Kotlin.NullPointerException = Kotlin.createClass();
|
||||
Kotlin.NoSuchElementException = Kotlin.createClass();
|
||||
Kotlin.IllegalArgumentException = Kotlin.createClass();
|
||||
Kotlin.IllegalStateException = Kotlin.createClass();
|
||||
Kotlin.UnsupportedOperationException = Kotlin.createClass();
|
||||
Kotlin.IOException = Kotlin.createClass();
|
||||
|
||||
Kotlin.throwNPE = function () {
|
||||
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"),
|
||||
hasNext: throwAbstractFunctionInvocationError("Iterator#hasNext")
|
||||
});
|
||||
|
||||
var ArrayIterator = KotlinNew.createClass(Kotlin.Iterator,
|
||||
var ArrayIterator = Kotlin.createClass(Kotlin.Iterator,
|
||||
function (array) {
|
||||
this.array = array;
|
||||
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) {
|
||||
this.list = list;
|
||||
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 () {
|
||||
this.name$ = 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) {
|
||||
this.name = name;
|
||||
}
|
||||
);
|
||||
|
||||
Kotlin.AbstractCollection = KotlinNew.createClass(Kotlin.Collection, null, {
|
||||
Kotlin.AbstractCollection = Kotlin.createClass(Kotlin.Collection, null, {
|
||||
size: function () {
|
||||
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 () {
|
||||
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)
|
||||
Kotlin.ArrayList = KotlinNew.createClass(Kotlin.AbstractList,
|
||||
Kotlin.ArrayList = Kotlin.createClass(Kotlin.AbstractList,
|
||||
function () {
|
||||
this.array = [];
|
||||
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")
|
||||
});
|
||||
|
||||
Kotlin.Comparable = KotlinNew.createClass(null, null, {
|
||||
Kotlin.Comparable = Kotlin.createClass(null, null, {
|
||||
compareTo: throwAbstractFunctionInvocationError("Comparable#compareTo")
|
||||
});
|
||||
|
||||
Kotlin.Appendable = KotlinNew.createClass(null, null, {
|
||||
Kotlin.Appendable = Kotlin.createClass(null, null, {
|
||||
append: throwAbstractFunctionInvocationError("Appendable#append")
|
||||
});
|
||||
|
||||
Kotlin.Closeable = KotlinNew.createClass(null, null, {
|
||||
Kotlin.Closeable = Kotlin.createClass(null, null, {
|
||||
close: throwAbstractFunctionInvocationError("Closeable#close")
|
||||
});
|
||||
|
||||
@@ -396,7 +396,7 @@ String.prototype.contains = function (s) {
|
||||
Kotlin.System.out().print(s);
|
||||
};
|
||||
|
||||
Kotlin.RangeIterator = KotlinNew.createClass(Kotlin.Iterator,
|
||||
Kotlin.RangeIterator = Kotlin.createClass(Kotlin.Iterator,
|
||||
function (start, end, increment) {
|
||||
this.start = start;
|
||||
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) {
|
||||
this.start = start;
|
||||
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) {
|
||||
this.start = start;
|
||||
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")
|
||||
});
|
||||
|
||||
var ComparatorImpl = KotlinNew.createClass(Kotlin.Comparator,
|
||||
var ComparatorImpl = Kotlin.createClass(Kotlin.Comparator,
|
||||
function (comparator) {
|
||||
this.compare = comparator;
|
||||
}
|
||||
@@ -493,7 +493,7 @@ String.prototype.contains = function (s) {
|
||||
};
|
||||
|
||||
|
||||
Kotlin.StringBuilder = KotlinNew.createClass(null,
|
||||
Kotlin.StringBuilder = Kotlin.createClass(null,
|
||||
function () {
|
||||
this.string = "";
|
||||
}, {
|
||||
|
||||
@@ -72,7 +72,7 @@
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
var KotlinNew = {};
|
||||
var Kotlin = {};
|
||||
|
||||
(function () {
|
||||
|
||||
@@ -103,7 +103,7 @@ var KotlinNew = {};
|
||||
|
||||
function getClass(basesArray) {
|
||||
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];
|
||||
}
|
||||
}
|
||||
@@ -112,16 +112,16 @@ var KotlinNew = {};
|
||||
|
||||
var emptyFunction = function() {};
|
||||
|
||||
KotlinNew.TYPE = {
|
||||
Kotlin.TYPE = {
|
||||
CLASS: "class",
|
||||
TRAIT: "trait",
|
||||
OBJECT: "object"
|
||||
};
|
||||
|
||||
KotlinNew.classCount = 0;
|
||||
KotlinNew.newClassIndex = function() {
|
||||
var tmp = KotlinNew.classCount;
|
||||
KotlinNew.classCount++;
|
||||
Kotlin.classCount = 0;
|
||||
Kotlin.newClassIndex = function() {
|
||||
var tmp = Kotlin.classCount;
|
||||
Kotlin.classCount++;
|
||||
return tmp;
|
||||
};
|
||||
|
||||
@@ -150,7 +150,7 @@ var KotlinNew = {};
|
||||
|
||||
metadata.baseClasses = toArray(bases);
|
||||
metadata.baseClass = getClass(metadata.baseClasses);
|
||||
metadata.classIndex = KotlinNew.newClassIndex();
|
||||
metadata.classIndex = Kotlin.newClassIndex();
|
||||
metadata.functions = {};
|
||||
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();
|
||||
copyProperties(constructor, staticProperties);
|
||||
|
||||
var metadata = computeMetadata(bases, properties);
|
||||
metadata.type = KotlinNew.TYPE.CLASS;
|
||||
metadata.type = Kotlin.TYPE.CLASS;
|
||||
|
||||
var prototypeObj;
|
||||
if (metadata.baseClass !== null) {
|
||||
@@ -228,27 +228,27 @@ var KotlinNew = {};
|
||||
return constructor;
|
||||
};
|
||||
|
||||
KotlinNew.createObject = function (bases, initializer, functions) {
|
||||
var noNameClass = KotlinNew.createClass(bases, initializer, functions);
|
||||
Kotlin.createObject = function (bases, initializer, functions) {
|
||||
var noNameClass = Kotlin.createClass(bases, initializer, functions);
|
||||
var obj = new noNameClass();
|
||||
obj.$metadata$ = {
|
||||
type: KotlinNew.TYPE.OBJECT
|
||||
type: Kotlin.TYPE.OBJECT
|
||||
};
|
||||
return obj;
|
||||
};
|
||||
|
||||
KotlinNew.createTrait = function (bases, properties, staticProperties) {
|
||||
Kotlin.createTrait = function (bases, properties, staticProperties) {
|
||||
var obj = function () {};
|
||||
copyProperties(obj, staticProperties);
|
||||
|
||||
obj.$metadata$ = computeMetadata(bases, properties);
|
||||
obj.$metadata$.type = KotlinNew.TYPE.TRAIT;
|
||||
obj.$metadata$.type = Kotlin.TYPE.TRAIT;
|
||||
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) {
|
||||
return false;
|
||||
} else {
|
||||
@@ -288,7 +288,7 @@ var KotlinNew = {};
|
||||
return definition;
|
||||
}
|
||||
|
||||
KotlinNew.definePackage = function (initializer, members) {
|
||||
Kotlin.definePackage = function (initializer, members) {
|
||||
var definition = createDefinition(members);
|
||||
if (initializer === null) {
|
||||
return {value: definition};
|
||||
@@ -299,7 +299,7 @@ var KotlinNew = {};
|
||||
}
|
||||
};
|
||||
|
||||
KotlinNew.defineRootPackage = function (initializer, members) {
|
||||
Kotlin.defineRootPackage = function (initializer, members) {
|
||||
var definition = createDefinition(members);
|
||||
|
||||
if (initializer === null) {
|
||||
@@ -310,7 +310,7 @@ var KotlinNew = {};
|
||||
return definition;
|
||||
};
|
||||
|
||||
KotlinNew.defineModule = function (id, module) {
|
||||
Kotlin.defineModule = function (id, module) {
|
||||
if (id in Kotlin.modules) {
|
||||
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.Map = KotlinNew.createClass();
|
||||
Kotlin.Map = Kotlin.createClass();
|
||||
|
||||
Kotlin.HashMap = KotlinNew.createClass(Kotlin.Map,
|
||||
Kotlin.HashMap = Kotlin.createClass(Kotlin.Map,
|
||||
function () {
|
||||
Kotlin.HashTable.call(this);
|
||||
}
|
||||
@@ -396,7 +396,7 @@ Kotlin.HashMap = KotlinNew.createClass(Kotlin.Map,
|
||||
Kotlin.ComplexHashMap = Kotlin.HashMap;
|
||||
|
||||
(function () {
|
||||
var PrimitiveHashMapValuesIterator = KotlinNew.createClass(Kotlin.Iterator,
|
||||
var PrimitiveHashMapValuesIterator = Kotlin.createClass(Kotlin.Iterator,
|
||||
function (map, keys) {
|
||||
this.map = map;
|
||||
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) {
|
||||
this.map = map;
|
||||
}, {
|
||||
@@ -426,7 +426,7 @@ Kotlin.ComplexHashMap = Kotlin.HashMap;
|
||||
}
|
||||
});
|
||||
|
||||
Kotlin.PrimitiveHashMap = KotlinNew.createClass(Kotlin.Map,
|
||||
Kotlin.PrimitiveHashMap = Kotlin.createClass(Kotlin.Map,
|
||||
function () {
|
||||
this.$size = 0;
|
||||
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 () {
|
||||
this.$size = 0;
|
||||
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 () {
|
||||
HashSet.call(this);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
(function () {
|
||||
var c = 0;
|
||||
|
||||
Kotlin.A = KotlinNew.createClass(null,
|
||||
Kotlin.A = Kotlin.createClass(null,
|
||||
function () {
|
||||
this.f = function(i) {
|
||||
if (i === undefined && c === 0) {
|
||||
|
||||
Reference in New Issue
Block a user