Chromium Code Reviews| Index: src/harmony-array.js |
| diff --git a/src/harmony-array.js b/src/harmony-array.js |
| index acf1b145e414774ab6604da2dd0bb7268e936d38..e6c2b8027afe11ad8e94e5f667a0e7603694a0a4 100644 |
| --- a/src/harmony-array.js |
| +++ b/src/harmony-array.js |
| @@ -3,6 +3,9 @@ |
| // found in the LICENSE file. |
| var $innerArrayCopyWithin; |
| +var $innerArrayFill; |
| +var $innerArrayFind; |
| +var $innerArrayFindIndex; |
| (function(global, exports) { |
| @@ -73,22 +76,11 @@ function ArrayCopyWithin(target, start, end) { |
| return InnerArrayCopyWithin(target, start, end, array, length); |
| } |
| -// ES6 draft 07-15-13, section 15.4.3.23 |
| -function ArrayFind(predicate /* thisArg */) { // length == 1 |
| - CHECK_OBJECT_COERCIBLE(this, "Array.prototype.find"); |
| - |
| - var array = $toObject(this); |
| - var length = $toInteger(array.length); |
| - |
| +function InnerArrayFind(predicate, thisArg, array, length) { |
| if (!IS_SPEC_FUNCTION(predicate)) { |
| throw MakeTypeError(kCalledNonCallable, predicate); |
| } |
| - var thisArg; |
| - if (%_ArgumentsLength() > 1) { |
| - thisArg = %_Arguments(1); |
| - } |
| - |
| var needs_wrapper = false; |
| if (IS_NULL(thisArg)) { |
| if (%IsSloppyModeFunction(predicate)) thisArg = UNDEFINED; |
| @@ -108,24 +100,24 @@ function ArrayFind(predicate /* thisArg */) { // length == 1 |
| return; |
| } |
| +$innerArrayFind = InnerArrayFind; |
| - |
| -// ES6 draft 07-15-13, section 15.4.3.24 |
| -function ArrayFindIndex(predicate /* thisArg */) { // length == 1 |
| - CHECK_OBJECT_COERCIBLE(this, "Array.prototype.findIndex"); |
| +// ES6 draft 07-15-13, section 15.4.3.23 |
| +function ArrayFind(predicate, thisArg) { |
| + CHECK_OBJECT_COERCIBLE(this, "Array.prototype.find"); |
| var array = $toObject(this); |
| var length = $toInteger(array.length); |
| + return InnerArrayFind(predicate, thisArg, array, length); |
| +} |
| +%FunctionSetLength(ArrayFind, 1); |
| + |
| +function InnerArrayFindIndex(predicate, thisArg, array, length) { |
| if (!IS_SPEC_FUNCTION(predicate)) { |
| throw MakeTypeError(kCalledNonCallable, predicate); |
| } |
| - var thisArg; |
| - if (%_ArgumentsLength() > 1) { |
| - thisArg = %_Arguments(1); |
| - } |
| - |
| var needs_wrapper = false; |
| if (IS_NULL(thisArg)) { |
| if (%IsSloppyModeFunction(predicate)) thisArg = UNDEFINED; |
| @@ -145,26 +137,23 @@ function ArrayFindIndex(predicate /* thisArg */) { // length == 1 |
| return -1; |
| } |
| +$innerArrayFindIndex = InnerArrayFindIndex; |
| - |
| -// ES6, draft 04-05-14, section 22.1.3.6 |
| -function ArrayFill(value /* [, start [, end ] ] */) { // length == 1 |
| - CHECK_OBJECT_COERCIBLE(this, "Array.prototype.fill"); |
| +// ES6 draft 07-15-13, section 15.4.3.24 |
| +function ArrayFindIndex(predicate, thisArg) { |
| + CHECK_OBJECT_COERCIBLE(this, "Array.prototype.findIndex"); |
| var array = $toObject(this); |
| - var length = TO_UINT32(array.length); |
| + var length = $toInteger(array.length); |
| - var i = 0; |
| - var end = length; |
| + return InnerArrayFindIndex(predicate, thisArg, array, length); |
| +} |
| +%FunctionSetLength(ArrayFindIndex, 1); |
|
adamk
2015/05/12 23:18:43
Please move this down to the other FunctionSetLeng
|
| - if (%_ArgumentsLength() > 1) { |
| - i = %_Arguments(1); |
| - i = IS_UNDEFINED(i) ? 0 : TO_INTEGER(i); |
| - if (%_ArgumentsLength() > 2) { |
| - end = %_Arguments(2); |
| - end = IS_UNDEFINED(end) ? length : TO_INTEGER(end); |
| - } |
| - } |
| +// ES6, draft 04-05-14, section 22.1.3.6 |
| +function InnerArrayFill(value, start, end, array, length) { |
| + var i = IS_UNDEFINED(start) ? 0 : TO_INTEGER(start); |
| + var end = IS_UNDEFINED(end) ? length : TO_INTEGER(end); |
| if (i < 0) { |
| i += length; |
| @@ -188,6 +177,18 @@ function ArrayFill(value /* [, start [, end ] ] */) { // length == 1 |
| array[i] = value; |
| return array; |
| } |
| +$innerArrayFill = InnerArrayFill; |
| + |
| +// ES6, draft 04-05-14, section 22.1.3.6 |
| +function ArrayFill(value, start, end) { |
| + CHECK_OBJECT_COERCIBLE(this, "Array.prototype.fill"); |
| + |
| + var array = $toObject(this); |
| + var length = TO_UINT32(array.length); |
| + |
| + return InnerArrayFill(value, start, end, array, length); |
| +} |
| +%FunctionSetLength(ArrayFill, 1); |
|
adamk
2015/05/12 23:18:43
Same here.
|
| // ES6, draft 10-14-14, section 22.1.2.1 |
| function ArrayFrom(arrayLike, mapfn, receiver) { |