
com.google.javascript.jscomp.js.es6.array.copywithin.js Maven / Gradle / Ivy
/*
* Copyright 2016 The Closure Compiler Authors.
*
* 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.
*/
'require util/polyfill';
$jscomp.polyfill('Array.prototype.copyWithin', function(orig) {
if (orig) return orig;
/**
* Copies elements from one part of the array to another.
*
* @this {!IArrayLike}
* @param {number} target Start index to copy elements to.
* @param {number} start Start index to copy elements from.
* @param {number=} opt_end Index from which to end copying.
* @return {!IArrayLike} The array, with the copy performed in-place.
* @template VALUE
*/
var polyfill = function(target, start, opt_end) {
var len = this.length;
target = Number(target);
start = Number(start);
opt_end = Number(opt_end != null ? opt_end : len);
if (target < start) {
opt_end = Math.min(opt_end, len);
while (start < opt_end) {
if (start in this) {
this[target++] = this[start++];
} else {
delete this[target++];
start++;
}
}
} else {
opt_end = Math.min(opt_end, len + start - target);
target += opt_end - start;
while (opt_end > start) {
if (--opt_end in this) {
this[--target] = this[opt_end];
} else {
delete this[target];
}
}
}
return this;
};
return polyfill;
}, 'es6-impl', 'es3');
© 2015 - 2025 Weber Informatics LLC | Privacy Policy