| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 366 var m = %_ArgumentsLength(); | 366 var m = %_ArgumentsLength(); |
| 367 for (var i = 0; i < m; i++) { | 367 for (var i = 0; i < m; i++) { |
| 368 this[i+n] = %_Arguments(i); | 368 this[i+n] = %_Arguments(i); |
| 369 } | 369 } |
| 370 this.length = n + m; | 370 this.length = n + m; |
| 371 return this.length; | 371 return this.length; |
| 372 } | 372 } |
| 373 | 373 |
| 374 | 374 |
| 375 function ArrayConcat(arg1) { // length == 1 | 375 function ArrayConcat(arg1) { // length == 1 |
| 376 var arg_number = 0, arg_count = %_ArgumentsLength(); | 376 // TODO: can we just use arguments? |
| 377 var n = 0; | 377 var arg_count = %_ArgumentsLength(); |
| 378 | 378 var arrays = new $Array(1 + arg_count); |
| 379 var A = $Array(1 + arg_count); | 379 arrays[0] = this; |
| 380 var E = this; | 380 for (var i = 0; i < arg_count; i++) { |
| 381 | 381 arrays[i + 1] = %_Arguments(i); |
| 382 while (true) { | |
| 383 if (IS_ARRAY(E)) { | |
| 384 // This is an array of intervals or an array of keys. Keys are | |
| 385 // represented by non-negative integers. Intervals are represented by | |
| 386 // negative integers, followed by positive counts. The interval start | |
| 387 // is determined by subtracting the entry from -1. There may also be | |
| 388 // undefined entries in the array which should be skipped. | |
| 389 var intervals = %GetArrayKeys(E, E.length); | |
| 390 var length = intervals.length; | |
| 391 for (var k = 0; k < length; k++) { | |
| 392 var key = intervals[k]; | |
| 393 if (key < 0) { | |
| 394 var j = -1 - key; | |
| 395 var limit = j + intervals[++k]; | |
| 396 for (; j < limit; j++) { | |
| 397 if (j in E) { | |
| 398 A[n + j] = E[j]; | |
| 399 } | |
| 400 } | |
| 401 } else { | |
| 402 // The case where key is undefined also ends here. | |
| 403 if (!IS_UNDEFINED(key)) { | |
| 404 A[n + key] = E[key]; | |
| 405 } | |
| 406 } | |
| 407 } | |
| 408 n += E.length; | |
| 409 } else { | |
| 410 A[n++] = E; | |
| 411 } | |
| 412 if (arg_number == arg_count) break; | |
| 413 E = %_Arguments(arg_number++); | |
| 414 } | 382 } |
| 415 | 383 |
| 416 A.length = n; // may contain empty arrays | 384 return %ArrayConcat(arrays); |
| 417 return A; | |
| 418 } | 385 } |
| 419 | 386 |
| 420 | 387 |
| 421 // For implementing reverse() on large, sparse arrays. | 388 // For implementing reverse() on large, sparse arrays. |
| 422 function SparseReverse(array, len) { | 389 function SparseReverse(array, len) { |
| 423 var keys = GetSortedArrayKeys(array, %GetArrayKeys(array, len)); | 390 var keys = GetSortedArrayKeys(array, %GetArrayKeys(array, len)); |
| 424 var high_counter = keys.length - 1; | 391 var high_counter = keys.length - 1; |
| 425 var low_counter = 0; | 392 var low_counter = 0; |
| 426 while (low_counter <= high_counter) { | 393 while (low_counter <= high_counter) { |
| 427 var i = keys[low_counter]; | 394 var i = keys[low_counter]; |
| (...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 ArrayEvery: 1, | 917 ArrayEvery: 1, |
| 951 ArrayMap: 1, | 918 ArrayMap: 1, |
| 952 ArrayIndexOf: 1, | 919 ArrayIndexOf: 1, |
| 953 ArrayLastIndexOf: 1, | 920 ArrayLastIndexOf: 1, |
| 954 ArrayPush: 1 | 921 ArrayPush: 1 |
| 955 }); | 922 }); |
| 956 } | 923 } |
| 957 | 924 |
| 958 | 925 |
| 959 SetupArray(); | 926 SetupArray(); |
| OLD | NEW |