Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(157)

Side by Side Diff: src/js/array.js

Issue 2670833008: Expose more %ArrayPrototype% functions to the public API. (Closed)
Patch Set: Rebased patch Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/contexts.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 1509 matching lines...) Expand 10 before | Expand all | Expand 10 after
1520 var f = jsBuiltin; 1520 var f = jsBuiltin;
1521 if (specialFunctions.hasOwnProperty(name)) { 1521 if (specialFunctions.hasOwnProperty(name)) {
1522 f = specialFunctions[name]; 1522 f = specialFunctions[name];
1523 } 1523 }
1524 if (!IS_UNDEFINED(len)) { 1524 if (!IS_UNDEFINED(len)) {
1525 %FunctionSetLength(f, len); 1525 %FunctionSetLength(f, len);
1526 } 1526 }
1527 return f; 1527 return f;
1528 }; 1528 };
1529 1529
1530 var ArrayValues = getFunction("values", null, 0); 1530 // Array prototype functions that return iterators. They are exposed to the
1531 // public API via Template::SetIntrinsicDataProperty().
1532 var IteratorFunctions = {
1533 "entries": getFunction("entries", null, 0),
1534 "forEach": getFunction("forEach", ArrayForEach, 1),
1535 "keys": getFunction("keys", null, 0),
1536 "values": getFunction("values", null, 0)
1537 }
1531 1538
1532 // Set up non-enumerable functions of the Array.prototype object and 1539 // Set up non-enumerable functions of the Array.prototype object and
1533 // set their names. 1540 // set their names.
1534 // Manipulate the length of some of the functions to meet 1541 // Manipulate the length of some of the functions to meet
1535 // expectations set by ECMA-262 or Mozilla. 1542 // expectations set by ECMA-262 or Mozilla.
1536 utils.InstallFunctions(GlobalArray.prototype, DONT_ENUM, [ 1543 utils.InstallFunctions(GlobalArray.prototype, DONT_ENUM, [
1537 "toString", getFunction("toString", ArrayToString), 1544 "toString", getFunction("toString", ArrayToString),
1538 "toLocaleString", getFunction("toLocaleString", ArrayToLocaleString), 1545 "toLocaleString", getFunction("toLocaleString", ArrayToLocaleString),
1539 "join", getFunction("join", ArrayJoin), 1546 "join", getFunction("join", ArrayJoin),
1540 "pop", getFunction("pop", ArrayPop), 1547 "pop", getFunction("pop", ArrayPop),
1541 "push", getFunction("push", ArrayPush, 1), 1548 "push", getFunction("push", ArrayPush, 1),
1542 "reverse", getFunction("reverse", ArrayReverse), 1549 "reverse", getFunction("reverse", ArrayReverse),
1543 "shift", getFunction("shift", ArrayShift), 1550 "shift", getFunction("shift", ArrayShift),
1544 "unshift", getFunction("unshift", ArrayUnshift, 1), 1551 "unshift", getFunction("unshift", ArrayUnshift, 1),
1545 "slice", getFunction("slice", ArraySlice, 2), 1552 "slice", getFunction("slice", ArraySlice, 2),
1546 "splice", getFunction("splice", ArraySplice, 2), 1553 "splice", getFunction("splice", ArraySplice, 2),
1547 "sort", getFunction("sort", ArraySort), 1554 "sort", getFunction("sort", ArraySort),
1548 "filter", getFunction("filter", ArrayFilter, 1), 1555 "filter", getFunction("filter", ArrayFilter, 1),
1549 "forEach", getFunction("forEach", ArrayForEach, 1),
1550 "some", getFunction("some", ArraySome, 1), 1556 "some", getFunction("some", ArraySome, 1),
1551 "every", getFunction("every", ArrayEvery, 1), 1557 "every", getFunction("every", ArrayEvery, 1),
1552 "map", getFunction("map", ArrayMap, 1), 1558 "map", getFunction("map", ArrayMap, 1),
1553 "indexOf", getFunction("indexOf", null, 1), 1559 "indexOf", getFunction("indexOf", null, 1),
1554 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), 1560 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1),
1555 "reduce", getFunction("reduce", ArrayReduce, 1), 1561 "reduce", getFunction("reduce", ArrayReduce, 1),
1556 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1), 1562 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1),
1557 "copyWithin", getFunction("copyWithin", ArrayCopyWithin, 2), 1563 "copyWithin", getFunction("copyWithin", ArrayCopyWithin, 2),
1558 "find", getFunction("find", ArrayFind, 1), 1564 "find", getFunction("find", ArrayFind, 1),
1559 "findIndex", getFunction("findIndex", ArrayFindIndex, 1), 1565 "findIndex", getFunction("findIndex", ArrayFindIndex, 1),
1560 "fill", getFunction("fill", ArrayFill, 1), 1566 "fill", getFunction("fill", ArrayFill, 1),
1561 "includes", getFunction("includes", null, 1), 1567 "includes", getFunction("includes", null, 1),
1562 "keys", getFunction("keys", null, 0), 1568 "entries", IteratorFunctions.entries,
1563 "entries", getFunction("entries", null, 0), 1569 "forEach", IteratorFunctions.forEach,
1564 iteratorSymbol, ArrayValues 1570 "keys", IteratorFunctions.keys,
1571 iteratorSymbol, IteratorFunctions.values
1565 ]); 1572 ]);
1566 1573
1567 utils.ForEachFunction = GlobalArray.prototype.forEach; 1574 utils.ForEachFunction = GlobalArray.prototype.forEach;
1568 1575
1569 %FunctionSetName(ArrayValues, "values"); 1576 %FunctionSetName(IteratorFunctions.entries, "entries");
1577 %FunctionSetName(IteratorFunctions.forEach, "forEach");
1578 %FunctionSetName(IteratorFunctions.keys, "keys");
1579 %FunctionSetName(IteratorFunctions.values, "values");
1570 1580
1571 %FinishArrayPrototypeSetup(GlobalArray.prototype); 1581 %FinishArrayPrototypeSetup(GlobalArray.prototype);
1572 1582
1573 // The internal Array prototype doesn't need to be fancy, since it's never 1583 // The internal Array prototype doesn't need to be fancy, since it's never
1574 // exposed to user code. 1584 // exposed to user code.
1575 // Adding only the functions that are actually used. 1585 // Adding only the functions that are actually used.
1576 utils.SetUpLockedPrototype(InternalArray, GlobalArray(), [ 1586 utils.SetUpLockedPrototype(InternalArray, GlobalArray(), [
1577 "indexOf", getFunction("indexOf", null), 1587 "indexOf", getFunction("indexOf", null),
1578 "join", getFunction("join", ArrayJoin), 1588 "join", getFunction("join", ArrayJoin),
1579 "pop", getFunction("pop", ArrayPop), 1589 "pop", getFunction("pop", ArrayPop),
(...skipping 22 matching lines...) Expand all
1602 ]); 1612 ]);
1603 1613
1604 // ------------------------------------------------------------------- 1614 // -------------------------------------------------------------------
1605 // Exports 1615 // Exports
1606 1616
1607 utils.Export(function(to) { 1617 utils.Export(function(to) {
1608 to.ArrayFrom = ArrayFrom; 1618 to.ArrayFrom = ArrayFrom;
1609 to.ArrayJoin = ArrayJoin; 1619 to.ArrayJoin = ArrayJoin;
1610 to.ArrayPush = ArrayPush; 1620 to.ArrayPush = ArrayPush;
1611 to.ArrayToString = ArrayToString; 1621 to.ArrayToString = ArrayToString;
1612 to.ArrayValues = ArrayValues; 1622 to.ArrayValues = IteratorFunctions.values,
1613 to.InnerArrayEvery = InnerArrayEvery; 1623 to.InnerArrayEvery = InnerArrayEvery;
1614 to.InnerArrayFill = InnerArrayFill; 1624 to.InnerArrayFill = InnerArrayFill;
1615 to.InnerArrayFilter = InnerArrayFilter; 1625 to.InnerArrayFilter = InnerArrayFilter;
1616 to.InnerArrayFind = InnerArrayFind; 1626 to.InnerArrayFind = InnerArrayFind;
1617 to.InnerArrayFindIndex = InnerArrayFindIndex; 1627 to.InnerArrayFindIndex = InnerArrayFindIndex;
1618 to.InnerArrayForEach = InnerArrayForEach; 1628 to.InnerArrayForEach = InnerArrayForEach;
1619 to.InnerArrayJoin = InnerArrayJoin; 1629 to.InnerArrayJoin = InnerArrayJoin;
1620 to.InnerArrayLastIndexOf = InnerArrayLastIndexOf; 1630 to.InnerArrayLastIndexOf = InnerArrayLastIndexOf;
1621 to.InnerArrayReduce = InnerArrayReduce; 1631 to.InnerArrayReduce = InnerArrayReduce;
1622 to.InnerArrayReduceRight = InnerArrayReduceRight; 1632 to.InnerArrayReduceRight = InnerArrayReduceRight;
1623 to.InnerArraySome = InnerArraySome; 1633 to.InnerArraySome = InnerArraySome;
1624 to.InnerArraySort = InnerArraySort; 1634 to.InnerArraySort = InnerArraySort;
1625 to.InnerArrayToLocaleString = InnerArrayToLocaleString; 1635 to.InnerArrayToLocaleString = InnerArrayToLocaleString;
1626 to.PackedArrayReverse = PackedArrayReverse; 1636 to.PackedArrayReverse = PackedArrayReverse;
1627 }); 1637 });
1628 1638
1629 %InstallToContext([ 1639 %InstallToContext([
1640 "array_entries_iterator", IteratorFunctions.entries,
1641 "array_for_each_iterator", IteratorFunctions.forEach,
1642 "array_keys_iterator", IteratorFunctions.keys,
1630 "array_pop", ArrayPop, 1643 "array_pop", ArrayPop,
1631 "array_push", ArrayPush, 1644 "array_push", ArrayPush,
1632 "array_shift", ArrayShift, 1645 "array_shift", ArrayShift,
1633 "array_splice", ArraySplice, 1646 "array_splice", ArraySplice,
1634 "array_slice", ArraySlice, 1647 "array_slice", ArraySlice,
1635 "array_unshift", ArrayUnshift, 1648 "array_unshift", ArrayUnshift,
1636 "array_values_iterator", ArrayValues, 1649 "array_values_iterator", IteratorFunctions.values,
1637 ]); 1650 ]);
1638 1651
1639 }); 1652 });
OLDNEW
« no previous file with comments | « src/contexts.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698