| 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 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 | 697 |
| 698 var current = ConvertDescriptorArrayToDescriptor(current_or_access); | 698 var current = ConvertDescriptorArrayToDescriptor(current_or_access); |
| 699 var extensible = %IsExtensible(ToObject(obj)); | 699 var extensible = %IsExtensible(ToObject(obj)); |
| 700 | 700 |
| 701 // Error handling according to spec. | 701 // Error handling according to spec. |
| 702 // Step 3 | 702 // Step 3 |
| 703 if (IS_UNDEFINED(current) && !extensible) { | 703 if (IS_UNDEFINED(current) && !extensible) { |
| 704 if (should_throw) { | 704 if (should_throw) { |
| 705 throw MakeTypeError("define_disallowed", [p]); | 705 throw MakeTypeError("define_disallowed", [p]); |
| 706 } else { | 706 } else { |
| 707 return; | 707 return false; |
| 708 } | 708 } |
| 709 } | 709 } |
| 710 | 710 |
| 711 if (!IS_UNDEFINED(current)) { | 711 if (!IS_UNDEFINED(current)) { |
| 712 // Step 5 and 6 | 712 // Step 5 and 6 |
| 713 if ((IsGenericDescriptor(desc) || | 713 if ((IsGenericDescriptor(desc) || |
| 714 IsDataDescriptor(desc) == IsDataDescriptor(current)) && | 714 IsDataDescriptor(desc) == IsDataDescriptor(current)) && |
| 715 (!desc.hasEnumerable() || | 715 (!desc.hasEnumerable() || |
| 716 SameValue(desc.isEnumerable(), current.isEnumerable())) && | 716 SameValue(desc.isEnumerable(), current.isEnumerable())) && |
| 717 (!desc.hasConfigurable() || | 717 (!desc.hasConfigurable() || |
| 718 SameValue(desc.isConfigurable(), current.isConfigurable())) && | 718 SameValue(desc.isConfigurable(), current.isConfigurable())) && |
| 719 (!desc.hasWritable() || | 719 (!desc.hasWritable() || |
| 720 SameValue(desc.isWritable(), current.isWritable())) && | 720 SameValue(desc.isWritable(), current.isWritable())) && |
| 721 (!desc.hasValue() || | 721 (!desc.hasValue() || |
| 722 SameValue(desc.getValue(), current.getValue())) && | 722 SameValue(desc.getValue(), current.getValue())) && |
| 723 (!desc.hasGetter() || | 723 (!desc.hasGetter() || |
| 724 SameValue(desc.getGet(), current.getGet())) && | 724 SameValue(desc.getGet(), current.getGet())) && |
| 725 (!desc.hasSetter() || | 725 (!desc.hasSetter() || |
| 726 SameValue(desc.getSet(), current.getSet()))) { | 726 SameValue(desc.getSet(), current.getSet()))) { |
| 727 return true; | 727 return true; |
| 728 } | 728 } |
| 729 if (!current.isConfigurable()) { | 729 if (!current.isConfigurable()) { |
| 730 // Step 7 | 730 // Step 7 |
| 731 if (desc.isConfigurable() || | 731 if (desc.isConfigurable() || |
| 732 (desc.hasEnumerable() && | 732 (desc.hasEnumerable() && |
| 733 desc.isEnumerable() != current.isEnumerable())) { | 733 desc.isEnumerable() != current.isEnumerable())) { |
| 734 if (should_throw) { | 734 if (should_throw) { |
| 735 throw MakeTypeError("redefine_disallowed", [p]); | 735 throw MakeTypeError("redefine_disallowed", [p]); |
| 736 } else { | 736 } else { |
| 737 return; | 737 return false; |
| 738 } | 738 } |
| 739 } | 739 } |
| 740 // Step 8 | 740 // Step 8 |
| 741 if (!IsGenericDescriptor(desc)) { | 741 if (!IsGenericDescriptor(desc)) { |
| 742 // Step 9a | 742 // Step 9a |
| 743 if (IsDataDescriptor(current) != IsDataDescriptor(desc)) { | 743 if (IsDataDescriptor(current) != IsDataDescriptor(desc)) { |
| 744 if (should_throw) { | 744 if (should_throw) { |
| 745 throw MakeTypeError("redefine_disallowed", [p]); | 745 throw MakeTypeError("redefine_disallowed", [p]); |
| 746 } else { | 746 } else { |
| 747 return; | 747 return false; |
| 748 } | 748 } |
| 749 } | 749 } |
| 750 // Step 10a | 750 // Step 10a |
| 751 if (IsDataDescriptor(current) && IsDataDescriptor(desc)) { | 751 if (IsDataDescriptor(current) && IsDataDescriptor(desc)) { |
| 752 if (!current.isWritable() && desc.isWritable()) { | 752 if (!current.isWritable() && desc.isWritable()) { |
| 753 if (should_throw) { | 753 if (should_throw) { |
| 754 throw MakeTypeError("redefine_disallowed", [p]); | 754 throw MakeTypeError("redefine_disallowed", [p]); |
| 755 } else { | 755 } else { |
| 756 return; | 756 return false; |
| 757 } | 757 } |
| 758 } | 758 } |
| 759 if (!current.isWritable() && desc.hasValue() && | 759 if (!current.isWritable() && desc.hasValue() && |
| 760 !SameValue(desc.getValue(), current.getValue())) { | 760 !SameValue(desc.getValue(), current.getValue())) { |
| 761 if (should_throw) { | 761 if (should_throw) { |
| 762 throw MakeTypeError("redefine_disallowed", [p]); | 762 throw MakeTypeError("redefine_disallowed", [p]); |
| 763 } else { | 763 } else { |
| 764 return; | 764 return false; |
| 765 } | 765 } |
| 766 } | 766 } |
| 767 } | 767 } |
| 768 // Step 11 | 768 // Step 11 |
| 769 if (IsAccessorDescriptor(desc) && IsAccessorDescriptor(current)) { | 769 if (IsAccessorDescriptor(desc) && IsAccessorDescriptor(current)) { |
| 770 if (desc.hasSetter() && !SameValue(desc.getSet(), current.getSet())) { | 770 if (desc.hasSetter() && !SameValue(desc.getSet(), current.getSet())) { |
| 771 if (should_throw) { | 771 if (should_throw) { |
| 772 throw MakeTypeError("redefine_disallowed", [p]); | 772 throw MakeTypeError("redefine_disallowed", [p]); |
| 773 } else { | 773 } else { |
| 774 return; | 774 return false; |
| 775 } | 775 } |
| 776 } | 776 } |
| 777 if (desc.hasGetter() && !SameValue(desc.getGet(),current.getGet())) { | 777 if (desc.hasGetter() && !SameValue(desc.getGet(),current.getGet())) { |
| 778 if (should_throw) { | 778 if (should_throw) { |
| 779 throw MakeTypeError("redefine_disallowed", [p]); | 779 throw MakeTypeError("redefine_disallowed", [p]); |
| 780 } else { | 780 } else { |
| 781 return; | 781 return false; |
| 782 } | 782 } |
| 783 } | 783 } |
| 784 } | 784 } |
| 785 } | 785 } |
| 786 } | 786 } |
| 787 } | 787 } |
| 788 | 788 |
| 789 // Send flags - enumerable and configurable are common - writable is | 789 // Send flags - enumerable and configurable are common - writable is |
| 790 // only send to the data descriptor. | 790 // only send to the data descriptor. |
| 791 // Take special care if enumerable and configurable is not defined on | 791 // Take special care if enumerable and configurable is not defined on |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 } | 874 } |
| 875 | 875 |
| 876 // Step 4 - Special handling for array index. | 876 // Step 4 - Special handling for array index. |
| 877 var index = ToUint32(p); | 877 var index = ToUint32(p); |
| 878 if (index == ToNumber(p) && index != 4294967295) { | 878 if (index == ToNumber(p) && index != 4294967295) { |
| 879 if ((index >= length && !length_desc.isWritable()) || | 879 if ((index >= length && !length_desc.isWritable()) || |
| 880 !DefineObjectProperty(obj, p, desc, true)) { | 880 !DefineObjectProperty(obj, p, desc, true)) { |
| 881 if (should_throw) { | 881 if (should_throw) { |
| 882 throw MakeTypeError("define_disallowed", [p]); | 882 throw MakeTypeError("define_disallowed", [p]); |
| 883 } else { | 883 } else { |
| 884 return; | 884 return false; |
| 885 } | 885 } |
| 886 } | 886 } |
| 887 if (index >= length) { | 887 if (index >= length) { |
| 888 // TODO(mstarzinger): We should actually set the value of the property | 888 // TODO(mstarzinger): We should actually set the value of the property |
| 889 // descriptor here and pass it to DefineObjectProperty(). Take a look at | 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. | 890 // ES5 section 15.4.5.1, step 4.e.i and 4.e.ii for details. |
| 891 obj.length = index + 1; | 891 obj.length = index + 1; |
| 892 } | 892 } |
| 893 return true; | 893 return true; |
| 894 } | 894 } |
| (...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1606 | 1606 |
| 1607 function SetUpFunction() { | 1607 function SetUpFunction() { |
| 1608 %CheckIsBootstrapping(); | 1608 %CheckIsBootstrapping(); |
| 1609 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1609 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
| 1610 "bind", FunctionBind, | 1610 "bind", FunctionBind, |
| 1611 "toString", FunctionToString | 1611 "toString", FunctionToString |
| 1612 )); | 1612 )); |
| 1613 } | 1613 } |
| 1614 | 1614 |
| 1615 SetUpFunction(); | 1615 SetUpFunction(); |
| OLD | NEW |