Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: src/v8natives.js

Issue 2944016: Add ES5 Object.freeze and Object.isFrozen methods.... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | test/es5conform/es5conform.status » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 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 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 } 716 }
717 var name = ToString(p); 717 var name = ToString(p);
718 var desc = ToPropertyDescriptor(attributes); 718 var desc = ToPropertyDescriptor(attributes);
719 DefineOwnProperty(obj, name, desc, true); 719 DefineOwnProperty(obj, name, desc, true);
720 return obj; 720 return obj;
721 } 721 }
722 722
723 723
724 // ES5 section 15.2.3.7. 724 // ES5 section 15.2.3.7.
725 function ObjectDefineProperties(obj, properties) { 725 function ObjectDefineProperties(obj, properties) {
726 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && 726 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) &&
727 !IS_UNDETECTABLE(obj)) 727 !IS_UNDETECTABLE(obj))
728 throw MakeTypeError("obj_ctor_property_non_object", ["defineProperties"]); 728 throw MakeTypeError("obj_ctor_property_non_object", ["defineProperties"]);
729 var props = ToObject(properties); 729 var props = ToObject(properties);
730 var key_values = []; 730 var key_values = [];
731 for (var key in props) { 731 for (var key in props) {
732 if (%HasLocalProperty(props, key)) { 732 if (%HasLocalProperty(props, key)) {
733 key_values.push(key); 733 key_values.push(key);
734 var value = props[key]; 734 var value = props[key];
735 var desc = ToPropertyDescriptor(value); 735 var desc = ToPropertyDescriptor(value);
736 key_values.push(desc); 736 key_values.push(desc);
737 } 737 }
738 } 738 }
739 for (var i = 0; i < key_values.length; i += 2) { 739 for (var i = 0; i < key_values.length; i += 2) {
740 var key = key_values[i]; 740 var key = key_values[i];
741 var desc = key_values[i + 1]; 741 var desc = key_values[i + 1];
742 DefineOwnProperty(obj, key, desc, true); 742 DefineOwnProperty(obj, key, desc, true);
743 } 743 }
744 return obj; 744 return obj;
745 } 745 }
746 746
747 747
748 // ES5 section 15.2.3.9.
749 function ObjectFreeze(obj) {
750 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) &&
751 !IS_UNDETECTABLE(obj)) {
752 throw MakeTypeError("obj_ctor_property_non_object", ["freeze"]);
753 }
754 var names = ObjectGetOwnPropertyNames(obj);
755 for (var key in names) {
756 var name = names[key];
757 var desc = GetOwnProperty(obj, name);
758 if (IsDataDescriptor(desc)) desc.setWritable(false);
759 if (desc.isConfigurable()) desc.setConfigurable(false);
760 DefineOwnProperty(obj, name, desc, true);
761 }
762 ObjectPreventExtension(obj);
763 }
764
765
748 // ES5 section 15.2.3.10 766 // ES5 section 15.2.3.10
749 function ObjectPreventExtension(obj) { 767 function ObjectPreventExtension(obj) {
750 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && 768 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) &&
751 !IS_UNDETECTABLE(obj)) { 769 !IS_UNDETECTABLE(obj)) {
752 throw MakeTypeError("obj_ctor_property_non_object", ["preventExtension"]); 770 throw MakeTypeError("obj_ctor_property_non_object", ["preventExtension"]);
753 } 771 }
754 %PreventExtensions(obj); 772 %PreventExtensions(obj);
755 return obj; 773 return obj;
756 } 774 }
757 775
758 776
777 // ES5 section 15.2.3.12
778 function ObjectIsFrozen(obj) {
779 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) &&
780 !IS_UNDETECTABLE(obj)) {
781 throw MakeTypeError("obj_ctor_property_non_object", ["isFrozen"]);
782 }
783 var names = ObjectGetOwnPropertyNames(obj);
784 for (var key in names) {
785 var name = names[key];
786 var desc = GetOwnProperty(obj, name);
787 if (IsDataDescriptor(desc) && desc.writable) return false;
788 if (desc.configurable) return false;
789 }
790 if (!ObjectIsExtensible(obj)) {
791 return true;
792 }
793 return false;
794 }
795
796
759 // ES5 section 15.2.3.13 797 // ES5 section 15.2.3.13
760 function ObjectIsExtensible(obj) { 798 function ObjectIsExtensible(obj) {
761 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) && 799 if ((!IS_SPEC_OBJECT_OR_NULL(obj) || IS_NULL_OR_UNDEFINED(obj)) &&
762 !IS_UNDETECTABLE(obj)) { 800 !IS_UNDETECTABLE(obj)) {
763 throw MakeTypeError("obj_ctor_property_non_object", ["preventExtension"]); 801 throw MakeTypeError("obj_ctor_property_non_object", ["preventExtension"]);
764 } 802 }
765 return %IsExtensible(obj); 803 return %IsExtensible(obj);
766 } 804 }
767 805
768 806
(...skipping 23 matching lines...) Expand all
792 "__defineGetter__", ObjectDefineGetter, 830 "__defineGetter__", ObjectDefineGetter,
793 "__lookupGetter__", ObjectLookupGetter, 831 "__lookupGetter__", ObjectLookupGetter,
794 "__defineSetter__", ObjectDefineSetter, 832 "__defineSetter__", ObjectDefineSetter,
795 "__lookupSetter__", ObjectLookupSetter 833 "__lookupSetter__", ObjectLookupSetter
796 )); 834 ));
797 InstallFunctions($Object, DONT_ENUM, $Array( 835 InstallFunctions($Object, DONT_ENUM, $Array(
798 "keys", ObjectKeys, 836 "keys", ObjectKeys,
799 "create", ObjectCreate, 837 "create", ObjectCreate,
800 "defineProperty", ObjectDefineProperty, 838 "defineProperty", ObjectDefineProperty,
801 "defineProperties", ObjectDefineProperties, 839 "defineProperties", ObjectDefineProperties,
840 "freeze", ObjectFreeze,
802 "getPrototypeOf", ObjectGetPrototypeOf, 841 "getPrototypeOf", ObjectGetPrototypeOf,
803 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor, 842 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor,
804 "getOwnPropertyNames", ObjectGetOwnPropertyNames, 843 "getOwnPropertyNames", ObjectGetOwnPropertyNames,
805 "isExtensible", ObjectIsExtensible, 844 "isExtensible", ObjectIsExtensible,
845 "isFrozen", ObjectIsFrozen,
806 "preventExtensions", ObjectPreventExtension 846 "preventExtensions", ObjectPreventExtension
807 )); 847 ));
808 } 848 }
809 849
810 SetupObject(); 850 SetupObject();
811 851
812 852
813 // ---------------------------------------------------------------------------- 853 // ----------------------------------------------------------------------------
814 // Boolean 854 // Boolean
815 855
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
1064 1104
1065 // ---------------------------------------------------------------------------- 1105 // ----------------------------------------------------------------------------
1066 1106
1067 function SetupFunction() { 1107 function SetupFunction() {
1068 InstallFunctions($Function.prototype, DONT_ENUM, $Array( 1108 InstallFunctions($Function.prototype, DONT_ENUM, $Array(
1069 "toString", FunctionToString 1109 "toString", FunctionToString
1070 )); 1110 ));
1071 } 1111 }
1072 1112
1073 SetupFunction(); 1113 SetupFunction();
OLDNEW
« no previous file with comments | « no previous file | test/es5conform/es5conform.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698