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 1502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1513 | 1513 |
1514 %FunctionSetLength(ArrayFrom, 1); | 1514 %FunctionSetLength(ArrayFrom, 1); |
1515 | 1515 |
1516 // Set up non-enumerable functions on the Array object. | 1516 // Set up non-enumerable functions on the Array object. |
1517 utils.InstallFunctions(GlobalArray, DONT_ENUM, [ | 1517 utils.InstallFunctions(GlobalArray, DONT_ENUM, [ |
1518 "from", ArrayFrom, | 1518 "from", ArrayFrom, |
1519 "of", ArrayOf | 1519 "of", ArrayOf |
1520 ]); | 1520 ]); |
1521 | 1521 |
1522 var specialFunctions = %SpecialArrayFunctions(); | 1522 var specialFunctions = %SpecialArrayFunctions(); |
1523 var specialExperimentalArrayFunctions = null; | |
1523 | 1524 |
1524 function getFunction(name, jsBuiltin, len) { | 1525 function getFunction(name, jsBuiltin, len) { |
1525 var f = jsBuiltin; | 1526 var f = jsBuiltin; |
1526 if (specialFunctions.hasOwnProperty(name)) { | 1527 if (specialFunctions.hasOwnProperty(name)) { |
1527 f = specialFunctions[name]; | 1528 f = specialFunctions[name]; |
1529 } else if (specialExperimentalArrayFunctions != null && | |
1530 specialExperimentalArrayFunctions.hasOwnProperty(name)) { | |
1531 f = specialExperimentalArrayFunctions[name]; | |
1528 } | 1532 } |
1529 if (!IS_UNDEFINED(len)) { | 1533 if (!IS_UNDEFINED(len)) { |
1530 %FunctionSetLength(f, len); | 1534 %FunctionSetLength(f, len); |
1531 } | 1535 } |
1532 return f; | 1536 return f; |
1533 }; | 1537 }; |
1534 | 1538 |
1535 var ArrayValues = getFunction("values", null, 0); | 1539 var ArrayValues = getFunction("values", null, 0); |
1536 | 1540 |
1537 // Set up non-enumerable functions of the Array.prototype object and | 1541 // Set up non-enumerable functions of the Array.prototype object and |
1538 // set their names. | 1542 // set their names. |
1539 // Manipulate the length of some of the functions to meet | 1543 // Manipulate the length of some of the functions to meet |
1540 // expectations set by ECMA-262 or Mozilla. | 1544 // expectations set by ECMA-262 or Mozilla. |
1541 utils.InstallFunctions(GlobalArray.prototype, DONT_ENUM, [ | 1545 utils.InstallFunctions(GlobalArray.prototype, DONT_ENUM, [ |
1542 "toString", getFunction("toString", ArrayToString), | 1546 "toString", getFunction("toString", ArrayToString), |
1543 "toLocaleString", getFunction("toLocaleString", ArrayToLocaleString), | 1547 "toLocaleString", getFunction("toLocaleString", ArrayToLocaleString), |
1544 "join", getFunction("join", ArrayJoin), | 1548 "join", getFunction("join", ArrayJoin), |
1545 "pop", getFunction("pop", ArrayPop), | 1549 "pop", getFunction("pop", ArrayPop), |
1546 "push", getFunction("push", ArrayPush, 1), | 1550 "push", getFunction("push", ArrayPush, 1), |
1547 "reverse", getFunction("reverse", ArrayReverse), | 1551 "reverse", getFunction("reverse", ArrayReverse), |
1548 "shift", getFunction("shift", ArrayShift), | 1552 "shift", getFunction("shift", ArrayShift), |
1549 "unshift", getFunction("unshift", ArrayUnshift, 1), | 1553 "unshift", getFunction("unshift", ArrayUnshift, 1), |
1550 "slice", getFunction("slice", ArraySlice, 2), | 1554 "slice", getFunction("slice", ArraySlice, 2), |
1551 "splice", getFunction("splice", ArraySplice, 2), | 1555 "splice", getFunction("splice", ArraySplice, 2), |
1552 "sort", getFunction("sort", ArraySort), | 1556 "sort", getFunction("sort", ArraySort), |
1553 "filter", getFunction("filter", ArrayFilter, 1), | 1557 "filter", getFunction("filter", ArrayFilter, 1), |
1554 "forEach", getFunction("forEach", ArrayForEach, 1), | |
1555 "some", getFunction("some", ArraySome, 1), | 1558 "some", getFunction("some", ArraySome, 1), |
1556 "every", getFunction("every", ArrayEvery, 1), | 1559 "every", getFunction("every", ArrayEvery, 1), |
1557 "map", getFunction("map", ArrayMap, 1), | 1560 "map", getFunction("map", ArrayMap, 1), |
1558 "indexOf", getFunction("indexOf", null, 1), | 1561 "indexOf", getFunction("indexOf", null, 1), |
1559 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), | 1562 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), |
1560 "reduce", getFunction("reduce", ArrayReduce, 1), | 1563 "reduce", getFunction("reduce", ArrayReduce, 1), |
1561 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1), | 1564 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1), |
1562 "copyWithin", getFunction("copyWithin", ArrayCopyWithin, 2), | 1565 "copyWithin", getFunction("copyWithin", ArrayCopyWithin, 2), |
1563 "find", getFunction("find", ArrayFind, 1), | 1566 "find", getFunction("find", ArrayFind, 1), |
1564 "findIndex", getFunction("findIndex", ArrayFindIndex, 1), | 1567 "findIndex", getFunction("findIndex", ArrayFindIndex, 1), |
1565 "fill", getFunction("fill", ArrayFill, 1), | 1568 "fill", getFunction("fill", ArrayFill, 1), |
1566 "includes", getFunction("includes", null, 1), | 1569 "includes", getFunction("includes", null, 1), |
1567 "keys", getFunction("keys", null, 0), | 1570 "keys", getFunction("keys", null, 0), |
1568 "entries", getFunction("entries", null, 0), | 1571 "entries", getFunction("entries", null, 0), |
1569 iteratorSymbol, ArrayValues | 1572 iteratorSymbol, ArrayValues |
1570 ]); | 1573 ]); |
1571 | 1574 |
1575 %FunctionRemovePrototype(ArrayForEach); | |
1576 | |
1577 var specialExperimentalArrayFunctions = null; | |
1578 | |
1579 function InstallExperimentalArrayFunctions() { | |
1580 specialExperimentalArrayFunctions = %SpecialExperimentalArrayFunctions(); | |
Yang
2017/02/02 10:04:58
Can we have all of this in C++, in the bootstrappe
danno
2017/02/02 17:15:48
Done.
| |
1581 utils.InstallFunctions(global.Array.prototype, DONT_ENUM, [ | |
1582 "forEach", getFunction("forEach", ArrayForEach, 1), | |
1583 ], false); | |
1584 } | |
1585 | |
1572 %FunctionSetName(ArrayValues, "values"); | 1586 %FunctionSetName(ArrayValues, "values"); |
1573 | 1587 |
1574 %FinishArrayPrototypeSetup(GlobalArray.prototype); | 1588 %FinishArrayPrototypeSetup(GlobalArray.prototype); |
1575 | 1589 |
1576 // The internal Array prototype doesn't need to be fancy, since it's never | 1590 // The internal Array prototype doesn't need to be fancy, since it's never |
1577 // exposed to user code. | 1591 // exposed to user code. |
1578 // Adding only the functions that are actually used. | 1592 // Adding only the functions that are actually used. |
1579 utils.SetUpLockedPrototype(InternalArray, GlobalArray(), [ | 1593 utils.SetUpLockedPrototype(InternalArray, GlobalArray(), [ |
1580 "indexOf", getFunction("indexOf", null), | 1594 "indexOf", getFunction("indexOf", null), |
1581 "join", getFunction("join", ArrayJoin), | 1595 "join", getFunction("join", ArrayJoin), |
(...skipping 22 matching lines...) Expand all Loading... | |
1604 "slice", getFunction("slice", ArraySlice) | 1618 "slice", getFunction("slice", ArraySlice) |
1605 ]); | 1619 ]); |
1606 | 1620 |
1607 // ------------------------------------------------------------------- | 1621 // ------------------------------------------------------------------- |
1608 // Exports | 1622 // Exports |
1609 | 1623 |
1610 utils.Export(function(to) { | 1624 utils.Export(function(to) { |
1611 to.ArrayFrom = ArrayFrom; | 1625 to.ArrayFrom = ArrayFrom; |
1612 to.ArrayJoin = ArrayJoin; | 1626 to.ArrayJoin = ArrayJoin; |
1613 to.ArrayPush = ArrayPush; | 1627 to.ArrayPush = ArrayPush; |
1628 to.InstallExperimentalArrayFunctions = InstallExperimentalArrayFunctions; | |
1614 to.ArrayToString = ArrayToString; | 1629 to.ArrayToString = ArrayToString; |
1615 to.ArrayValues = ArrayValues; | 1630 to.ArrayValues = ArrayValues; |
1616 to.InnerArrayCopyWithin = InnerArrayCopyWithin; | 1631 to.InnerArrayCopyWithin = InnerArrayCopyWithin; |
1617 to.InnerArrayEvery = InnerArrayEvery; | 1632 to.InnerArrayEvery = InnerArrayEvery; |
1618 to.InnerArrayFill = InnerArrayFill; | 1633 to.InnerArrayFill = InnerArrayFill; |
1619 to.InnerArrayFilter = InnerArrayFilter; | 1634 to.InnerArrayFilter = InnerArrayFilter; |
1620 to.InnerArrayFind = InnerArrayFind; | 1635 to.InnerArrayFind = InnerArrayFind; |
1621 to.InnerArrayFindIndex = InnerArrayFindIndex; | 1636 to.InnerArrayFindIndex = InnerArrayFindIndex; |
1622 to.InnerArrayForEach = InnerArrayForEach; | 1637 to.InnerArrayForEach = InnerArrayForEach; |
1623 to.InnerArrayJoin = InnerArrayJoin; | 1638 to.InnerArrayJoin = InnerArrayJoin; |
(...skipping 10 matching lines...) Expand all Loading... | |
1634 "array_pop", ArrayPop, | 1649 "array_pop", ArrayPop, |
1635 "array_push", ArrayPush, | 1650 "array_push", ArrayPush, |
1636 "array_shift", ArrayShift, | 1651 "array_shift", ArrayShift, |
1637 "array_splice", ArraySplice, | 1652 "array_splice", ArraySplice, |
1638 "array_slice", ArraySlice, | 1653 "array_slice", ArraySlice, |
1639 "array_unshift", ArrayUnshift, | 1654 "array_unshift", ArrayUnshift, |
1640 "array_values_iterator", ArrayValues, | 1655 "array_values_iterator", ArrayValues, |
1641 ]); | 1656 ]); |
1642 | 1657 |
1643 }); | 1658 }); |
OLD | NEW |