JS: fixed <Type>Array.iterator methods; added -Xtypedarray compiler key
The <Type>Array.iterator used to lack next<Type>() method (KT-16626). The -Xtypedarray compiler key enables translation of primitive arrays to TypedArrays, and primitive array`is`-checks (KT-15358, KT-14007, KT-14614, KT-16056).
This commit is contained in:
+52
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2010-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
function normalizeOffset(offset, length) {
|
||||
if (offset < 0) return Math.max(0, offset + length);
|
||||
return Math.min(offset, length);
|
||||
}
|
||||
function typedArraySlice(begin, end) {
|
||||
if (typeof end === "undefined") {
|
||||
end = this.length;
|
||||
}
|
||||
begin = normalizeOffset(begin || 0, this.length);
|
||||
end = Math.max(begin, normalizeOffset(end, this.length));
|
||||
return new this.constructor(this.subarray(begin, end));
|
||||
}
|
||||
|
||||
var arrays = [Int8Array, Int16Array, Uint16Array, Int32Array, Float32Array, Float64Array];
|
||||
for (var i = 0; i < arrays.length; ++i) {
|
||||
var TypedArray = arrays[i];
|
||||
if (typeof TypedArray.prototype.slice === "undefined") {
|
||||
Object.defineProperty(TypedArray.prototype, 'slice', {
|
||||
value: typedArraySlice
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Patch apply to work with TypedArrays if needed.
|
||||
try {
|
||||
(function() {}).apply(null, new Int32Array(0))
|
||||
} catch (e) {
|
||||
var apply = Function.prototype.apply;
|
||||
Object.defineProperty(Function.prototype, 'apply', {
|
||||
value: function(self, array) {
|
||||
return apply.call(this, self, [].slice.call(array));
|
||||
}
|
||||
});
|
||||
}
|
||||
})();
|
||||
Vendored
+2
-2
@@ -3,10 +3,10 @@
|
||||
<head>
|
||||
<script type="application/javascript" src="../../../dist/js/kotlin.js"></script>
|
||||
<script type="application/javascript" src="../../../dist/classes/kotlin-test-js/kotlin-test.js"></script>
|
||||
<script type="application/javascript" src="../../../js/js.translator/testData/out/box/standardClasses/stringBuilder_v5.js"></script>
|
||||
<script type="application/javascript" src="../../../js/js.translator/testData/out/codegen/box/arrays/primitiveArrays_v5.js"></script>
|
||||
|
||||
<script type="application/javascript">
|
||||
console.log(JS_TESTS.foo.box());
|
||||
console.log(JS_TESTS.box());
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
Reference in New Issue
Block a user