| 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 855 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 866 | 866 |
| 867 // ES5 section 15.4.5.1. | 867 // ES5 section 15.4.5.1. |
| 868 function DefineArrayProperty(obj, p, desc, should_throw) { | 868 function DefineArrayProperty(obj, p, desc, should_throw) { |
| 869 // Note that the length of an array is not actually stored as part of the | 869 // Note that the length of an array is not actually stored as part of the |
| 870 // property, hence we use generated code throughout this function instead of | 870 // property, hence we use generated code throughout this function instead of |
| 871 // DefineObjectProperty() to modify its value. | 871 // DefineObjectProperty() to modify its value. |
| 872 | 872 |
| 873 // Step 3 - Special handling for length property. | 873 // Step 3 - Special handling for length property. |
| 874 if (p === "length") { | 874 if (p === "length") { |
| 875 var length = obj.length; | 875 var length = obj.length; |
| 876 var old_length = length; |
| 876 if (!desc.hasValue()) { | 877 if (!desc.hasValue()) { |
| 877 return DefineObjectProperty(obj, "length", desc, should_throw); | 878 return DefineObjectProperty(obj, "length", desc, should_throw); |
| 878 } | 879 } |
| 879 var new_length = ToUint32(desc.getValue()); | 880 var new_length = ToUint32(desc.getValue()); |
| 880 if (new_length != ToNumber(desc.getValue())) { | 881 if (new_length != ToNumber(desc.getValue())) { |
| 881 throw new $RangeError('defineProperty() array length out of range'); | 882 throw new $RangeError('defineProperty() array length out of range'); |
| 882 } | 883 } |
| 883 var length_desc = GetOwnProperty(obj, "length"); | 884 var length_desc = GetOwnProperty(obj, "length"); |
| 884 if (new_length != length && !length_desc.isWritable()) { | 885 if (new_length != length && !length_desc.isWritable()) { |
| 885 if (should_throw) { | 886 if (should_throw) { |
| 886 throw MakeTypeError("redefine_disallowed", [p]); | 887 throw MakeTypeError("redefine_disallowed", [p]); |
| 887 } else { | 888 } else { |
| 888 return false; | 889 return false; |
| 889 } | 890 } |
| 890 } | 891 } |
| 891 var threw = false; | 892 var threw = false; |
| 893 |
| 894 var emit_splice = %IsObserved(obj) && new_length !== old_length; |
| 895 var removed; |
| 896 if (emit_splice) { |
| 897 BeginPerformSplice(obj); |
| 898 removed = []; |
| 899 if (new_length < old_length) |
| 900 removed.length = old_length - new_length; |
| 901 } |
| 902 |
| 892 while (new_length < length--) { | 903 while (new_length < length--) { |
| 893 if (!Delete(obj, ToString(length), false)) { | 904 var index = ToString(length); |
| 905 if (emit_splice) { |
| 906 var deletedDesc = GetOwnProperty(obj, index); |
| 907 if (deletedDesc && deletedDesc.hasValue()) |
| 908 removed[length - new_length] = deletedDesc.getValue(); |
| 909 } |
| 910 if (!Delete(obj, index, false)) { |
| 894 new_length = length + 1; | 911 new_length = length + 1; |
| 895 threw = true; | 912 threw = true; |
| 896 break; | 913 break; |
| 897 } | 914 } |
| 898 } | 915 } |
| 899 // Make sure the below call to DefineObjectProperty() doesn't overwrite | 916 // Make sure the below call to DefineObjectProperty() doesn't overwrite |
| 900 // any magic "length" property by removing the value. | 917 // any magic "length" property by removing the value. |
| 901 // TODO(mstarzinger): This hack should be removed once we have addressed the | 918 // TODO(mstarzinger): This hack should be removed once we have addressed the |
| 902 // respective TODO in Runtime_DefineOrRedefineDataProperty. | 919 // respective TODO in Runtime_DefineOrRedefineDataProperty. |
| 903 // For the time being, we need a hack to prevent Object.observe from | 920 // For the time being, we need a hack to prevent Object.observe from |
| 904 // generating two change records. | 921 // generating two change records. |
| 905 var isObserved = %IsObserved(obj); | |
| 906 if (isObserved) %SetIsObserved(obj, false); | |
| 907 obj.length = new_length; | 922 obj.length = new_length; |
| 908 desc.value_ = void 0; | 923 desc.value_ = void 0; |
| 909 desc.hasValue_ = false; | 924 desc.hasValue_ = false; |
| 910 threw = !DefineObjectProperty(obj, "length", desc, should_throw) || threw; | 925 threw = !DefineObjectProperty(obj, "length", desc, should_throw) || threw; |
| 911 if (isObserved) %SetIsObserved(obj, true); | 926 if (emit_splice) { |
| 927 EndPerformSplice(obj); |
| 928 EnqueueSpliceRecord(obj, |
| 929 new_length < old_length ? new_length : old_length, |
| 930 removed, |
| 931 removed.length, |
| 932 new_length > old_length ? new_length - old_length : 0); |
| 933 } |
| 912 if (threw) { | 934 if (threw) { |
| 913 if (should_throw) { | 935 if (should_throw) { |
| 914 throw MakeTypeError("redefine_disallowed", [p]); | 936 throw MakeTypeError("redefine_disallowed", [p]); |
| 915 } else { | 937 } else { |
| 916 return false; | 938 return false; |
| 917 } | 939 } |
| 918 } | 940 } |
| 919 if (isObserved) { | |
| 920 var new_desc = GetOwnProperty(obj, "length"); | |
| 921 var updated = length_desc.value_ !== new_desc.value_; | |
| 922 var reconfigured = length_desc.writable_ !== new_desc.writable_ || | |
| 923 length_desc.configurable_ !== new_desc.configurable_ || | |
| 924 length_desc.enumerable_ !== new_desc.configurable_; | |
| 925 if (updated || reconfigured) { | |
| 926 NotifyChange(reconfigured ? "reconfigured" : "updated", | |
| 927 obj, "length", length_desc.value_); | |
| 928 } | |
| 929 } | |
| 930 return true; | 941 return true; |
| 931 } | 942 } |
| 932 | 943 |
| 933 // Step 4 - Special handling for array index. | 944 // Step 4 - Special handling for array index. |
| 934 var index = ToUint32(p); | 945 var index = ToUint32(p); |
| 946 var emit_splice = false; |
| 935 if (ToString(index) == p && index != 4294967295) { | 947 if (ToString(index) == p && index != 4294967295) { |
| 936 var length = obj.length; | 948 var length = obj.length; |
| 949 if (index >= length && %IsObserved(obj)) { |
| 950 emit_splice = true; |
| 951 BeginPerformSplice(obj); |
| 952 } |
| 953 |
| 937 var length_desc = GetOwnProperty(obj, "length"); | 954 var length_desc = GetOwnProperty(obj, "length"); |
| 938 if ((index >= length && !length_desc.isWritable()) || | 955 if ((index >= length && !length_desc.isWritable()) || |
| 939 !DefineObjectProperty(obj, p, desc, true)) { | 956 !DefineObjectProperty(obj, p, desc, true)) { |
| 957 if (emit_splice) |
| 958 EndPerformSplice(obj); |
| 940 if (should_throw) { | 959 if (should_throw) { |
| 941 throw MakeTypeError("define_disallowed", [p]); | 960 throw MakeTypeError("define_disallowed", [p]); |
| 942 } else { | 961 } else { |
| 943 return false; | 962 return false; |
| 944 } | 963 } |
| 945 } | 964 } |
| 946 if (index >= length) { | 965 if (index >= length) { |
| 947 obj.length = index + 1; | 966 obj.length = index + 1; |
| 948 } | 967 } |
| 968 if (emit_splice) { |
| 969 EndPerformSplice(obj); |
| 970 EnqueueSpliceRecord(obj, length, [], 0, index + 1 - length); |
| 971 } |
| 949 return true; | 972 return true; |
| 950 } | 973 } |
| 951 | 974 |
| 952 // Step 5 - Fallback to default implementation. | 975 // Step 5 - Fallback to default implementation. |
| 953 return DefineObjectProperty(obj, p, desc, should_throw); | 976 return DefineObjectProperty(obj, p, desc, should_throw); |
| 954 } | 977 } |
| 955 | 978 |
| 956 | 979 |
| 957 // ES5 section 8.12.9, ES5 section 15.4.5.1 and Harmony proxies. | 980 // ES5 section 8.12.9, ES5 section 15.4.5.1 and Harmony proxies. |
| 958 function DefineOwnProperty(obj, p, desc, should_throw) { | 981 function DefineOwnProperty(obj, p, desc, should_throw) { |
| (...skipping 842 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1801 %SetCode($Function, NewFunction); | 1824 %SetCode($Function, NewFunction); |
| 1802 %SetProperty($Function.prototype, "constructor", $Function, DONT_ENUM); | 1825 %SetProperty($Function.prototype, "constructor", $Function, DONT_ENUM); |
| 1803 | 1826 |
| 1804 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1827 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
| 1805 "bind", FunctionBind, | 1828 "bind", FunctionBind, |
| 1806 "toString", FunctionToString | 1829 "toString", FunctionToString |
| 1807 )); | 1830 )); |
| 1808 } | 1831 } |
| 1809 | 1832 |
| 1810 SetUpFunction(); | 1833 SetUpFunction(); |
| OLD | NEW |