Chromium Code Reviews| Index: src/harmony-array.js | 
| diff --git a/src/harmony-array.js b/src/harmony-array.js | 
| index dc7d71fcb4dca34110756793db4953325ca95b8e..d5dde144657494ff1fe34e65d323ea3e1090bbde 100644 | 
| --- a/src/harmony-array.js | 
| +++ b/src/harmony-array.js | 
| @@ -10,6 +10,72 @@ | 
| // ------------------------------------------------------------------- | 
| +// ES6 draft 05-22-14, section 22.1.3.3 | 
| +function ArrayCopyWithin(target, start /* [ , end ] */ ) { // length == 2 | 
| + CHECK_OBJECT_COERCIBLE(this, "Array.prototype.copyWithin"); | 
| 
 
adamk
2015/04/20 17:26:14
For consistency I feel like we might as well leave
 
 | 
| + | 
| + var array = ToObject(this); | 
| + var length = ToInteger(array.length); | 
| + var to; | 
| + var from; | 
| + var relativeEnd = length; | 
| + var end; | 
| + var final; | 
| + var count; | 
| + var direction = 1; | 
| + var fromVal; | 
| + | 
| + target = ToInteger(target); | 
| + if (target < 0) { | 
| + to = MathMax(length + target, 0); | 
| + } else { | 
| + to = MathMin(target, length); | 
| + } | 
| + | 
| + start = ToInteger(start); | 
| + | 
| + if (start < 0) { | 
| + from = MathMax(length + start, 0); | 
| + } else { | 
| + from = MathMin(start, length); | 
| + } | 
| + | 
| + if (%_ArgumentsLength() > 2) { | 
| + end = %_Arguments(2); | 
| + if (!IS_UNDEFINED(end)) { | 
| + relativeEnd = ToInteger(end); | 
| + } | 
| + } | 
| + | 
| + if (relativeEnd < 0) { | 
| + final = MathMax(length + relativeEnd, 0); | 
| + } else { | 
| + final = MathMin(relativeEnd, length); | 
| + } | 
| + | 
| + count = MathMin(final - from, length - to); | 
| + | 
| + if (from < to && to < (from + count)) { | 
| + direction = -1; | 
| + from = from + count - 1; | 
| + to = to + count - 1; | 
| + } | 
| + | 
| + while (count > 0) { | 
| + if (from in array) { | 
| + fromVal = array[from]; | 
| + array[to] = fromVal; | 
| + } 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"); | 
| @@ -232,6 +298,7 @@ function HarmonyArrayExtendArrayPrototype() { | 
| // Set up the non-enumerable functions on the Array prototype object. | 
| InstallFunctions($Array.prototype, DONT_ENUM, [ | 
| + "copyWithin", ArrayCopyWithin, | 
| "find", ArrayFind, | 
| "findIndex", ArrayFindIndex, | 
| "fill", ArrayFill |