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 672 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 [handler, "defineProperty"]); | 683 [handler, "defineProperty"]); |
684 } else { | 684 } else { |
685 return false; | 685 return false; |
686 } | 686 } |
687 } | 687 } |
688 return true; | 688 return true; |
689 } | 689 } |
690 | 690 |
691 | 691 |
692 // ES5 8.12.9. | 692 // ES5 8.12.9. |
693 function DefineOwnProperty(obj, p, desc, should_throw) { | 693 function DefineObjectProperty(obj, p, desc, should_throw) { |
694 if (%IsJSProxy(obj)) { | |
695 var attributes = FromGenericPropertyDescriptor(desc); | |
696 return DefineProxyProperty(obj, p, attributes, should_throw); | |
697 } | |
698 | |
699 var current_or_access = %GetOwnProperty(ToObject(obj), ToString(p)); | 694 var current_or_access = %GetOwnProperty(ToObject(obj), ToString(p)); |
700 // A false value here means that access checks failed. | 695 // A false value here means that access checks failed. |
701 if (current_or_access === false) return void 0; | 696 if (current_or_access === false) return void 0; |
702 | 697 |
703 var current = ConvertDescriptorArrayToDescriptor(current_or_access); | 698 var current = ConvertDescriptorArrayToDescriptor(current_or_access); |
704 var extensible = %IsExtensible(ToObject(obj)); | 699 var extensible = %IsExtensible(ToObject(obj)); |
705 | 700 |
706 // Error handling according to spec. | 701 // Error handling according to spec. |
707 // Step 3 | 702 // Step 3 |
708 if (IS_UNDEFINED(current) && !extensible) { | 703 if (IS_UNDEFINED(current) && !extensible) { |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 %DefineOrRedefineAccessorProperty(obj, p, GETTER, desc.getGet(), flag); | 847 %DefineOrRedefineAccessorProperty(obj, p, GETTER, desc.getGet(), flag); |
853 } | 848 } |
854 if (desc.hasSetter()) { | 849 if (desc.hasSetter()) { |
855 %DefineOrRedefineAccessorProperty(obj, p, SETTER, desc.getSet(), flag); | 850 %DefineOrRedefineAccessorProperty(obj, p, SETTER, desc.getSet(), flag); |
856 } | 851 } |
857 } | 852 } |
858 return true; | 853 return true; |
859 } | 854 } |
860 | 855 |
861 | 856 |
| 857 // ES5 section 15.4.5.1. |
| 858 function DefineArrayProperty(obj, p, desc, should_throw) { |
| 859 var length_desc = GetOwnProperty(obj, "length"); |
| 860 var length = length_desc.getValue(); |
| 861 |
| 862 // Step 3 - Special handling for the length property. |
| 863 if (p == "length") { |
| 864 if (!desc.hasValue()) { |
| 865 return DefineObjectProperty(obj, "length", desc, should_throw); |
| 866 } |
| 867 var new_length = ToUint32(desc.getValue()); |
| 868 if (new_length != ToNumber(desc.getValue())) { |
| 869 throw new $RangeError('defineProperty() array length out of range'); |
| 870 } |
| 871 // TODO(1756): There still are some uncovered corner cases left on how to |
| 872 // handle changes to the length property of arrays. |
| 873 return DefineObjectProperty(obj, "length", desc, should_throw); |
| 874 } |
| 875 |
| 876 // Step 4 - Special handling for array index. |
| 877 var index = ToUint32(p); |
| 878 if (index == ToNumber(p) && index != 4294967295) { |
| 879 if ((index >= length && !length_desc.isWritable()) || |
| 880 !DefineObjectProperty(obj, p, desc, true)) { |
| 881 if (should_throw) { |
| 882 throw MakeTypeError("define_disallowed", [p]); |
| 883 } else { |
| 884 return; |
| 885 } |
| 886 } |
| 887 if (index >= length) { |
| 888 // TODO(mstarzinger): We should actually set the value of the property |
| 889 // descriptor here and pass it to DefineObjectProperty(). Take a look at |
| 890 // ES5 section 15.4.5.1, step 4.e.i and 4.e.ii for details. |
| 891 obj.length = index + 1; |
| 892 } |
| 893 return true; |
| 894 } |
| 895 |
| 896 // Step 5 - Fallback to default implementation. |
| 897 return DefineObjectProperty(obj, p, desc, should_throw); |
| 898 } |
| 899 |
| 900 |
| 901 // ES5 section 8.12.9, ES5 section 15.4.5.1 and Harmony proxies. |
| 902 function DefineOwnProperty(obj, p, desc, should_throw) { |
| 903 if (%IsJSProxy(obj)) { |
| 904 var attributes = FromGenericPropertyDescriptor(desc); |
| 905 return DefineProxyProperty(obj, p, attributes, should_throw); |
| 906 } else if (IS_ARRAY(obj)) { |
| 907 return DefineArrayProperty(obj, p, desc, should_throw); |
| 908 } else { |
| 909 return DefineObjectProperty(obj, p, desc, should_throw); |
| 910 } |
| 911 } |
| 912 |
| 913 |
862 // ES5 section 15.2.3.2. | 914 // ES5 section 15.2.3.2. |
863 function ObjectGetPrototypeOf(obj) { | 915 function ObjectGetPrototypeOf(obj) { |
864 if (!IS_SPEC_OBJECT(obj)) | 916 if (!IS_SPEC_OBJECT(obj)) |
865 throw MakeTypeError("obj_ctor_property_non_object", ["getPrototypeOf"]); | 917 throw MakeTypeError("obj_ctor_property_non_object", ["getPrototypeOf"]); |
866 return %GetPrototype(obj); | 918 return %GetPrototype(obj); |
867 } | 919 } |
868 | 920 |
869 | 921 |
870 // ES5 section 15.2.3.3 | 922 // ES5 section 15.2.3.3 |
871 function ObjectGetOwnPropertyDescriptor(obj, p) { | 923 function ObjectGetOwnPropertyDescriptor(obj, p) { |
(...skipping 690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1562 | 1614 |
1563 function SetUpFunction() { | 1615 function SetUpFunction() { |
1564 %CheckIsBootstrapping(); | 1616 %CheckIsBootstrapping(); |
1565 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1617 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
1566 "bind", FunctionBind, | 1618 "bind", FunctionBind, |
1567 "toString", FunctionToString | 1619 "toString", FunctionToString |
1568 )); | 1620 )); |
1569 } | 1621 } |
1570 | 1622 |
1571 SetUpFunction(); | 1623 SetUpFunction(); |
OLD | NEW |