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

Side by Side Diff: src/array.js

Issue 223473002: Use premordial Object.isSealed/isFrozen in builtins. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comments by Michael Stanton. Created 6 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-builtinbust-1.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 // 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 401 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 // ECMA-262, section 15.4.4.6. 412 // ECMA-262, section 15.4.4.6.
413 function ArrayPop() { 413 function ArrayPop() {
414 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.pop"); 414 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.pop");
415 415
416 var n = TO_UINT32(this.length); 416 var n = TO_UINT32(this.length);
417 if (n == 0) { 417 if (n == 0) {
418 this.length = n; 418 this.length = n;
419 return; 419 return;
420 } 420 }
421 421
422 if ($Object.isSealed(this)) { 422 if (ObjectIsSealed(this)) {
423 throw MakeTypeError("array_functions_change_sealed", 423 throw MakeTypeError("array_functions_change_sealed",
424 ["Array.prototype.pop"]); 424 ["Array.prototype.pop"]);
425 } 425 }
426 426
427 if (%IsObserved(this)) 427 if (%IsObserved(this))
428 return ObservedArrayPop.call(this, n); 428 return ObservedArrayPop.call(this, n);
429 429
430 n--; 430 n--;
431 var value = this[n]; 431 var value = this[n];
432 Delete(this, ToName(n), true); 432 Delete(this, ToName(n), true);
(...skipping 20 matching lines...) Expand all
453 return this.length; 453 return this.length;
454 } 454 }
455 455
456 // Appends the arguments to the end of the array and returns the new 456 // Appends the arguments to the end of the array and returns the new
457 // length of the array. See ECMA-262, section 15.4.4.7. 457 // length of the array. See ECMA-262, section 15.4.4.7.
458 function ArrayPush() { 458 function ArrayPush() {
459 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.push"); 459 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.push");
460 460
461 var n = TO_UINT32(this.length); 461 var n = TO_UINT32(this.length);
462 var m = %_ArgumentsLength(); 462 var m = %_ArgumentsLength();
463 if (m > 0 && $Object.isSealed(this)) { 463 if (m > 0 && ObjectIsSealed(this)) {
464 throw MakeTypeError("array_functions_change_sealed", 464 throw MakeTypeError("array_functions_change_sealed",
465 ["Array.prototype.push"]); 465 ["Array.prototype.push"]);
466 } 466 }
467 467
468 if (%IsObserved(this)) 468 if (%IsObserved(this))
469 return ObservedArrayPush.apply(this, arguments); 469 return ObservedArrayPush.apply(this, arguments);
470 470
471 for (var i = 0; i < m; i++) { 471 for (var i = 0; i < m; i++) {
472 this[i+n] = %_Arguments(i); 472 this[i+n] = %_Arguments(i);
473 } 473 }
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 function ArrayShift() { 589 function ArrayShift() {
590 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.shift"); 590 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.shift");
591 591
592 var len = TO_UINT32(this.length); 592 var len = TO_UINT32(this.length);
593 593
594 if (len === 0) { 594 if (len === 0) {
595 this.length = 0; 595 this.length = 0;
596 return; 596 return;
597 } 597 }
598 598
599 if ($Object.isSealed(this)) { 599 if (ObjectIsSealed(this)) {
600 throw MakeTypeError("array_functions_change_sealed", 600 throw MakeTypeError("array_functions_change_sealed",
601 ["Array.prototype.shift"]); 601 ["Array.prototype.shift"]);
602 } 602 }
603 603
604 if (%IsObserved(this)) 604 if (%IsObserved(this))
605 return ObservedArrayShift.call(this, len); 605 return ObservedArrayShift.call(this, len);
606 606
607 var first = this[0]; 607 var first = this[0];
608 608
609 if (IS_ARRAY(this)) { 609 if (IS_ARRAY(this)) {
(...skipping 24 matching lines...) Expand all
634 } 634 }
635 635
636 return len + num_arguments; 636 return len + num_arguments;
637 } 637 }
638 638
639 function ArrayUnshift(arg1) { // length == 1 639 function ArrayUnshift(arg1) { // length == 1
640 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.unshift"); 640 CHECK_OBJECT_COERCIBLE(this, "Array.prototype.unshift");
641 641
642 var len = TO_UINT32(this.length); 642 var len = TO_UINT32(this.length);
643 var num_arguments = %_ArgumentsLength(); 643 var num_arguments = %_ArgumentsLength();
644 var is_sealed = $Object.isSealed(this); 644 var is_sealed = ObjectIsSealed(this);
645 645
646 if (num_arguments > 0 && is_sealed) { 646 if (num_arguments > 0 && is_sealed) {
647 throw MakeTypeError("array_functions_change_sealed", 647 throw MakeTypeError("array_functions_change_sealed",
648 ["Array.prototype.unshift"]); 648 ["Array.prototype.unshift"]);
649 } 649 }
650 650
651 if (%IsObserved(this)) 651 if (%IsObserved(this))
652 return ObservedArrayUnshift.apply(this, arguments); 652 return ObservedArrayUnshift.apply(this, arguments);
653 653
654 if (IS_ARRAY(this) && !is_sealed) { 654 if (IS_ARRAY(this) && !is_sealed) {
655 SmartMove(this, 0, 0, len, num_arguments); 655 SmartMove(this, 0, 0, len, num_arguments);
656 } else { 656 } else {
657 if (num_arguments == 0 && $Object.isFrozen(this)) { 657 if (num_arguments == 0 && ObjectIsFrozen(this)) {
658 // In the zero argument case, values from the prototype come into the 658 // In the zero argument case, values from the prototype come into the
659 // object. This can't be allowed on frozen arrays. 659 // object. This can't be allowed on frozen arrays.
660 for (var i = 0; i < len; i++) { 660 for (var i = 0; i < len; i++) {
661 if (!this.hasOwnProperty(i) && !IS_UNDEFINED(this[i])) { 661 if (!this.hasOwnProperty(i) && !IS_UNDEFINED(this[i])) {
662 throw MakeTypeError("array_functions_on_frozen", 662 throw MakeTypeError("array_functions_on_frozen",
663 ["Array.prototype.shift"]); 663 ["Array.prototype.shift"]);
664 } 664 }
665 } 665 }
666 } 666 }
667 667
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 800
801 var num_arguments = %_ArgumentsLength(); 801 var num_arguments = %_ArgumentsLength();
802 var len = TO_UINT32(this.length); 802 var len = TO_UINT32(this.length);
803 var start_i = ComputeSpliceStartIndex(TO_INTEGER(start), len); 803 var start_i = ComputeSpliceStartIndex(TO_INTEGER(start), len);
804 var del_count = ComputeSpliceDeleteCount(delete_count, num_arguments, len, 804 var del_count = ComputeSpliceDeleteCount(delete_count, num_arguments, len,
805 start_i); 805 start_i);
806 var deleted_elements = []; 806 var deleted_elements = [];
807 deleted_elements.length = del_count; 807 deleted_elements.length = del_count;
808 var num_elements_to_add = num_arguments > 2 ? num_arguments - 2 : 0; 808 var num_elements_to_add = num_arguments > 2 ? num_arguments - 2 : 0;
809 809
810 if (del_count != num_elements_to_add && $Object.isSealed(this)) { 810 if (del_count != num_elements_to_add && ObjectIsSealed(this)) {
811 throw MakeTypeError("array_functions_change_sealed", 811 throw MakeTypeError("array_functions_change_sealed",
812 ["Array.prototype.splice"]); 812 ["Array.prototype.splice"]);
813 } else if (del_count > 0 && $Object.isFrozen(this)) { 813 } else if (del_count > 0 && ObjectIsFrozen(this)) {
814 throw MakeTypeError("array_functions_on_frozen", 814 throw MakeTypeError("array_functions_on_frozen",
815 ["Array.prototype.splice"]); 815 ["Array.prototype.splice"]);
816 } 816 }
817 817
818 var use_simple_splice = true; 818 var use_simple_splice = true;
819 if (IS_ARRAY(this) && 819 if (IS_ARRAY(this) &&
820 num_elements_to_add !== del_count) { 820 num_elements_to_add !== del_count) {
821 // If we are only deleting/moving a few things near the end of the 821 // If we are only deleting/moving a few things near the end of the
822 // array then the simple version is going to be faster, because it 822 // array then the simple version is going to be faster, because it
823 // doesn't touch most of the array. 823 // doesn't touch most of the array.
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after
1635 )); 1635 ));
1636 1636
1637 SetUpLockedPrototype(InternalPackedArray, $Array(), $Array( 1637 SetUpLockedPrototype(InternalPackedArray, $Array(), $Array(
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 )); 1641 ));
1642 } 1642 }
1643 1643
1644 SetUpArray(); 1644 SetUpArray();
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/regress/regress-builtinbust-1.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698