KT-3008 Merge JS runtime modules in one kotlin.js
This commit is contained in:
+9
-3
@@ -1,13 +1,19 @@
|
||||
(function (root, factory) {
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define('Kotlin', [], factory);
|
||||
define('kotlin', [], factory);
|
||||
} else if (typeof exports === 'object') {
|
||||
module.exports = factory();
|
||||
} else {
|
||||
root.Kotlin = factory();
|
||||
root.kotlin = factory();
|
||||
}
|
||||
}(this, function () {
|
||||
var Kotlin = {};
|
||||
var kotlin = Kotlin;
|
||||
function require() {
|
||||
return Kotlin;
|
||||
}
|
||||
var module = {};
|
||||
%output%
|
||||
return Kotlin;
|
||||
Kotlin.modules.kotlin = mergedRoot;
|
||||
return mergedRoot;
|
||||
}));
|
||||
+1
-1
@@ -32,7 +32,7 @@ var JsTests = (function () {
|
||||
|
||||
var init = function () {
|
||||
init = function() {};
|
||||
Kotlin.modules["JS_TESTS"].kotlin.test.init();
|
||||
kotlin.modules.JS_TESTS.kotlin.test.init();
|
||||
};
|
||||
|
||||
var test = function (testName, testFun) {
|
||||
|
||||
+18
-14
@@ -274,7 +274,7 @@
|
||||
*/
|
||||
lazyInitClasses.ArrayIterator = Kotlin.createClass(
|
||||
function () {
|
||||
return [Kotlin.modules['builtins'].kotlin.collections.MutableIterator];
|
||||
return [Kotlin.kotlin.collections.MutableIterator];
|
||||
},
|
||||
/** @constructs */
|
||||
function (array) {
|
||||
@@ -306,7 +306,7 @@
|
||||
*/
|
||||
lazyInitClasses.ListIterator = Kotlin.createClass(
|
||||
function () {
|
||||
return [Kotlin.modules['builtins'].kotlin.collections.ListIterator]; // TODO: MutableListIterator
|
||||
return [Kotlin.kotlin.collections.ListIterator]; // TODO: MutableListIterator
|
||||
},
|
||||
/** @constructs */
|
||||
function (list, index) {
|
||||
@@ -340,6 +340,8 @@
|
||||
}
|
||||
});
|
||||
|
||||
Kotlin.Annotation = Kotlin.createTraitNow(null);
|
||||
|
||||
Kotlin.Enum = Kotlin.createClassNow(null,
|
||||
function () {
|
||||
this.name$ = void 0;
|
||||
@@ -380,7 +382,7 @@
|
||||
|
||||
lazyInitClasses.AbstractCollection = Kotlin.createClass(
|
||||
function () {
|
||||
return [Kotlin.modules['builtins'].kotlin.collections.MutableCollection];
|
||||
return [Kotlin.kotlin.collections.MutableCollection];
|
||||
}, null, {
|
||||
addAll_wtfk93$: function (collection) {
|
||||
var modified = false;
|
||||
@@ -474,7 +476,7 @@
|
||||
*/
|
||||
lazyInitClasses.AbstractList = Kotlin.createClass(
|
||||
function () {
|
||||
return [Kotlin.modules['builtins'].kotlin.collections.MutableList, Kotlin.AbstractCollection];
|
||||
return [Kotlin.kotlin.collections.MutableList, Kotlin.AbstractCollection];
|
||||
}, null, {
|
||||
iterator: function () {
|
||||
return new Kotlin.ListIterator(this);
|
||||
@@ -792,7 +794,7 @@
|
||||
|
||||
lazyInitClasses.RangeIterator = Kotlin.createClass(
|
||||
function () {
|
||||
return [Kotlin.modules['builtins'].kotlin.collections.Iterator];
|
||||
return [Kotlin.kotlin.collections.Iterator];
|
||||
},
|
||||
function (start, end, step) {
|
||||
this.start = start;
|
||||
@@ -878,7 +880,7 @@
|
||||
|
||||
lazyInitClasses.NumberProgression = Kotlin.createClass(
|
||||
function () {
|
||||
return [Kotlin.modules['builtins'].kotlin.collections.Iterable];
|
||||
return [Kotlin.kotlin.collections.Iterable];
|
||||
},
|
||||
function (start, end, step) {
|
||||
this.first = start;
|
||||
@@ -904,7 +906,7 @@
|
||||
|
||||
lazyInitClasses.NumberRange = Kotlin.createClass(
|
||||
function() {
|
||||
return [Kotlin.modules['builtins'].kotlin.ranges.ClosedRange, Kotlin.NumberProgression]
|
||||
return [Kotlin.kotlin.ranges.ClosedRange, Kotlin.NumberProgression]
|
||||
},
|
||||
function $fun(start, endInclusive) {
|
||||
$fun.baseInitializer.call(this, start, endInclusive, 1);
|
||||
@@ -934,7 +936,7 @@
|
||||
|
||||
lazyInitClasses.LongRangeIterator = Kotlin.createClass(
|
||||
function () {
|
||||
return [Kotlin.modules['builtins'].kotlin.collections.Iterator];
|
||||
return [Kotlin.kotlin.collections.Iterator];
|
||||
},
|
||||
function (start, end, step) {
|
||||
this.start = start;
|
||||
@@ -957,7 +959,7 @@
|
||||
|
||||
lazyInitClasses.LongProgression = Kotlin.createClass(
|
||||
function () {
|
||||
return [Kotlin.modules['builtins'].kotlin.collections.Iterable];
|
||||
return [Kotlin.kotlin.collections.Iterable];
|
||||
},
|
||||
function (start, end, step) {
|
||||
this.first = start;
|
||||
@@ -983,7 +985,7 @@
|
||||
|
||||
lazyInitClasses.LongRange = Kotlin.createClass(
|
||||
function () {
|
||||
return [Kotlin.modules['builtins'].kotlin.ranges.ClosedRange, Kotlin.LongProgression];
|
||||
return [Kotlin.kotlin.ranges.ClosedRange, Kotlin.LongProgression];
|
||||
},
|
||||
function $fun(start, endInclusive) {
|
||||
$fun.baseInitializer.call(this, start, endInclusive, Kotlin.Long.ONE);
|
||||
@@ -1027,7 +1029,7 @@
|
||||
|
||||
lazyInitClasses.CharProgression = Kotlin.createClassNow(
|
||||
function () {
|
||||
return [Kotlin.modules['builtins'].kotlin.collections.Iterable];
|
||||
return [Kotlin.kotlin.collections.Iterable];
|
||||
},
|
||||
function (start, end, step) {
|
||||
this.first = start;
|
||||
@@ -1056,7 +1058,7 @@
|
||||
|
||||
lazyInitClasses.CharRange = Kotlin.createClass(
|
||||
function() {
|
||||
return [Kotlin.modules['builtins'].kotlin.ranges.ClosedRange, Kotlin.CharProgression]
|
||||
return [Kotlin.kotlin.ranges.ClosedRange, Kotlin.CharProgression]
|
||||
},
|
||||
function $fun(start, endInclusive) {
|
||||
$fun.baseInitializer.call(this, start, endInclusive, 1);
|
||||
@@ -1238,6 +1240,8 @@
|
||||
}
|
||||
return obj1;
|
||||
};
|
||||
|
||||
Kotlin.createDefinition(lazyInitClasses, Kotlin);
|
||||
|
||||
Kotlin.lazyInitClasses = Kotlin.lazyInitClasses || [];
|
||||
Kotlin.lazyInitClasses.push(lazyInitClasses);
|
||||
})(Kotlin);
|
||||
|
||||
|
||||
+12
-11
@@ -186,7 +186,8 @@
|
||||
//noinspection JSUnfilteredForInLoop
|
||||
Object.defineProperty(constructor, innerTypeName, {
|
||||
get: innerType,
|
||||
configurable: true
|
||||
configurable: true,
|
||||
enumerable: true
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -225,7 +226,7 @@
|
||||
Kotlin.createClass = function (basesFun, constructor, properties, staticProperties) {
|
||||
function $o() {
|
||||
var klass = Kotlin.createClassNow(getBases(basesFun), constructor, properties, staticProperties);
|
||||
Object.defineProperty(this, $o.className, {value: klass});
|
||||
Object.defineProperty(this, $o.className, {value: klass, enumerable: true});
|
||||
if (staticProperties && staticProperties.object_initializer$) {
|
||||
staticProperties.object_initializer$(klass);
|
||||
}
|
||||
@@ -301,7 +302,7 @@
|
||||
Kotlin.createTrait = function (basesFun, properties, staticProperties) {
|
||||
function $o() {
|
||||
var klass = Kotlin.createTraitNow(getBases(basesFun), properties, staticProperties);
|
||||
Object.defineProperty(this, $o.className, {value: klass});
|
||||
Object.defineProperty(this, $o.className, {value: klass, enumerable: true});
|
||||
return klass;
|
||||
}
|
||||
|
||||
@@ -324,7 +325,7 @@
|
||||
var obj = new klass();
|
||||
var metadata = klass.$metadata$;
|
||||
metadata.type = Kotlin.TYPE.OBJECT;
|
||||
Object.defineProperty(this, $o.className, {value: obj});
|
||||
Object.defineProperty(this, $o.className, {value: obj, enumerable: true});
|
||||
defineNestedTypes(obj, klass.$metadata$.types);
|
||||
copyProperties(obj, metadata.staticMembers);
|
||||
if (metadata.baseClass != null) {
|
||||
@@ -511,7 +512,8 @@
|
||||
members[p].className = p;
|
||||
Object.defineProperty(definition, p, {
|
||||
get: members[p],
|
||||
configurable: true
|
||||
configurable: true,
|
||||
enumerable: true
|
||||
});
|
||||
}
|
||||
else {
|
||||
@@ -536,11 +538,11 @@
|
||||
Kotlin.definePackage = function (initializer, members) {
|
||||
var definition = createDefinition(members);
|
||||
if (initializer === null) {
|
||||
return {value: definition};
|
||||
return {value: definition, enumerable: true};
|
||||
}
|
||||
else {
|
||||
var getter = createPackageGetter(definition, initializer);
|
||||
return {get: getter};
|
||||
return {get: getter, enumerable: true};
|
||||
}
|
||||
};
|
||||
|
||||
@@ -561,11 +563,10 @@
|
||||
* @param {Object} declaration
|
||||
*/
|
||||
Kotlin.defineModule = function (id, declaration) {
|
||||
if (id in Kotlin.modules) {
|
||||
throw new Error("Module " + id + " is already defined");
|
||||
if (typeof declaration.$initializer$ === "function") {
|
||||
declaration.$initializer$.call(declaration); // TODO: temporary hack
|
||||
}
|
||||
declaration.$initializer$.call(declaration); // TODO: temporary hack
|
||||
Object.defineProperty(Kotlin.modules, id, {value: declaration});
|
||||
Kotlin.modules[id] = declaration;
|
||||
};
|
||||
|
||||
Kotlin.defineInlineFunction = function(tag, fun) {
|
||||
|
||||
Vendored
+7
-8
@@ -14,8 +14,6 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
var Kotlin = Kotlin || {};
|
||||
|
||||
(function (Kotlin) {
|
||||
"use strict";
|
||||
|
||||
@@ -523,7 +521,7 @@ var Kotlin = Kotlin || {};
|
||||
|
||||
lazyInitClasses.HashMap = Kotlin.createClass(
|
||||
function () {
|
||||
return [Kotlin.HashTable, Kotlin.modules['builtins'].kotlin.collections.MutableMap];
|
||||
return [Kotlin.HashTable, Kotlin.kotlin.collections.MutableMap];
|
||||
},
|
||||
function () {
|
||||
Kotlin.HashTable.call(this);
|
||||
@@ -543,7 +541,7 @@ var Kotlin = Kotlin || {};
|
||||
*/
|
||||
lazyInitClasses.PrimitiveHashMapValuesIterator = Kotlin.createClass(
|
||||
function () {
|
||||
return [Kotlin.modules['builtins'].kotlin.collections.Iterator];
|
||||
return [Kotlin.kotlin.collections.Iterator];
|
||||
},
|
||||
function (map, keys) {
|
||||
this.map = map;
|
||||
@@ -828,7 +826,7 @@ var Kotlin = Kotlin || {};
|
||||
|
||||
lazyInitClasses.LinkedHashSet = Kotlin.createClass(
|
||||
function () {
|
||||
return [Kotlin.modules['builtins'].kotlin.collections.MutableSet, Kotlin.HashSet];
|
||||
return [Kotlin.kotlin.collections.MutableSet, Kotlin.HashSet];
|
||||
},
|
||||
/** @constructs */
|
||||
function () {
|
||||
@@ -870,7 +868,7 @@ var Kotlin = Kotlin || {};
|
||||
*/
|
||||
lazyInitClasses.SetIterator = Kotlin.createClass(
|
||||
function () {
|
||||
return [Kotlin.modules['builtins'].kotlin.collections.MutableIterator];
|
||||
return [Kotlin.kotlin.collections.MutableIterator];
|
||||
},
|
||||
function (set) {
|
||||
this.set = set;
|
||||
@@ -1117,7 +1115,7 @@ var Kotlin = Kotlin || {};
|
||||
|
||||
lazyInitClasses.HashSet = Kotlin.createClass(
|
||||
function () {
|
||||
return [Kotlin.modules['builtins'].kotlin.collections.MutableSet, Kotlin.AbstractCollection];
|
||||
return [Kotlin.kotlin.collections.MutableSet, Kotlin.AbstractCollection];
|
||||
},
|
||||
function () {
|
||||
HashSet.call(this);
|
||||
@@ -1126,5 +1124,6 @@ var Kotlin = Kotlin || {};
|
||||
|
||||
Object.defineProperty(Kotlin, "ComplexHashSet", { get : function () { return Kotlin.HashSet; }});
|
||||
|
||||
Kotlin.createDefinition(lazyInitClasses, Kotlin);
|
||||
Kotlin.lazyInitClasses = Kotlin.lazyInitClasses || [];
|
||||
Kotlin.lazyInitClasses.push(lazyInitClasses);
|
||||
}(Kotlin));
|
||||
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
var mergedRoot = Kotlin;
|
||||
for (var propertyName in stdlib) {
|
||||
Kotlin[propertyName] = stdlib[propertyName];
|
||||
}
|
||||
(function () {
|
||||
for (var i = 0; i < Kotlin.lazyInitClasses.length; ++i) {
|
||||
Kotlin.createDefinition(Kotlin.lazyInitClasses[i], mergedRoot);
|
||||
}
|
||||
})();
|
||||
+1
-1
@@ -9,7 +9,7 @@ fun box(): String {
|
||||
|
||||
assertEquals(5, eval("3 + 2"))
|
||||
|
||||
val PACKAGE = "Kotlin.modules.JS_TESTS.foo"
|
||||
val PACKAGE = "kotlin.modules.JS_TESTS.foo"
|
||||
assertEquals(top, eval("$PACKAGE.top"))
|
||||
|
||||
return "OK"
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package foo
|
||||
|
||||
internal val PACKAGE = "Kotlin.modules.JS_TESTS.foo"
|
||||
internal val PACKAGE = "kotlin.modules.JS_TESTS.foo"
|
||||
|
||||
internal fun funToString(name: String) = eval("$PACKAGE.$name.toString()") as String
|
||||
|
||||
|
||||
+6
-6
@@ -23,7 +23,7 @@ var buffer: String = noImpl
|
||||
fun test(expected: String, initCode: String, getResult: () -> String) {
|
||||
buffer = ""
|
||||
|
||||
eval("Kotlin.out = new $initCode")
|
||||
eval("kotlin.out = new $initCode")
|
||||
|
||||
print("Hello")
|
||||
print(", World")
|
||||
@@ -40,19 +40,19 @@ fun test(expected: String, initCode: String, getResult: () -> String) {
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
test(EXPECTED, "Kotlin.NodeJsOutput(outputStream)") {
|
||||
test(EXPECTED, "kotlin.NodeJsOutput(outputStream)") {
|
||||
buffer
|
||||
}
|
||||
|
||||
test(EXPECTED_NEWLINE_FOR_EACH, "Kotlin.OutputToConsoleLog()") {
|
||||
test(EXPECTED_NEWLINE_FOR_EACH, "kotlin.OutputToConsoleLog()") {
|
||||
buffer
|
||||
}
|
||||
|
||||
test(EXPECTED, "Kotlin.BufferedOutput()") {
|
||||
eval("Kotlin.out.buffer") as String
|
||||
test(EXPECTED, "kotlin.BufferedOutput()") {
|
||||
eval("kotlin.out.buffer") as String
|
||||
}
|
||||
|
||||
test(EXPECTED, "Kotlin.BufferedOutputToConsoleLog()") {
|
||||
test(EXPECTED, "kotlin.BufferedOutputToConsoleLog()") {
|
||||
buffer
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
(function () {
|
||||
var c = 0;
|
||||
|
||||
Kotlin.A = Kotlin.createClassNow(null,
|
||||
kotlin.A = kotlin.createClassNow(null,
|
||||
function () {
|
||||
this.f = function (i) {
|
||||
if (i === undefined && c === 0) {
|
||||
@@ -13,7 +13,7 @@
|
||||
}
|
||||
}
|
||||
);
|
||||
Kotlin.getResult = function () {
|
||||
kotlin.getResult = function () {
|
||||
return c === 2;
|
||||
};
|
||||
})();
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package foo
|
||||
|
||||
val PACKAGE = "Kotlin.modules.JS_TESTS.foo"
|
||||
val PACKAGE = "kotlin.modules.JS_TESTS.foo"
|
||||
|
||||
class A
|
||||
@native val Any.__proto__: String get() = noImpl
|
||||
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
var builtins = module.exports;
|
||||
delete Kotlin.modules.kotlin;
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
var stdlib = module.exports;
|
||||
delete Kotlin.modules.kotlin;
|
||||
@@ -15,7 +15,7 @@ fun box(): String {
|
||||
test("byteArrayOf", byteArrayOf(0, 1, 2, 3, 4), "0, 1, 2, 3, 4")
|
||||
test("shortArrayOf", shortArrayOf(0, 1, 2, 3, 4), "0, 1, 2, 3, 4")
|
||||
test("intArray,", intArrayOf(0, 1, 2, 3, 4), "0, 1, 2, 3, 4")
|
||||
test("longArrayOf", longArrayOf(0, 1, 2, 3, 4), "Kotlin.Long.fromInt(0), Kotlin.Long.fromInt(1), Kotlin.Long.fromInt(2), Kotlin.Long.fromInt(3), Kotlin.Long.fromInt(4)")
|
||||
test("longArrayOf", longArrayOf(0, 1, 2, 3, 4), "kotlin.Long.fromInt(0), kotlin.Long.fromInt(1), kotlin.Long.fromInt(2), kotlin.Long.fromInt(3), kotlin.Long.fromInt(4)")
|
||||
test("floatArrayOf", floatArrayOf(0.0f, 1.0f, 2.0f, 3.0f, 4.0f), "0.0, 1.0, 2.0, 3.0, 4.0")
|
||||
test("doubleArrayOf", doubleArrayOf(0.0, 1.1, 2.2, 3.3, 4.4), "0.0, 1.1, 2.2, 3.3, 4.4")
|
||||
}
|
||||
|
||||
Vendored
+3
-5
@@ -1,13 +1,11 @@
|
||||
<!-- for debugging tests in browser -->
|
||||
<html>
|
||||
<head>
|
||||
<script type="application/javascript" src="kotlin_lib_ecma5.js"></script>
|
||||
<script type="application/javascript" src="kotlin_lib.js"></script>
|
||||
|
||||
<script type="application/javascript" src="webDemoExamples2/out/life_v5.js"></script>
|
||||
<script type="application/javascript" src="../../../dist/js/kotlin.js"></script>
|
||||
<script type="application/javascript" src="native/out/eval_v5.js"></script>
|
||||
|
||||
<script type="application/javascript">
|
||||
console.log(Kotlin.modules.JS_TESTS.foo.box());
|
||||
console.log(JS_TESTS.foo.box());
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ fun box(): String {
|
||||
if (!hasProp(b, "foo")) return "B hasn't foo"
|
||||
if (!hasProp(b, "boo")) return "B hasn't boo"
|
||||
|
||||
val PREFIX = "Kotlin.modules.JS_TESTS.foo"
|
||||
val PREFIX = "kotlin.modules.JS_TESTS.foo"
|
||||
if (eval("$PREFIX.A") == null) return "$PREFIX.A not found"
|
||||
if (eval("$PREFIX.B") == null) return "$PREFIX.B not found"
|
||||
if (eval("$PREFIX.A === $PREFIX.B") as Boolean) return "A and B refer to the same object"
|
||||
|
||||
Reference in New Issue
Block a user