OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
866 if (p == "length") { | 866 if (p == "length") { |
867 var length = obj.length; | 867 var length = obj.length; |
868 if (!desc.hasValue()) { | 868 if (!desc.hasValue()) { |
869 return DefineObjectProperty(obj, "length", desc, should_throw); | 869 return DefineObjectProperty(obj, "length", desc, should_throw); |
870 } | 870 } |
871 var new_length = ToUint32(desc.getValue()); | 871 var new_length = ToUint32(desc.getValue()); |
872 if (new_length != ToNumber(desc.getValue())) { | 872 if (new_length != ToNumber(desc.getValue())) { |
873 throw new $RangeError('defineProperty() array length out of range'); | 873 throw new $RangeError('defineProperty() array length out of range'); |
874 } | 874 } |
875 var length_desc = GetOwnProperty(obj, "length"); | 875 var length_desc = GetOwnProperty(obj, "length"); |
876 // Make sure the below call to DefineObjectProperty() doesn't overwrite | 876 if (new_length != length && !length_desc.isWritable()) { |
877 // any magic "length" property by removing the value. | |
878 desc.value_ = void 0; | |
879 desc.hasValue_ = false; | |
880 if ((new_length != length && !length_desc.isWritable()) || | |
881 !DefineObjectProperty(obj, "length", desc, should_throw)) { | |
882 if (should_throw) { | 877 if (should_throw) { |
883 throw MakeTypeError("redefine_disallowed", [p]); | 878 throw MakeTypeError("redefine_disallowed", [p]); |
884 } else { | 879 } else { |
885 return false; | 880 return false; |
886 } | 881 } |
887 } | 882 } |
| 883 var threw = false; |
| 884 while (new_length < length--) { |
| 885 if (!Delete(obj, ToString(length), false)) { |
| 886 new_length = length + 1; |
| 887 threw = true; |
| 888 break; |
| 889 } |
| 890 } |
| 891 // Make sure the below call to DefineObjectProperty() doesn't overwrite |
| 892 // any magic "length" property by removing the value. |
888 obj.length = new_length; | 893 obj.length = new_length; |
889 while (new_length < length--) { | 894 desc.value_ = void 0; |
890 if (!Delete(obj, length, false)) { | 895 desc.hasValue_ = false; |
891 obj.length = length + 1; | 896 if (!DefineObjectProperty(obj, "length", desc, should_throw) || threw) { |
892 if (should_throw) { | 897 if (should_throw) { |
893 throw MakeTypeError("redefine_disallowed", [p]); | 898 throw MakeTypeError("redefine_disallowed", [p]); |
894 } else { | 899 } else { |
895 return false; | 900 return false; |
896 } | |
897 } | 901 } |
898 } | 902 } |
899 return true; | 903 return true; |
900 } | 904 } |
901 | 905 |
902 // Step 4 - Special handling for array index. | 906 // Step 4 - Special handling for array index. |
903 var index = ToUint32(p); | 907 var index = ToUint32(p); |
904 if (index == ToNumber(p) && index != 4294967295) { | 908 if (index == ToNumber(p) && index != 4294967295) { |
905 var length = obj.length; | 909 var length = obj.length; |
906 var length_desc = GetOwnProperty(obj, "length"); | 910 var length_desc = GetOwnProperty(obj, "length"); |
(...skipping 735 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1642 | 1646 |
1643 function SetUpFunction() { | 1647 function SetUpFunction() { |
1644 %CheckIsBootstrapping(); | 1648 %CheckIsBootstrapping(); |
1645 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1649 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
1646 "bind", FunctionBind, | 1650 "bind", FunctionBind, |
1647 "toString", FunctionToString | 1651 "toString", FunctionToString |
1648 )); | 1652 )); |
1649 } | 1653 } |
1650 | 1654 |
1651 SetUpFunction(); | 1655 SetUpFunction(); |
OLD | NEW |