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

Side by Side Diff: src/v8natives.js

Issue 1224523002: Avoid converting key to string for deleting of elements (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 5 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/runtime/runtime-object.cc ('k') | test/mjsunit/messages.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 $functionSourceString; 5 var $functionSourceString;
6 var $globalEval; 6 var $globalEval;
7 var $objectDefineOwnProperty; 7 var $objectDefineOwnProperty;
8 var $objectGetOwnPropertyDescriptor; 8 var $objectGetOwnPropertyDescriptor;
9 var $toCompletePropertyDescriptor; 9 var $toCompletePropertyDescriptor;
10 10
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 setter = current.getSet(); 795 setter = current.getSet();
796 } 796 }
797 %DefineAccessorPropertyUnchecked(obj, p, getter, setter, flag); 797 %DefineAccessorPropertyUnchecked(obj, p, getter, setter, flag);
798 } 798 }
799 return true; 799 return true;
800 } 800 }
801 801
802 802
803 // ES5 section 15.4.5.1. 803 // ES5 section 15.4.5.1.
804 function DefineArrayProperty(obj, p, desc, should_throw) { 804 function DefineArrayProperty(obj, p, desc, should_throw) {
805 // Note that the length of an array is not actually stored as part of the 805 // Step 3 - Special handling for array index.
806 // property, hence we use generated code throughout this function instead of
807 // DefineObjectProperty() to modify its value.
808
809 // Step 3 - Special handling for length property.
810 if (p === "length") {
811 var length = obj.length;
812 var old_length = length;
813 if (!desc.hasValue()) {
814 return DefineObjectProperty(obj, "length", desc, should_throw);
815 }
816 var new_length = $toUint32(desc.getValue());
817 if (new_length != $toNumber(desc.getValue())) {
818 throw MakeRangeError(kArrayLengthOutOfRange);
819 }
820 var length_desc = GetOwnPropertyJS(obj, "length");
821 if (new_length != length && !length_desc.isWritable()) {
822 if (should_throw) {
823 throw MakeTypeError(kRedefineDisallowed, p);
824 } else {
825 return false;
826 }
827 }
828 var threw = false;
829
830 var emit_splice = %IsObserved(obj) && new_length !== old_length;
831 var removed;
832 if (emit_splice) {
833 $observeBeginPerformSplice(obj);
834 removed = [];
835 if (new_length < old_length)
836 removed.length = old_length - new_length;
837 }
838
839 while (new_length < length--) {
840 var index = $toString(length);
841 if (emit_splice) {
842 var deletedDesc = GetOwnPropertyJS(obj, index);
843 if (deletedDesc && deletedDesc.hasValue())
844 removed[length - new_length] = deletedDesc.getValue();
845 }
846 if (!Delete(obj, index, false)) {
847 new_length = length + 1;
848 threw = true;
849 break;
850 }
851 }
852 threw = !DefineObjectProperty(obj, "length", desc, should_throw) || threw;
853 if (emit_splice) {
854 $observeEndPerformSplice(obj);
855 $observeEnqueueSpliceRecord(obj,
856 new_length < old_length ? new_length : old_length,
857 removed,
858 new_length > old_length ? new_length - old_length : 0);
859 }
860 if (threw) {
861 if (should_throw) {
862 throw MakeTypeError(kRedefineDisallowed, p);
863 } else {
864 return false;
865 }
866 }
867 return true;
868 }
869
870 // Step 4 - Special handling for array index.
871 if (!IS_SYMBOL(p)) { 806 if (!IS_SYMBOL(p)) {
872 var index = $toUint32(p); 807 var index = $toUint32(p);
873 var emit_splice = false; 808 var emit_splice = false;
874 if ($toString(index) == p && index != 4294967295) { 809 if ($toString(index) == p && index != 4294967295) {
875 var length = obj.length; 810 var length = obj.length;
876 if (index >= length && %IsObserved(obj)) { 811 if (index >= length && %IsObserved(obj)) {
877 emit_splice = true; 812 emit_splice = true;
878 $observeBeginPerformSplice(obj); 813 $observeBeginPerformSplice(obj);
879 } 814 }
880 815
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after
1873 to.ObjectGetOwnPropertyKeys = ObjectGetOwnPropertyKeys; 1808 to.ObjectGetOwnPropertyKeys = ObjectGetOwnPropertyKeys;
1874 to.ObjectHasOwnProperty = ObjectHasOwnProperty; 1809 to.ObjectHasOwnProperty = ObjectHasOwnProperty;
1875 to.ObjectIsFrozen = ObjectIsFrozen; 1810 to.ObjectIsFrozen = ObjectIsFrozen;
1876 to.ObjectIsSealed = ObjectIsSealed; 1811 to.ObjectIsSealed = ObjectIsSealed;
1877 to.ObjectToString = ObjectToString; 1812 to.ObjectToString = ObjectToString;
1878 to.OwnPropertyKeys = OwnPropertyKeys; 1813 to.OwnPropertyKeys = OwnPropertyKeys;
1879 to.ToNameArray = ToNameArray; 1814 to.ToNameArray = ToNameArray;
1880 }); 1815 });
1881 1816
1882 }) 1817 })
OLDNEW
« no previous file with comments | « src/runtime/runtime-object.cc ('k') | test/mjsunit/messages.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698