OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 (function(global, utils, extrasUtils) { | 5 (function(global, utils, extrasUtils) { |
6 | 6 |
7 "use strict"; | 7 "use strict"; |
8 | 8 |
9 %CheckIsBootstrapping(); | 9 %CheckIsBootstrapping(); |
10 | 10 |
(...skipping 1362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1373 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.findIndex"); | 1373 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.findIndex"); |
1374 | 1374 |
1375 var array = TO_OBJECT(this); | 1375 var array = TO_OBJECT(this); |
1376 var length = TO_INTEGER(array.length); | 1376 var length = TO_INTEGER(array.length); |
1377 | 1377 |
1378 return InnerArrayFindIndex(predicate, thisArg, array, length); | 1378 return InnerArrayFindIndex(predicate, thisArg, array, length); |
1379 } | 1379 } |
1380 | 1380 |
1381 | 1381 |
1382 // ES6, draft 04-05-14, section 22.1.3.6 | 1382 // ES6, draft 04-05-14, section 22.1.3.6 |
1383 function InnerArrayFill(value, start, end, array, length) { | 1383 function ArrayFill(value, start, end) { |
| 1384 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.fill"); |
| 1385 |
| 1386 var array = TO_OBJECT(this); |
| 1387 var length = TO_LENGTH(array.length); |
| 1388 |
1384 var i = IS_UNDEFINED(start) ? 0 : TO_INTEGER(start); | 1389 var i = IS_UNDEFINED(start) ? 0 : TO_INTEGER(start); |
1385 var end = IS_UNDEFINED(end) ? length : TO_INTEGER(end); | 1390 var end = IS_UNDEFINED(end) ? length : TO_INTEGER(end); |
1386 | 1391 |
1387 if (i < 0) { | 1392 if (i < 0) { |
1388 i += length; | 1393 i += length; |
1389 if (i < 0) i = 0; | 1394 if (i < 0) i = 0; |
1390 } else { | 1395 } else { |
1391 if (i > length) i = length; | 1396 if (i > length) i = length; |
1392 } | 1397 } |
1393 | 1398 |
1394 if (end < 0) { | 1399 if (end < 0) { |
1395 end += length; | 1400 end += length; |
1396 if (end < 0) end = 0; | 1401 if (end < 0) end = 0; |
1397 } else { | 1402 } else { |
1398 if (end > length) end = length; | 1403 if (end > length) end = length; |
1399 } | 1404 } |
1400 | 1405 |
1401 if ((end - i) > 0 && %object_is_frozen(array)) { | 1406 if ((end - i) > 0 && %object_is_frozen(array)) { |
1402 throw %make_type_error(kArrayFunctionsOnFrozen); | 1407 throw %make_type_error(kArrayFunctionsOnFrozen); |
1403 } | 1408 } |
1404 | 1409 |
1405 for (; i < end; i++) | 1410 for (; i < end; i++) |
1406 array[i] = value; | 1411 array[i] = value; |
1407 return array; | 1412 return array; |
1408 } | 1413 } |
1409 | 1414 |
1410 | 1415 |
1411 // ES6, draft 04-05-14, section 22.1.3.6 | |
1412 function ArrayFill(value, start, end) { | |
1413 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.fill"); | |
1414 | |
1415 var array = TO_OBJECT(this); | |
1416 var length = TO_LENGTH(array.length); | |
1417 | |
1418 return InnerArrayFill(value, start, end, array, length); | |
1419 } | |
1420 | |
1421 | |
1422 // ES6, draft 10-14-14, section 22.1.2.1 | 1416 // ES6, draft 10-14-14, section 22.1.2.1 |
1423 function ArrayFrom(arrayLike, mapfn, receiver) { | 1417 function ArrayFrom(arrayLike, mapfn, receiver) { |
1424 var items = TO_OBJECT(arrayLike); | 1418 var items = TO_OBJECT(arrayLike); |
1425 var mapping = !IS_UNDEFINED(mapfn); | 1419 var mapping = !IS_UNDEFINED(mapfn); |
1426 | 1420 |
1427 if (mapping) { | 1421 if (mapping) { |
1428 if (!IS_CALLABLE(mapfn)) { | 1422 if (!IS_CALLABLE(mapfn)) { |
1429 throw %make_type_error(kCalledNonCallable, mapfn); | 1423 throw %make_type_error(kCalledNonCallable, mapfn); |
1430 } | 1424 } |
1431 } | 1425 } |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1615 // ------------------------------------------------------------------- | 1609 // ------------------------------------------------------------------- |
1616 // Exports | 1610 // Exports |
1617 | 1611 |
1618 utils.Export(function(to) { | 1612 utils.Export(function(to) { |
1619 to.ArrayFrom = ArrayFrom; | 1613 to.ArrayFrom = ArrayFrom; |
1620 to.ArrayJoin = ArrayJoin; | 1614 to.ArrayJoin = ArrayJoin; |
1621 to.ArrayPush = ArrayPush; | 1615 to.ArrayPush = ArrayPush; |
1622 to.ArrayToString = ArrayToString; | 1616 to.ArrayToString = ArrayToString; |
1623 to.ArrayValues = IteratorFunctions.values, | 1617 to.ArrayValues = IteratorFunctions.values, |
1624 to.InnerArrayEvery = InnerArrayEvery; | 1618 to.InnerArrayEvery = InnerArrayEvery; |
1625 to.InnerArrayFill = InnerArrayFill; | |
1626 to.InnerArrayFilter = InnerArrayFilter; | 1619 to.InnerArrayFilter = InnerArrayFilter; |
1627 to.InnerArrayFind = InnerArrayFind; | 1620 to.InnerArrayFind = InnerArrayFind; |
1628 to.InnerArrayFindIndex = InnerArrayFindIndex; | 1621 to.InnerArrayFindIndex = InnerArrayFindIndex; |
1629 to.InnerArrayForEach = InnerArrayForEach; | 1622 to.InnerArrayForEach = InnerArrayForEach; |
1630 to.InnerArrayJoin = InnerArrayJoin; | 1623 to.InnerArrayJoin = InnerArrayJoin; |
1631 to.InnerArrayLastIndexOf = InnerArrayLastIndexOf; | 1624 to.InnerArrayLastIndexOf = InnerArrayLastIndexOf; |
1632 to.InnerArrayReduce = InnerArrayReduce; | 1625 to.InnerArrayReduce = InnerArrayReduce; |
1633 to.InnerArrayReduceRight = InnerArrayReduceRight; | 1626 to.InnerArrayReduceRight = InnerArrayReduceRight; |
1634 to.InnerArraySome = InnerArraySome; | 1627 to.InnerArraySome = InnerArraySome; |
1635 to.InnerArraySort = InnerArraySort; | 1628 to.InnerArraySort = InnerArraySort; |
1636 to.InnerArrayToLocaleString = InnerArrayToLocaleString; | 1629 to.InnerArrayToLocaleString = InnerArrayToLocaleString; |
1637 to.PackedArrayReverse = PackedArrayReverse; | 1630 to.PackedArrayReverse = PackedArrayReverse; |
1638 }); | 1631 }); |
1639 | 1632 |
1640 %InstallToContext([ | 1633 %InstallToContext([ |
1641 "array_entries_iterator", IteratorFunctions.entries, | 1634 "array_entries_iterator", IteratorFunctions.entries, |
1642 "array_for_each_iterator", IteratorFunctions.forEach, | 1635 "array_for_each_iterator", IteratorFunctions.forEach, |
1643 "array_keys_iterator", IteratorFunctions.keys, | 1636 "array_keys_iterator", IteratorFunctions.keys, |
1644 "array_pop", ArrayPop, | 1637 "array_pop", ArrayPop, |
1645 "array_push", ArrayPush, | 1638 "array_push", ArrayPush, |
1646 "array_shift", ArrayShift, | 1639 "array_shift", ArrayShift, |
1647 "array_splice", ArraySplice, | 1640 "array_splice", ArraySplice, |
1648 "array_slice", ArraySlice, | 1641 "array_slice", ArraySlice, |
1649 "array_unshift", ArrayUnshift, | 1642 "array_unshift", ArrayUnshift, |
1650 "array_values_iterator", IteratorFunctions.values, | 1643 "array_values_iterator", IteratorFunctions.values, |
1651 ]); | 1644 ]); |
1652 | 1645 |
1653 }); | 1646 }); |
OLD | NEW |