Skip to content

Commit

Permalink
Revert of Revert of [es6] implement Array.prototype.copyWithin() (pat…
Browse files Browse the repository at this point in the history
…chset #1 id:1 of https://codereview.chromium.org/1084183004/)

Reason for revert:
Check if this CL fails independently of https://chromium.googlesource.com/v8/v8/+/580d66bcda66220d2f3062ac58daf925436df74c

Original issue's description:
> Revert of [es6] implement Array.prototype.copyWithin() (patchset #7 id:120001 of https://codereview.chromium.org/376623004/)
>
> Reason for revert:
> [Sheriff] This causes test failures on mac gc stress:
> http://build.chromium.org/p/client.v8/builders/V8%20Mac%20GC%20Stress/builds/1027
>
> Original issue's description:
> > [es6] implement Array.prototype.copyWithin()
> >
> > https://people.mozilla.org/~jorendorff/es6-draft.html#sec-array.prototype.copywithin
> >
> > BUG=v8:4039
> > R=adamk@chromium.org
> > LOG=N
>
> TBR=dslomov@chromium.org,rossberg@chromium.org,adamk@chromium.org,caitpotter88@gmail.com
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
> BUG=v8:4039
>
> Committed: https://crrev.com/9283fc89710e59445bdc4479454fba97ab9ebdd7
> Cr-Commit-Position: refs/heads/master@{#27984}

TBR=dslomov@chromium.org,rossberg@chromium.org,adamk@chromium.org,caitpotter88@gmail.com
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=v8:4039

Review URL: https://codereview.chromium.org/1072193005

Cr-Commit-Position: refs/heads/master@{#27997}
  • Loading branch information
mi-ac authored and Commit bot committed Apr 22, 2015
1 parent 556221a commit 2739742
Show file tree
Hide file tree
Showing 2 changed files with 393 additions and 0 deletions.
55 changes: 55 additions & 0 deletions src/harmony-array.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,59 @@ var GlobalSymbol = global.Symbol;

// -------------------------------------------------------------------

// ES6 draft 03-17-15, section 22.1.3.3
function ArrayCopyWithin(target, start, end) {
CHECK_OBJECT_COERCIBLE(this, "Array.prototype.copyWithin");

var array = TO_OBJECT_INLINE(this);
var length = ToLength(array.length);

target = TO_INTEGER(target);
var to;
if (target < 0) {
to = $max(length + target, 0);
} else {
to = $min(target, length);
}

start = TO_INTEGER(start);
var from;
if (start < 0) {
from = $max(length + start, 0);
} else {
from = $min(start, length);
}

end = IS_UNDEFINED(end) ? length : TO_INTEGER(end);
var final;
if (end < 0) {
final = $max(length + end, 0);
} else {
final = $min(end, length);
}

var count = $min(final - from, length - to);
var direction = 1;
if (from < to && to < (from + count)) {
direction = -1;
from = from + count - 1;
to = to + count - 1;
}

while (count > 0) {
if (from in array) {
array[to] = array[from];
} else {
delete array[to];
}
from = from + direction;
to = to + direction;
count--;
}

return array;
}

// ES6 draft 07-15-13, section 15.4.3.23
function ArrayFind(predicate /* thisArg */) { // length == 1
CHECK_OBJECT_COERCIBLE(this, "Array.prototype.find");
Expand Down Expand Up @@ -216,6 +269,7 @@ InstallConstants(GlobalSymbol, [
"isConcatSpreadable", symbolIsConcatSpreadable
]);

%FunctionSetLength(ArrayCopyWithin, 2);
%FunctionSetLength(ArrayFrom, 1);

// Set up non-enumerable functions on the Array object.
Expand All @@ -226,6 +280,7 @@ InstallFunctions(GlobalArray, DONT_ENUM, [

// Set up the non-enumerable functions on the Array prototype object.
InstallFunctions(GlobalArray.prototype, DONT_ENUM, [
"copyWithin", ArrayCopyWithin,
"find", ArrayFind,
"findIndex", ArrayFindIndex,
"fill", ArrayFill
Expand Down
Loading

0 comments on commit 2739742

Please sign in to comment.