Refact stdlib generator, add support for different backends
[JS IR BE] Runtime fixes * Do not generate external declarations for IR BE * Move `arrayToString` helper function out of shared JS stdlib * Fix arrays type check for IR BE
This commit is contained in:
@@ -288,12 +288,27 @@ if (typeof ArrayBuffer.isView === "undefined") {
|
||||
}
|
||||
|
||||
// Patch sort to work with TypedArrays if needed.
|
||||
// TODO: consider to remove following function and replace it with `Kotlin.doubleCompareTo` (see misc.js)
|
||||
var totalOrderComparator = function (a, b) {
|
||||
if (a < b) return -1;
|
||||
if (a > b) return 1;
|
||||
|
||||
if (a === b) {
|
||||
if (a !== 0) return 0;
|
||||
|
||||
var ia = 1 / a;
|
||||
return ia === 1 / b ? 0 : (ia < 0 ? -1 : 1);
|
||||
}
|
||||
|
||||
return a !== a ? (b !== b ? 0 : 1) : -1
|
||||
};
|
||||
|
||||
for (var i = 0; i < arrays.length; ++i) {
|
||||
var TypedArray = arrays[i];
|
||||
if (typeof TypedArray.prototype.sort === "undefined") {
|
||||
Object.defineProperty(TypedArray.prototype, 'sort', {
|
||||
value: function(compareFunction) {
|
||||
return Array.prototype.sort.call(this, compareFunction);
|
||||
return Array.prototype.sort.call(this, compareFunction || totalOrderComparator);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
package kotlin.collections
|
||||
|
||||
import kotlin.comparisons.naturalOrder
|
||||
import kotlin.internal.InlineOnly
|
||||
import kotlin.random.Random
|
||||
|
||||
/** Returns the array if it's not `null`, or an empty array otherwise. */
|
||||
@@ -50,10 +49,6 @@ internal actual fun <T> copyToArrayImpl(collection: Collection<*>, array: Array<
|
||||
return array
|
||||
}
|
||||
|
||||
@library("arrayToString")
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
internal fun arrayToString(array: Array<*>): String = definedExternally
|
||||
|
||||
/**
|
||||
* Returns an immutable list containing only the specified object [element].
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package kotlin.collections
|
||||
|
||||
@library("arrayToString")
|
||||
@Suppress("UNUSED_PARAMETER")
|
||||
internal fun arrayToString(array: Array<*>): String = definedExternally
|
||||
Reference in New Issue
Block a user