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