org.teavm.backend.javascript.array.js Maven / Gradle / Ivy
/*
* Copyright 2019 Alexey Andreev.
*
* 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 $rt_array(cls, data) {
$rt_initMonitorField(this);
this.$id$ = 0;
this.type = cls;
this.data = data;
this.constructor = $rt_arraycls(cls);
}
$rt_array.prototype = Object.create($rt_objcls().prototype);
$rt_array.prototype.toString = function() {
var str = "[";
for (var i = 0; i < this.data.length; ++i) {
if (i > 0) {
str += ", ";
}
str += this.data[i].toString();
}
str += "]";
return str;
};
$rt_setCloneMethod($rt_array.prototype, function () {
var dataCopy;
if ('slice' in this.data) {
dataCopy = this.data.slice();
} else {
dataCopy = new this.data.constructor(this.data.length);
for (var i = 0; i < dataCopy.length; ++i) {
dataCopy[i] = this.data[i];
}
}
return new $rt_array(this.type, dataCopy);
});
© 2015 - 2024 Weber Informatics LLC | Privacy Policy