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

Side by Side Diff: src/array.js

Issue 1154743003: Revert of Hook up more import/exports in natives. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 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 | « no previous file | src/array-iterator.js » ('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 var $arrayConcat; 5 var $arrayConcat;
6 var $arrayJoin;
6 var $arrayPush; 7 var $arrayPush;
7 var $arrayPop; 8 var $arrayPop;
8 var $arrayShift; 9 var $arrayShift;
9 var $arraySlice; 10 var $arraySlice;
10 var $arraySplice; 11 var $arraySplice;
11 var $arrayUnshift; 12 var $arrayUnshift;
13 var $innerArrayForEach;
14 var $innerArrayEvery;
15 var $innerArrayFilter;
16 var $innerArrayIndexOf;
17 var $innerArrayLastIndexOf;
18 var $innerArrayMap;
19 var $innerArrayReverse;
20 var $innerArraySome;
21 var $innerArraySort;
12 22
13 (function(global, utils) { 23 (function(global, utils) {
14 24
15 "use strict"; 25 "use strict";
16 26
17 %CheckIsBootstrapping(); 27 %CheckIsBootstrapping();
18 28
19 // ------------------------------------------------------------------- 29 // -------------------------------------------------------------------
20 // Imports 30 // Imports
21 31
22 var GlobalArray = global.Array; 32 var GlobalArray = global.Array;
23 var InternalArray = utils.InternalArray; 33 var InternalArray = utils.InternalArray;
24 var InternalPackedArray = utils.InternalPackedArray; 34 var InternalPackedArray = utils.InternalPackedArray;
25 35
26 var Delete;
27 var MathMin; 36 var MathMin;
28 var ObjectHasOwnProperty;
29 var ObjectIsFrozen;
30 var ObjectIsSealed;
31 var ObjectToString;
32 37
33 utils.Import(function(from) { 38 utils.Import(function(from) {
34 Delete = from.Delete;
35 MathMin = from.MathMin; 39 MathMin = from.MathMin;
36 ObjectHasOwnProperty = from.ObjectHasOwnProperty;
37 ObjectIsFrozen = from.ObjectIsFrozen;
38 ObjectIsSealed = from.ObjectIsSealed;
39 ObjectToString = from.ObjectToString;
40 }); 40 });
41 41
42 // ------------------------------------------------------------------- 42 // -------------------------------------------------------------------
43 43
44 // Global list of arrays visited during toString, toLocaleString and 44 // Global list of arrays visited during toString, toLocaleString and
45 // join invocations. 45 // join invocations.
46 var visited_arrays = new InternalArray(); 46 var visited_arrays = new InternalArray();
47 47
48 48
49 // Gets a sorted array of array keys. Useful for operations on sparse 49 // Gets a sorted array of array keys. Useful for operations on sparse
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 func = this.join; 385 func = this.join;
386 if (func === ArrayJoin) { 386 if (func === ArrayJoin) {
387 return Join(this, this.length, ',', ConvertToString); 387 return Join(this, this.length, ',', ConvertToString);
388 } 388 }
389 array = this; 389 array = this;
390 } else { 390 } else {
391 array = $toObject(this); 391 array = $toObject(this);
392 func = array.join; 392 func = array.join;
393 } 393 }
394 if (!IS_SPEC_FUNCTION(func)) { 394 if (!IS_SPEC_FUNCTION(func)) {
395 return %_CallFunction(array, ObjectToString); 395 return %_CallFunction(array, $objectToString);
396 } 396 }
397 return %_CallFunction(array, func); 397 return %_CallFunction(array, func);
398 } 398 }
399 399
400 400
401 function ArrayToLocaleString() { 401 function ArrayToLocaleString() {
402 var array = $toObject(this); 402 var array = $toObject(this);
403 var arrayLen = array.length; 403 var arrayLen = array.length;
404 var len = TO_UINT32(arrayLen); 404 var len = TO_UINT32(arrayLen);
405 if (len === 0) return ""; 405 if (len === 0) return "";
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 if (n == 0) { 460 if (n == 0) {
461 array.length = n; 461 array.length = n;
462 return; 462 return;
463 } 463 }
464 464
465 if (%IsObserved(array)) 465 if (%IsObserved(array))
466 return ObservedArrayPop.call(array, n); 466 return ObservedArrayPop.call(array, n);
467 467
468 n--; 468 n--;
469 var value = array[n]; 469 var value = array[n];
470 Delete(array, $toName(n), true); 470 $delete(array, $toName(n), true);
471 array.length = n; 471 array.length = n;
472 return value; 472 return value;
473 } 473 }
474 474
475 475
476 function ObservedArrayPush() { 476 function ObservedArrayPush() {
477 var n = TO_UINT32(this.length); 477 var n = TO_UINT32(this.length);
478 var m = %_ArgumentsLength(); 478 var m = %_ArgumentsLength();
479 479
480 try { 480 try {
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.shift"); 638 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.shift");
639 639
640 var array = TO_OBJECT_INLINE(this); 640 var array = TO_OBJECT_INLINE(this);
641 var len = TO_UINT32(array.length); 641 var len = TO_UINT32(array.length);
642 642
643 if (len === 0) { 643 if (len === 0) {
644 array.length = 0; 644 array.length = 0;
645 return; 645 return;
646 } 646 }
647 647
648 if (ObjectIsSealed(array)) throw MakeTypeError(kArrayFunctionsOnSealed); 648 if ($objectIsSealed(array)) throw MakeTypeError(kArrayFunctionsOnSealed);
649 649
650 if (%IsObserved(array)) 650 if (%IsObserved(array))
651 return ObservedArrayShift.call(array, len); 651 return ObservedArrayShift.call(array, len);
652 652
653 var first = array[0]; 653 var first = array[0];
654 654
655 if (UseSparseVariant(array, len, IS_ARRAY(array), len)) { 655 if (UseSparseVariant(array, len, IS_ARRAY(array), len)) {
656 SparseMove(array, 0, 1, len, 0); 656 SparseMove(array, 0, 1, len, 0);
657 } else { 657 } else {
658 SimpleMove(array, 0, 1, len, 0); 658 SimpleMove(array, 0, 1, len, 0);
(...skipping 30 matching lines...) Expand all
689 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.unshift"); 689 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.unshift");
690 690
691 if (%IsObserved(this)) 691 if (%IsObserved(this))
692 return ObservedArrayUnshift.apply(this, arguments); 692 return ObservedArrayUnshift.apply(this, arguments);
693 693
694 var array = TO_OBJECT_INLINE(this); 694 var array = TO_OBJECT_INLINE(this);
695 var len = TO_UINT32(array.length); 695 var len = TO_UINT32(array.length);
696 var num_arguments = %_ArgumentsLength(); 696 var num_arguments = %_ArgumentsLength();
697 697
698 if (len > 0 && UseSparseVariant(array, len, IS_ARRAY(array), len) && 698 if (len > 0 && UseSparseVariant(array, len, IS_ARRAY(array), len) &&
699 !ObjectIsSealed(array)) { 699 !$objectIsSealed(array)) {
700 SparseMove(array, 0, 0, len, num_arguments); 700 SparseMove(array, 0, 0, len, num_arguments);
701 } else { 701 } else {
702 SimpleMove(array, 0, 0, len, num_arguments); 702 SimpleMove(array, 0, 0, len, num_arguments);
703 } 703 }
704 704
705 for (var i = 0; i < num_arguments; i++) { 705 for (var i = 0; i < num_arguments; i++) {
706 array[i] = %_Arguments(i); 706 array[i] = %_Arguments(i);
707 } 707 }
708 708
709 var new_length = len + num_arguments; 709 var new_length = len + num_arguments;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
835 var num_arguments = %_ArgumentsLength(); 835 var num_arguments = %_ArgumentsLength();
836 var array = TO_OBJECT_INLINE(this); 836 var array = TO_OBJECT_INLINE(this);
837 var len = TO_UINT32(array.length); 837 var len = TO_UINT32(array.length);
838 var start_i = ComputeSpliceStartIndex(TO_INTEGER(start), len); 838 var start_i = ComputeSpliceStartIndex(TO_INTEGER(start), len);
839 var del_count = ComputeSpliceDeleteCount(delete_count, num_arguments, len, 839 var del_count = ComputeSpliceDeleteCount(delete_count, num_arguments, len,
840 start_i); 840 start_i);
841 var deleted_elements = []; 841 var deleted_elements = [];
842 deleted_elements.length = del_count; 842 deleted_elements.length = del_count;
843 var num_elements_to_add = num_arguments > 2 ? num_arguments - 2 : 0; 843 var num_elements_to_add = num_arguments > 2 ? num_arguments - 2 : 0;
844 844
845 if (del_count != num_elements_to_add && ObjectIsSealed(array)) { 845 if (del_count != num_elements_to_add && $objectIsSealed(array)) {
846 throw MakeTypeError(kArrayFunctionsOnSealed); 846 throw MakeTypeError(kArrayFunctionsOnSealed);
847 } else if (del_count > 0 && ObjectIsFrozen(array)) { 847 } else if (del_count > 0 && $objectIsFrozen(array)) {
848 throw MakeTypeError(kArrayFunctionsOnFrozen); 848 throw MakeTypeError(kArrayFunctionsOnFrozen);
849 } 849 }
850 850
851 var changed_elements = del_count; 851 var changed_elements = del_count;
852 if (num_elements_to_add != del_count) { 852 if (num_elements_to_add != del_count) {
853 // If the slice needs to do a actually move elements after the insertion 853 // If the slice needs to do a actually move elements after the insertion
854 // point, then include those in the estimate of changed elements. 854 // point, then include those in the estimate of changed elements.
855 changed_elements += len - start_i - del_count; 855 changed_elements += len - start_i - del_count;
856 } 856 }
857 if (UseSparseVariant(array, len, IS_ARRAY(array), changed_elements)) { 857 if (UseSparseVariant(array, len, IS_ARRAY(array), changed_elements)) {
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after
1575 fill: true, 1575 fill: true,
1576 find: true, 1576 find: true,
1577 findIndex: true, 1577 findIndex: true,
1578 keys: true, 1578 keys: true,
1579 }; 1579 };
1580 1580
1581 %AddNamedProperty(GlobalArray.prototype, symbolUnscopables, unscopables, 1581 %AddNamedProperty(GlobalArray.prototype, symbolUnscopables, unscopables,
1582 DONT_ENUM | READ_ONLY); 1582 DONT_ENUM | READ_ONLY);
1583 1583
1584 // Set up non-enumerable functions on the Array object. 1584 // Set up non-enumerable functions on the Array object.
1585 utils.InstallFunctions(GlobalArray, DONT_ENUM, [ 1585 $installFunctions(GlobalArray, DONT_ENUM, [
1586 "isArray", ArrayIsArray 1586 "isArray", ArrayIsArray
1587 ]); 1587 ]);
1588 1588
1589 var specialFunctions = %SpecialArrayFunctions(); 1589 var specialFunctions = %SpecialArrayFunctions();
1590 1590
1591 var getFunction = function(name, jsBuiltin, len) { 1591 var getFunction = function(name, jsBuiltin, len) {
1592 var f = jsBuiltin; 1592 var f = jsBuiltin;
1593 if (specialFunctions.hasOwnProperty(name)) { 1593 if (specialFunctions.hasOwnProperty(name)) {
1594 f = specialFunctions[name]; 1594 f = specialFunctions[name];
1595 } 1595 }
1596 if (!IS_UNDEFINED(len)) { 1596 if (!IS_UNDEFINED(len)) {
1597 %FunctionSetLength(f, len); 1597 %FunctionSetLength(f, len);
1598 } 1598 }
1599 return f; 1599 return f;
1600 }; 1600 };
1601 1601
1602 // Set up non-enumerable functions of the Array.prototype object and 1602 // Set up non-enumerable functions of the Array.prototype object and
1603 // set their names. 1603 // set their names.
1604 // Manipulate the length of some of the functions to meet 1604 // Manipulate the length of some of the functions to meet
1605 // expectations set by ECMA-262 or Mozilla. 1605 // expectations set by ECMA-262 or Mozilla.
1606 utils.InstallFunctions(GlobalArray.prototype, DONT_ENUM, [ 1606 $installFunctions(GlobalArray.prototype, DONT_ENUM, [
1607 "toString", getFunction("toString", ArrayToString), 1607 "toString", getFunction("toString", ArrayToString),
1608 "toLocaleString", getFunction("toLocaleString", ArrayToLocaleString), 1608 "toLocaleString", getFunction("toLocaleString", ArrayToLocaleString),
1609 "join", getFunction("join", ArrayJoin), 1609 "join", getFunction("join", ArrayJoin),
1610 "pop", getFunction("pop", ArrayPop), 1610 "pop", getFunction("pop", ArrayPop),
1611 "push", getFunction("push", ArrayPush, 1), 1611 "push", getFunction("push", ArrayPush, 1),
1612 "concat", getFunction("concat", ArrayConcatJS, 1), 1612 "concat", getFunction("concat", ArrayConcatJS, 1),
1613 "reverse", getFunction("reverse", ArrayReverse), 1613 "reverse", getFunction("reverse", ArrayReverse),
1614 "shift", getFunction("shift", ArrayShift), 1614 "shift", getFunction("shift", ArrayShift),
1615 "unshift", getFunction("unshift", ArrayUnshift, 1), 1615 "unshift", getFunction("unshift", ArrayUnshift, 1),
1616 "slice", getFunction("slice", ArraySlice, 2), 1616 "slice", getFunction("slice", ArraySlice, 2),
1617 "splice", getFunction("splice", ArraySplice, 2), 1617 "splice", getFunction("splice", ArraySplice, 2),
1618 "sort", getFunction("sort", ArraySort), 1618 "sort", getFunction("sort", ArraySort),
1619 "filter", getFunction("filter", ArrayFilter, 1), 1619 "filter", getFunction("filter", ArrayFilter, 1),
1620 "forEach", getFunction("forEach", ArrayForEach, 1), 1620 "forEach", getFunction("forEach", ArrayForEach, 1),
1621 "some", getFunction("some", ArraySome, 1), 1621 "some", getFunction("some", ArraySome, 1),
1622 "every", getFunction("every", ArrayEvery, 1), 1622 "every", getFunction("every", ArrayEvery, 1),
1623 "map", getFunction("map", ArrayMap, 1), 1623 "map", getFunction("map", ArrayMap, 1),
1624 "indexOf", getFunction("indexOf", ArrayIndexOf, 1), 1624 "indexOf", getFunction("indexOf", ArrayIndexOf, 1),
1625 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), 1625 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1),
1626 "reduce", getFunction("reduce", ArrayReduce, 1), 1626 "reduce", getFunction("reduce", ArrayReduce, 1),
1627 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) 1627 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1)
1628 ]); 1628 ]);
1629 1629
1630 %FinishArrayPrototypeSetup(GlobalArray.prototype); 1630 %FinishArrayPrototypeSetup(GlobalArray.prototype);
1631 1631
1632 // The internal Array prototype doesn't need to be fancy, since it's never 1632 // The internal Array prototype doesn't need to be fancy, since it's never
1633 // exposed to user code. 1633 // exposed to user code.
1634 // Adding only the functions that are actually used. 1634 // Adding only the functions that are actually used.
1635 utils.SetUpLockedPrototype(InternalArray, GlobalArray(), [ 1635 $setUpLockedPrototype(InternalArray, GlobalArray(), [
1636 "concat", getFunction("concat", ArrayConcatJS), 1636 "concat", getFunction("concat", ArrayConcatJS),
1637 "indexOf", getFunction("indexOf", ArrayIndexOf), 1637 "indexOf", getFunction("indexOf", ArrayIndexOf),
1638 "join", getFunction("join", ArrayJoin), 1638 "join", getFunction("join", ArrayJoin),
1639 "pop", getFunction("pop", ArrayPop), 1639 "pop", getFunction("pop", ArrayPop),
1640 "push", getFunction("push", ArrayPush), 1640 "push", getFunction("push", ArrayPush),
1641 "shift", getFunction("shift", ArrayShift), 1641 "shift", getFunction("shift", ArrayShift),
1642 "splice", getFunction("splice", ArraySplice) 1642 "splice", getFunction("splice", ArraySplice)
1643 ]); 1643 ]);
1644 1644
1645 utils.SetUpLockedPrototype(InternalPackedArray, GlobalArray(), [ 1645 $setUpLockedPrototype(InternalPackedArray, GlobalArray(), [
1646 "join", getFunction("join", ArrayJoin), 1646 "join", getFunction("join", ArrayJoin),
1647 "pop", getFunction("pop", ArrayPop), 1647 "pop", getFunction("pop", ArrayPop),
1648 "push", getFunction("push", ArrayPush), 1648 "push", getFunction("push", ArrayPush),
1649 "shift", getFunction("shift", ArrayShift) 1649 "shift", getFunction("shift", ArrayShift)
1650 ]); 1650 ]);
1651 1651
1652 // -------------------------------------------------------------------
1653 // Exports
1654
1655 utils.Export(function(to) {
1656 to.ArrayJoin = ArrayJoin;
1657 to.InnerArrayEvery = InnerArrayEvery;
1658 to.InnerArrayFilter = InnerArrayFilter;
1659 to.InnerArrayForEach = InnerArrayForEach;
1660 to.InnerArrayIndexOf = InnerArrayIndexOf;
1661 to.InnerArrayLastIndexOf = InnerArrayLastIndexOf;
1662 to.InnerArrayMap = InnerArrayMap;
1663 to.InnerArrayReverse = InnerArrayReverse;
1664 to.InnerArraySome = InnerArraySome;
1665 to.InnerArraySort = InnerArraySort;
1666 });
1667
1668 $arrayConcat = ArrayConcatJS; 1652 $arrayConcat = ArrayConcatJS;
1653 $arrayJoin = ArrayJoin;
1669 $arrayPush = ArrayPush; 1654 $arrayPush = ArrayPush;
1670 $arrayPop = ArrayPop; 1655 $arrayPop = ArrayPop;
1671 $arrayShift = ArrayShift; 1656 $arrayShift = ArrayShift;
1672 $arraySlice = ArraySlice; 1657 $arraySlice = ArraySlice;
1673 $arraySplice = ArraySplice; 1658 $arraySplice = ArraySplice;
1674 $arrayUnshift = ArrayUnshift; 1659 $arrayUnshift = ArrayUnshift;
1675 1660
1661 $innerArrayEvery = InnerArrayEvery;
1662 $innerArrayFilter = InnerArrayFilter;
1663 $innerArrayForEach = InnerArrayForEach;
1664 $innerArrayIndexOf = InnerArrayIndexOf;
1665 $innerArrayLastIndexOf = InnerArrayLastIndexOf;
1666 $innerArrayMap = InnerArrayMap;
1667 $innerArrayReverse = InnerArrayReverse;
1668 $innerArraySome = InnerArraySome;
1669 $innerArraySort = InnerArraySort;
1670
1676 }); 1671 });
OLDNEW
« no previous file with comments | « no previous file | src/array-iterator.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698