| 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 "use strict"; | 5 "use strict"; |
| 6 | 6 |
| 7 // This file relies on the fact that the following declarations have been made | 7 // This file relies on the fact that the following declarations have been made |
| 8 // in runtime.js: | 8 // in runtime.js: |
| 9 // var $Array = global.Array; | 9 // var $Array = global.Array; |
| 10 | 10 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 keys.push(key); | 38 keys.push(key); |
| 39 } | 39 } |
| 40 } | 40 } |
| 41 } | 41 } |
| 42 %_CallFunction(keys, function(a, b) { return a - b; }, ArraySort); | 42 %_CallFunction(keys, function(a, b) { return a - b; }, ArraySort); |
| 43 } | 43 } |
| 44 return keys; | 44 return keys; |
| 45 } | 45 } |
| 46 | 46 |
| 47 | 47 |
| 48 function SparseJoinWithSeparator(array, len, convert, separator) { | 48 function SparseJoinWithSeparatorJS(array, len, convert, separator) { |
| 49 var keys = GetSortedArrayKeys(array, %GetArrayKeys(array, len)); | 49 var keys = GetSortedArrayKeys(array, %GetArrayKeys(array, len)); |
| 50 var totalLength = 0; | 50 var totalLength = 0; |
| 51 var elements = new InternalArray(keys.length * 2); | 51 var elements = new InternalArray(keys.length * 2); |
| 52 var previousKey = -1; | 52 var previousKey = -1; |
| 53 for (var i = 0; i < keys.length; i++) { | 53 for (var i = 0; i < keys.length; i++) { |
| 54 var key = keys[i]; | 54 var key = keys[i]; |
| 55 if (key != previousKey) { // keys may contain duplicates. | 55 if (key != previousKey) { // keys may contain duplicates. |
| 56 var e = array[key]; | 56 var e = array[key]; |
| 57 if (!IS_STRING(e)) e = convert(e); | 57 if (!IS_STRING(e)) e = convert(e); |
| 58 elements[i * 2] = key; | 58 elements[i * 2] = key; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 // visited arrays. | 104 // visited arrays. |
| 105 if (!%PushIfAbsent(visited_arrays, array)) return ''; | 105 if (!%PushIfAbsent(visited_arrays, array)) return ''; |
| 106 } | 106 } |
| 107 | 107 |
| 108 // Attempt to convert the elements. | 108 // Attempt to convert the elements. |
| 109 try { | 109 try { |
| 110 if (UseSparseVariant(array, length, is_array)) { | 110 if (UseSparseVariant(array, length, is_array)) { |
| 111 if (separator.length == 0) { | 111 if (separator.length == 0) { |
| 112 return SparseJoin(array, length, convert); | 112 return SparseJoin(array, length, convert); |
| 113 } else { | 113 } else { |
| 114 return SparseJoinWithSeparator(array, length, convert, separator); | 114 return SparseJoinWithSeparatorJS(array, length, convert, separator); |
| 115 } | 115 } |
| 116 } | 116 } |
| 117 | 117 |
| 118 // Fast case for one-element arrays. | 118 // Fast case for one-element arrays. |
| 119 if (length == 1) { | 119 if (length == 1) { |
| 120 var e = array[0]; | 120 var e = array[0]; |
| 121 if (IS_STRING(e)) return e; | 121 if (IS_STRING(e)) return e; |
| 122 return convert(e); | 122 return convert(e); |
| 123 } | 123 } |
| 124 | 124 |
| (...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 | 450 |
| 451 var new_length = n + m; | 451 var new_length = n + m; |
| 452 array.length = new_length; | 452 array.length = new_length; |
| 453 return new_length; | 453 return new_length; |
| 454 } | 454 } |
| 455 | 455 |
| 456 | 456 |
| 457 // Returns an array containing the array elements of the object followed | 457 // Returns an array containing the array elements of the object followed |
| 458 // by the array elements of each argument in order. See ECMA-262, | 458 // by the array elements of each argument in order. See ECMA-262, |
| 459 // section 15.4.4.7. | 459 // section 15.4.4.7. |
| 460 function ArrayConcat(arg1) { // length == 1 | 460 function ArrayConcatJS(arg1) { // length == 1 |
| 461 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.concat"); | 461 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.concat"); |
| 462 | 462 |
| 463 var array = ToObject(this); | 463 var array = ToObject(this); |
| 464 var arg_count = %_ArgumentsLength(); | 464 var arg_count = %_ArgumentsLength(); |
| 465 var arrays = new InternalArray(1 + arg_count); | 465 var arrays = new InternalArray(1 + arg_count); |
| 466 arrays[0] = array; | 466 arrays[0] = array; |
| 467 for (var i = 0; i < arg_count; i++) { | 467 for (var i = 0; i < arg_count; i++) { |
| 468 arrays[i + 1] = %_Arguments(i); | 468 arrays[i + 1] = %_Arguments(i); |
| 469 } | 469 } |
| 470 | 470 |
| (...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1485 // Set up non-enumerable functions of the Array.prototype object and | 1485 // Set up non-enumerable functions of the Array.prototype object and |
| 1486 // set their names. | 1486 // set their names. |
| 1487 // Manipulate the length of some of the functions to meet | 1487 // Manipulate the length of some of the functions to meet |
| 1488 // expectations set by ECMA-262 or Mozilla. | 1488 // expectations set by ECMA-262 or Mozilla. |
| 1489 InstallFunctions($Array.prototype, DONT_ENUM, $Array( | 1489 InstallFunctions($Array.prototype, DONT_ENUM, $Array( |
| 1490 "toString", getFunction("toString", ArrayToString), | 1490 "toString", getFunction("toString", ArrayToString), |
| 1491 "toLocaleString", getFunction("toLocaleString", ArrayToLocaleString), | 1491 "toLocaleString", getFunction("toLocaleString", ArrayToLocaleString), |
| 1492 "join", getFunction("join", ArrayJoin), | 1492 "join", getFunction("join", ArrayJoin), |
| 1493 "pop", getFunction("pop", ArrayPop), | 1493 "pop", getFunction("pop", ArrayPop), |
| 1494 "push", getFunction("push", ArrayPush, 1), | 1494 "push", getFunction("push", ArrayPush, 1), |
| 1495 "concat", getFunction("concat", ArrayConcat, 1), | 1495 "concat", getFunction("concat", ArrayConcatJS, 1), |
| 1496 "reverse", getFunction("reverse", ArrayReverse), | 1496 "reverse", getFunction("reverse", ArrayReverse), |
| 1497 "shift", getFunction("shift", ArrayShift), | 1497 "shift", getFunction("shift", ArrayShift), |
| 1498 "unshift", getFunction("unshift", ArrayUnshift, 1), | 1498 "unshift", getFunction("unshift", ArrayUnshift, 1), |
| 1499 "slice", getFunction("slice", ArraySlice, 2), | 1499 "slice", getFunction("slice", ArraySlice, 2), |
| 1500 "splice", getFunction("splice", ArraySplice, 2), | 1500 "splice", getFunction("splice", ArraySplice, 2), |
| 1501 "sort", getFunction("sort", ArraySort), | 1501 "sort", getFunction("sort", ArraySort), |
| 1502 "filter", getFunction("filter", ArrayFilter, 1), | 1502 "filter", getFunction("filter", ArrayFilter, 1), |
| 1503 "forEach", getFunction("forEach", ArrayForEach, 1), | 1503 "forEach", getFunction("forEach", ArrayForEach, 1), |
| 1504 "some", getFunction("some", ArraySome, 1), | 1504 "some", getFunction("some", ArraySome, 1), |
| 1505 "every", getFunction("every", ArrayEvery, 1), | 1505 "every", getFunction("every", ArrayEvery, 1), |
| 1506 "map", getFunction("map", ArrayMap, 1), | 1506 "map", getFunction("map", ArrayMap, 1), |
| 1507 "indexOf", getFunction("indexOf", ArrayIndexOf, 1), | 1507 "indexOf", getFunction("indexOf", ArrayIndexOf, 1), |
| 1508 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), | 1508 "lastIndexOf", getFunction("lastIndexOf", ArrayLastIndexOf, 1), |
| 1509 "reduce", getFunction("reduce", ArrayReduce, 1), | 1509 "reduce", getFunction("reduce", ArrayReduce, 1), |
| 1510 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) | 1510 "reduceRight", getFunction("reduceRight", ArrayReduceRight, 1) |
| 1511 )); | 1511 )); |
| 1512 | 1512 |
| 1513 %FinishArrayPrototypeSetup($Array.prototype); | 1513 %FinishArrayPrototypeSetup($Array.prototype); |
| 1514 | 1514 |
| 1515 // The internal Array prototype doesn't need to be fancy, since it's never | 1515 // The internal Array prototype doesn't need to be fancy, since it's never |
| 1516 // exposed to user code. | 1516 // exposed to user code. |
| 1517 // Adding only the functions that are actually used. | 1517 // Adding only the functions that are actually used. |
| 1518 SetUpLockedPrototype(InternalArray, $Array(), $Array( | 1518 SetUpLockedPrototype(InternalArray, $Array(), $Array( |
| 1519 "concat", getFunction("concat", ArrayConcat), | 1519 "concat", getFunction("concat", ArrayConcatJS), |
| 1520 "indexOf", getFunction("indexOf", ArrayIndexOf), | 1520 "indexOf", getFunction("indexOf", ArrayIndexOf), |
| 1521 "join", getFunction("join", ArrayJoin), | 1521 "join", getFunction("join", ArrayJoin), |
| 1522 "pop", getFunction("pop", ArrayPop), | 1522 "pop", getFunction("pop", ArrayPop), |
| 1523 "push", getFunction("push", ArrayPush), | 1523 "push", getFunction("push", ArrayPush), |
| 1524 "splice", getFunction("splice", ArraySplice) | 1524 "splice", getFunction("splice", ArraySplice) |
| 1525 )); | 1525 )); |
| 1526 | 1526 |
| 1527 SetUpLockedPrototype(InternalPackedArray, $Array(), $Array( | 1527 SetUpLockedPrototype(InternalPackedArray, $Array(), $Array( |
| 1528 "join", getFunction("join", ArrayJoin), | 1528 "join", getFunction("join", ArrayJoin), |
| 1529 "pop", getFunction("pop", ArrayPop), | 1529 "pop", getFunction("pop", ArrayPop), |
| 1530 "push", getFunction("push", ArrayPush) | 1530 "push", getFunction("push", ArrayPush) |
| 1531 )); | 1531 )); |
| 1532 } | 1532 } |
| 1533 | 1533 |
| 1534 SetUpArray(); | 1534 SetUpArray(); |
| OLD | NEW |