function
ArraySlice(start,
end
) {
CHECK_OBJECT_COERCIBLE(this,
"Array.prototype.slice"
);
var
array
= TO_OBJECT(this);
var
len = TO_LENGTH(
array
.length);
var
start_i = TO_INTEGER(start);
var
end_i = len;
if
(!IS_UNDEFINED(
end
)) end_i = TO_INTEGER(
end
);
if
(start_i < 0) {
start_i += len;
if
(start_i < 0) start_i = 0;
}
else
{
if
(start_i > len) start_i = len;
}
if
(end_i < 0) {
end_i += len;
if
(end_i < 0) end_i = 0;
}
else
{
if
(end_i > len) end_i = len;
}
var
result = ArraySpeciesCreate(
array
, MaxSimple(end_i - start_i, 0));
if
(end_i < start_i)
return
result;
if
(UseSparseVariant(
array
, len,
IS_ARRAY
(
array
), end_i - start_i)) {
%NormalizeElements(
array
);
if
(
IS_ARRAY
(result)) %NormalizeElements(result);
SparseSlice(
array
, start_i, end_i - start_i, len, result);
}
else
{
SimpleSlice(
array
, start_i, end_i - start_i, len, result);
}
result.length = end_i - start_i;
return
result;
}
function
SparseSlice(
array
, start_i, del_count, len, deleted_elements) {
var
indices = %GetArrayKeys(
array
, start_i + del_count);
if
(IS_NUMBER(indices)) {
var
limit = indices;
for
(
var
i = start_i; i < limit; ++i) {
var
current =
array
[i];
if
(!IS_UNDEFINED(current) || i in
array
) {
%CreateDataProperty(deleted_elements, i - start_i, current);
}
}
}
else
{
var
length = indices.length;
for
(
var
k = 0; k < length; ++k) {
var
key = indices[k];
if
(key >= start_i) {
var
current =
array
[key];
if
(!IS_UNDEFINED(current) || key in
array
) {
%CreateDataProperty(deleted_elements, key - start_i, current);
}
}
}
}
}
function
SimpleSlice(
array
, start_i, del_count, len, deleted_elements) {
for
(
var
i = 0; i < del_count; i++) {
var
index = start_i + i;
if
(index in
array
) {
var
current =
array
[index];
%CreateDataProperty(deleted_elements, i, current);
}
}
}