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

Side by Side Diff: src/array.js

Issue 1121453003: Revert of Wrap v8natives.js into a function. (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 | « src/api.cc ('k') | 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 $arrayJoin;
7 var $arrayPush; 7 var $arrayPush;
8 var $arrayPop; 8 var $arrayPop;
9 var $arrayShift; 9 var $arrayShift;
10 var $arraySlice; 10 var $arraySlice;
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after
365 func = this.join; 365 func = this.join;
366 if (func === ArrayJoin) { 366 if (func === ArrayJoin) {
367 return Join(this, this.length, ',', ConvertToString); 367 return Join(this, this.length, ',', ConvertToString);
368 } 368 }
369 array = this; 369 array = this;
370 } else { 370 } else {
371 array = ToObject(this); 371 array = ToObject(this);
372 func = array.join; 372 func = array.join;
373 } 373 }
374 if (!IS_SPEC_FUNCTION(func)) { 374 if (!IS_SPEC_FUNCTION(func)) {
375 return %_CallFunction(array, $objectToString); 375 return %_CallFunction(array, ObjectToString);
376 } 376 }
377 return %_CallFunction(array, func); 377 return %_CallFunction(array, func);
378 } 378 }
379 379
380 380
381 function ArrayToLocaleString() { 381 function ArrayToLocaleString() {
382 var array = ToObject(this); 382 var array = ToObject(this);
383 var arrayLen = array.length; 383 var arrayLen = array.length;
384 var len = TO_UINT32(arrayLen); 384 var len = TO_UINT32(arrayLen);
385 if (len === 0) return ""; 385 if (len === 0) return "";
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 if (n == 0) { 440 if (n == 0) {
441 array.length = n; 441 array.length = n;
442 return; 442 return;
443 } 443 }
444 444
445 if (%IsObserved(array)) 445 if (%IsObserved(array))
446 return ObservedArrayPop.call(array, n); 446 return ObservedArrayPop.call(array, n);
447 447
448 n--; 448 n--;
449 var value = array[n]; 449 var value = array[n];
450 $delete(array, ToName(n), true); 450 Delete(array, ToName(n), true);
451 array.length = n; 451 array.length = n;
452 return value; 452 return value;
453 } 453 }
454 454
455 455
456 function ObservedArrayPush() { 456 function ObservedArrayPush() {
457 var n = TO_UINT32(this.length); 457 var n = TO_UINT32(this.length);
458 var m = %_ArgumentsLength(); 458 var m = %_ArgumentsLength();
459 459
460 try { 460 try {
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.shift"); 613 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.shift");
614 614
615 var array = TO_OBJECT_INLINE(this); 615 var array = TO_OBJECT_INLINE(this);
616 var len = TO_UINT32(array.length); 616 var len = TO_UINT32(array.length);
617 617
618 if (len === 0) { 618 if (len === 0) {
619 array.length = 0; 619 array.length = 0;
620 return; 620 return;
621 } 621 }
622 622
623 if ($objectIsSealed(array)) throw MakeTypeError(kArrayFunctionsOnSealed); 623 if (ObjectIsSealed(array)) throw MakeTypeError(kArrayFunctionsOnSealed);
624 624
625 if (%IsObserved(array)) 625 if (%IsObserved(array))
626 return ObservedArrayShift.call(array, len); 626 return ObservedArrayShift.call(array, len);
627 627
628 var first = array[0]; 628 var first = array[0];
629 629
630 if (UseSparseVariant(array, len, IS_ARRAY(array), len)) { 630 if (UseSparseVariant(array, len, IS_ARRAY(array), len)) {
631 SparseMove(array, 0, 1, len, 0); 631 SparseMove(array, 0, 1, len, 0);
632 } else { 632 } else {
633 SimpleMove(array, 0, 1, len, 0); 633 SimpleMove(array, 0, 1, len, 0);
(...skipping 30 matching lines...) Expand all
664 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.unshift"); 664 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.unshift");
665 665
666 if (%IsObserved(this)) 666 if (%IsObserved(this))
667 return ObservedArrayUnshift.apply(this, arguments); 667 return ObservedArrayUnshift.apply(this, arguments);
668 668
669 var array = TO_OBJECT_INLINE(this); 669 var array = TO_OBJECT_INLINE(this);
670 var len = TO_UINT32(array.length); 670 var len = TO_UINT32(array.length);
671 var num_arguments = %_ArgumentsLength(); 671 var num_arguments = %_ArgumentsLength();
672 672
673 if (len > 0 && UseSparseVariant(array, len, IS_ARRAY(array), len) && 673 if (len > 0 && UseSparseVariant(array, len, IS_ARRAY(array), len) &&
674 !$objectIsSealed(array)) { 674 !ObjectIsSealed(array)) {
675 SparseMove(array, 0, 0, len, num_arguments); 675 SparseMove(array, 0, 0, len, num_arguments);
676 } else { 676 } else {
677 SimpleMove(array, 0, 0, len, num_arguments); 677 SimpleMove(array, 0, 0, len, num_arguments);
678 } 678 }
679 679
680 for (var i = 0; i < num_arguments; i++) { 680 for (var i = 0; i < num_arguments; i++) {
681 array[i] = %_Arguments(i); 681 array[i] = %_Arguments(i);
682 } 682 }
683 683
684 var new_length = len + num_arguments; 684 var new_length = len + num_arguments;
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 var num_arguments = %_ArgumentsLength(); 810 var num_arguments = %_ArgumentsLength();
811 var array = TO_OBJECT_INLINE(this); 811 var array = TO_OBJECT_INLINE(this);
812 var len = TO_UINT32(array.length); 812 var len = TO_UINT32(array.length);
813 var start_i = ComputeSpliceStartIndex(TO_INTEGER(start), len); 813 var start_i = ComputeSpliceStartIndex(TO_INTEGER(start), len);
814 var del_count = ComputeSpliceDeleteCount(delete_count, num_arguments, len, 814 var del_count = ComputeSpliceDeleteCount(delete_count, num_arguments, len,
815 start_i); 815 start_i);
816 var deleted_elements = []; 816 var deleted_elements = [];
817 deleted_elements.length = del_count; 817 deleted_elements.length = del_count;
818 var num_elements_to_add = num_arguments > 2 ? num_arguments - 2 : 0; 818 var num_elements_to_add = num_arguments > 2 ? num_arguments - 2 : 0;
819 819
820 if (del_count != num_elements_to_add && $objectIsSealed(array)) { 820 if (del_count != num_elements_to_add && ObjectIsSealed(array)) {
821 throw MakeTypeError(kArrayFunctionsOnSealed); 821 throw MakeTypeError(kArrayFunctionsOnSealed);
822 } else if (del_count > 0 && $objectIsFrozen(array)) { 822 } else if (del_count > 0 && ObjectIsFrozen(array)) {
823 throw MakeTypeError(kArrayFunctionsOnFrozen); 823 throw MakeTypeError(kArrayFunctionsOnFrozen);
824 } 824 }
825 825
826 var changed_elements = del_count; 826 var changed_elements = del_count;
827 if (num_elements_to_add != del_count) { 827 if (num_elements_to_add != del_count) {
828 // If the slice needs to do a actually move elements after the insertion 828 // If the slice needs to do a actually move elements after the insertion
829 // point, then include those in the estimate of changed elements. 829 // point, then include those in the estimate of changed elements.
830 changed_elements += len - start_i - del_count; 830 changed_elements += len - start_i - del_count;
831 } 831 }
832 if (UseSparseVariant(array, len, IS_ARRAY(array), changed_elements)) { 832 if (UseSparseVariant(array, len, IS_ARRAY(array), changed_elements)) {
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 fill: true, 1516 fill: true,
1517 find: true, 1517 find: true,
1518 findIndex: true, 1518 findIndex: true,
1519 keys: true, 1519 keys: true,
1520 }; 1520 };
1521 1521
1522 %AddNamedProperty(GlobalArray.prototype, symbolUnscopables, unscopables, 1522 %AddNamedProperty(GlobalArray.prototype, symbolUnscopables, unscopables,
1523 DONT_ENUM | READ_ONLY); 1523 DONT_ENUM | READ_ONLY);
1524 1524
1525 // Set up non-enumerable functions on the Array object. 1525 // Set up non-enumerable functions on the Array object.
1526 $installFunctions(GlobalArray, DONT_ENUM, [ 1526 InstallFunctions(GlobalArray, DONT_ENUM, [
1527 "isArray", ArrayIsArray 1527 "isArray", ArrayIsArray
1528 ]); 1528 ]);
1529 1529
1530 var specialFunctions = %SpecialArrayFunctions(); 1530 var specialFunctions = %SpecialArrayFunctions();
1531 1531
1532 var getFunction = function(name, jsBuiltin, len) { 1532 var getFunction = function(name, jsBuiltin, len) {
1533 var f = jsBuiltin; 1533 var f = jsBuiltin;
1534 if (specialFunctions.hasOwnProperty(name)) { 1534 if (specialFunctions.hasOwnProperty(name)) {
1535 f = specialFunctions[name]; 1535 f = specialFunctions[name];
1536 } 1536 }
1537 if (!IS_UNDEFINED(len)) { 1537 if (!IS_UNDEFINED(len)) {
1538 %FunctionSetLength(f, len); 1538 %FunctionSetLength(f, len);
1539 } 1539 }
1540 return f; 1540 return f;
1541 }; 1541 };
1542 1542
1543 // Set up non-enumerable functions of the Array.prototype object and 1543 // Set up non-enumerable functions of the Array.prototype object and
1544 // set their names. 1544 // set their names.
1545 // Manipulate the length of some of the functions to meet 1545 // Manipulate the length of some of the functions to meet
1546 // expectations set by ECMA-262 or Mozilla. 1546 // expectations set by ECMA-262 or Mozilla.
1547 $installFunctions(GlobalArray.prototype, DONT_ENUM, [ 1547 InstallFunctions(GlobalArray.prototype, DONT_ENUM, [
1548 "toString", getFunction("toString", ArrayToString), 1548 "toString", getFunction("toString", ArrayToString),
1549 "toLocaleString", getFunction("toLocaleString", ArrayToLocaleString), 1549 "toLocaleString", getFunction("toLocaleString", ArrayToLocaleString),
1550 "join", getFunction("join", ArrayJoin), 1550 "join", getFunction("join", ArrayJoin),
1551 "pop", getFunction("pop", ArrayPop), 1551 "pop", getFunction("pop", ArrayPop),
1552 "push", getFunction("push", ArrayPush, 1), 1552 "push", getFunction("push", ArrayPush, 1),
1553 "concat", getFunction("concat", ArrayConcatJS, 1), 1553 "concat", getFunction("concat", ArrayConcatJS, 1),
1554 "reverse", getFunction("reverse", ArrayReverse), 1554 "reverse", getFunction("reverse", ArrayReverse),
1555 "shift", getFunction("shift", ArrayShift), 1555 "shift", getFunction("shift", ArrayShift),
1556 "unshift", getFunction("unshift", ArrayUnshift, 1), 1556 "unshift", getFunction("unshift", ArrayUnshift, 1),
1557 "slice", getFunction("slice", ArraySlice, 2), 1557 "slice", getFunction("slice", ArraySlice, 2),
1558 "splice", getFunction("splice", ArraySplice, 2), 1558 "splice", getFunction("splice", ArraySplice, 2),
1559 "sort", getFunction("sort", ArraySort), 1559 "sort", getFunction("sort", ArraySort),
1560 "filter", getFunction("filter", ArrayFilter, 1), 1560 "filter", getFunction("filter", ArrayFilter, 1),
1561 "forEach", getFunction("forEach", ArrayForEach, 1), 1561 "forEach", getFunction("forEach", ArrayForEach, 1),
1562 "some", getFunction("some", ArraySome, 1), 1562 "some", getFunction("some", ArraySome, 1),
1563 "every", getFunction("every", ArrayEvery, 1), 1563 "every", getFunction("every", ArrayEvery, 1),
1564 "map", getFunction("map", ArrayMap, 1), 1564 "map", getFunction("map", ArrayMap, 1),
1565 "indexOf", getFunction("indexOf", ArrayIndexOf, 1), 1565 "indexOf", getFunction("indexOf", ArrayIndexOf, 1),
1566 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), 1566 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1),
1567 "reduce", getFunction("reduce", ArrayReduce, 1), 1567 "reduce", getFunction("reduce", ArrayReduce, 1),
1568 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) 1568 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1)
1569 ]); 1569 ]);
1570 1570
1571 %FinishArrayPrototypeSetup(GlobalArray.prototype); 1571 %FinishArrayPrototypeSetup(GlobalArray.prototype);
1572 1572
1573 // The internal Array prototype doesn't need to be fancy, since it's never 1573 // The internal Array prototype doesn't need to be fancy, since it's never
1574 // exposed to user code. 1574 // exposed to user code.
1575 // Adding only the functions that are actually used. 1575 // Adding only the functions that are actually used.
1576 $setUpLockedPrototype(InternalArray, GlobalArray(), [ 1576 SetUpLockedPrototype(InternalArray, GlobalArray(), [
1577 "concat", getFunction("concat", ArrayConcatJS), 1577 "concat", getFunction("concat", ArrayConcatJS),
1578 "indexOf", getFunction("indexOf", ArrayIndexOf), 1578 "indexOf", getFunction("indexOf", ArrayIndexOf),
1579 "join", getFunction("join", ArrayJoin), 1579 "join", getFunction("join", ArrayJoin),
1580 "pop", getFunction("pop", ArrayPop), 1580 "pop", getFunction("pop", ArrayPop),
1581 "push", getFunction("push", ArrayPush), 1581 "push", getFunction("push", ArrayPush),
1582 "splice", getFunction("splice", ArraySplice) 1582 "splice", getFunction("splice", ArraySplice)
1583 ]); 1583 ]);
1584 1584
1585 $setUpLockedPrototype(InternalPackedArray, GlobalArray(), [ 1585 SetUpLockedPrototype(InternalPackedArray, GlobalArray(), [
1586 "join", getFunction("join", ArrayJoin), 1586 "join", getFunction("join", ArrayJoin),
1587 "pop", getFunction("pop", ArrayPop), 1587 "pop", getFunction("pop", ArrayPop),
1588 "push", getFunction("push", ArrayPush) 1588 "push", getFunction("push", ArrayPush)
1589 ]); 1589 ]);
1590 1590
1591 $arrayConcat = ArrayConcatJS; 1591 $arrayConcat = ArrayConcatJS;
1592 $arrayJoin = ArrayJoin; 1592 $arrayJoin = ArrayJoin;
1593 $arrayPush = ArrayPush; 1593 $arrayPush = ArrayPush;
1594 $arrayPop = ArrayPop; 1594 $arrayPop = ArrayPop;
1595 $arrayShift = ArrayShift; 1595 $arrayShift = ArrayShift;
1596 $arraySlice = ArraySlice; 1596 $arraySlice = ArraySlice;
1597 $arraySplice = ArraySplice; 1597 $arraySplice = ArraySplice;
1598 $arrayUnshift = ArrayUnshift; 1598 $arrayUnshift = ArrayUnshift;
1599 1599
1600 })(); 1600 })();
OLDNEW
« no previous file with comments | « src/api.cc ('k') | src/array-iterator.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698