OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 if (!IS_UNDEFINED(result)) return result; | 392 if (!IS_UNDEFINED(result)) return result; |
393 | 393 |
394 return Join(this, length, separator, ConvertToString); | 394 return Join(this, length, separator, ConvertToString); |
395 } | 395 } |
396 | 396 |
397 | 397 |
398 function ObservedArrayPop(n) { | 398 function ObservedArrayPop(n) { |
399 n--; | 399 n--; |
400 var value = this[n]; | 400 var value = this[n]; |
401 | 401 |
402 EnqueueSpliceRecord(this, n, [value], 0); | |
403 | |
404 try { | 402 try { |
405 BeginPerformSplice(this); | 403 BeginPerformSplice(this); |
406 delete this[n]; | 404 delete this[n]; |
407 this.length = n; | 405 this.length = n; |
408 } finally { | 406 } finally { |
409 EndPerformSplice(this); | 407 EndPerformSplice(this); |
| 408 EnqueueSpliceRecord(this, n, [value], 0); |
410 } | 409 } |
411 | 410 |
412 return value; | 411 return value; |
413 } | 412 } |
414 | 413 |
415 // Removes the last element from the array and returns it. See | 414 // Removes the last element from the array and returns it. See |
416 // ECMA-262, section 15.4.4.6. | 415 // ECMA-262, section 15.4.4.6. |
417 function ArrayPop() { | 416 function ArrayPop() { |
418 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 417 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
419 throw MakeTypeError("called_on_null_or_undefined", | 418 throw MakeTypeError("called_on_null_or_undefined", |
(...skipping 14 matching lines...) Expand all Loading... |
434 delete this[n]; | 433 delete this[n]; |
435 this.length = n; | 434 this.length = n; |
436 return value; | 435 return value; |
437 } | 436 } |
438 | 437 |
439 | 438 |
440 function ObservedArrayPush() { | 439 function ObservedArrayPush() { |
441 var n = TO_UINT32(this.length); | 440 var n = TO_UINT32(this.length); |
442 var m = %_ArgumentsLength(); | 441 var m = %_ArgumentsLength(); |
443 | 442 |
444 EnqueueSpliceRecord(this, n, [], m); | |
445 | |
446 try { | 443 try { |
447 BeginPerformSplice(this); | 444 BeginPerformSplice(this); |
448 for (var i = 0; i < m; i++) { | 445 for (var i = 0; i < m; i++) { |
449 this[i+n] = %_Arguments(i); | 446 this[i+n] = %_Arguments(i); |
450 } | 447 } |
451 this.length = n + m; | 448 this.length = n + m; |
452 } finally { | 449 } finally { |
453 EndPerformSplice(this); | 450 EndPerformSplice(this); |
| 451 EnqueueSpliceRecord(this, n, [], m); |
454 } | 452 } |
455 | 453 |
456 return this.length; | 454 return this.length; |
457 } | 455 } |
458 | 456 |
459 // Appends the arguments to the end of the array and returns the new | 457 // Appends the arguments to the end of the array and returns the new |
460 // length of the array. See ECMA-262, section 15.4.4.7. | 458 // length of the array. See ECMA-262, section 15.4.4.7. |
461 function ArrayPush() { | 459 function ArrayPush() { |
462 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 460 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
463 throw MakeTypeError("called_on_null_or_undefined", | 461 throw MakeTypeError("called_on_null_or_undefined", |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
574 } | 572 } |
575 } | 573 } |
576 } | 574 } |
577 return this; | 575 return this; |
578 } | 576 } |
579 | 577 |
580 | 578 |
581 function ObservedArrayShift(len) { | 579 function ObservedArrayShift(len) { |
582 var first = this[0]; | 580 var first = this[0]; |
583 | 581 |
584 EnqueueSpliceRecord(this, 0, [first], 0); | |
585 | |
586 try { | 582 try { |
587 BeginPerformSplice(this); | 583 BeginPerformSplice(this); |
588 SimpleMove(this, 0, 1, len, 0); | 584 SimpleMove(this, 0, 1, len, 0); |
589 this.length = len - 1; | 585 this.length = len - 1; |
590 } finally { | 586 } finally { |
591 EndPerformSplice(this); | 587 EndPerformSplice(this); |
| 588 EnqueueSpliceRecord(this, 0, [first], 0); |
592 } | 589 } |
593 | 590 |
594 return first; | 591 return first; |
595 } | 592 } |
596 | 593 |
597 function ArrayShift() { | 594 function ArrayShift() { |
598 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 595 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
599 throw MakeTypeError("called_on_null_or_undefined", | 596 throw MakeTypeError("called_on_null_or_undefined", |
600 ["Array.prototype.shift"]); | 597 ["Array.prototype.shift"]); |
601 } | 598 } |
(...skipping 18 matching lines...) Expand all Loading... |
620 | 617 |
621 this.length = len - 1; | 618 this.length = len - 1; |
622 | 619 |
623 return first; | 620 return first; |
624 } | 621 } |
625 | 622 |
626 function ObservedArrayUnshift() { | 623 function ObservedArrayUnshift() { |
627 var len = TO_UINT32(this.length); | 624 var len = TO_UINT32(this.length); |
628 var num_arguments = %_ArgumentsLength(); | 625 var num_arguments = %_ArgumentsLength(); |
629 | 626 |
630 EnqueueSpliceRecord(this, 0, [], num_arguments); | |
631 | |
632 try { | 627 try { |
633 BeginPerformSplice(this); | 628 BeginPerformSplice(this); |
634 SimpleMove(this, 0, 0, len, num_arguments); | 629 SimpleMove(this, 0, 0, len, num_arguments); |
635 for (var i = 0; i < num_arguments; i++) { | 630 for (var i = 0; i < num_arguments; i++) { |
636 this[i] = %_Arguments(i); | 631 this[i] = %_Arguments(i); |
637 } | 632 } |
638 this.length = len + num_arguments; | 633 this.length = len + num_arguments; |
639 } finally { | 634 } finally { |
640 EndPerformSplice(this); | 635 EndPerformSplice(this); |
| 636 EnqueueSpliceRecord(this, 0, [], num_arguments); |
641 } | 637 } |
642 | 638 |
643 return len + num_arguments; | 639 return len + num_arguments; |
644 } | 640 } |
645 | 641 |
646 function ArrayUnshift(arg1) { // length == 1 | 642 function ArrayUnshift(arg1) { // length == 1 |
647 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { | 643 if (IS_NULL_OR_UNDEFINED(this) && !IS_UNDETECTABLE(this)) { |
648 throw MakeTypeError("called_on_null_or_undefined", | 644 throw MakeTypeError("called_on_null_or_undefined", |
649 ["Array.prototype.unshift"]); | 645 ["Array.prototype.unshift"]); |
650 } | 646 } |
(...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1656 )); | 1652 )); |
1657 | 1653 |
1658 SetUpLockedPrototype(InternalPackedArray, $Array(), $Array( | 1654 SetUpLockedPrototype(InternalPackedArray, $Array(), $Array( |
1659 "join", getFunction("join", ArrayJoin), | 1655 "join", getFunction("join", ArrayJoin), |
1660 "pop", getFunction("pop", ArrayPop), | 1656 "pop", getFunction("pop", ArrayPop), |
1661 "push", getFunction("push", ArrayPush) | 1657 "push", getFunction("push", ArrayPush) |
1662 )); | 1658 )); |
1663 } | 1659 } |
1664 | 1660 |
1665 SetUpArray(); | 1661 SetUpArray(); |
OLD | NEW |