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

Side by Side Diff: src/v8natives.js

Issue 7391001: Implement sealing, freezing, and related functions for proxies. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressing Mads' comments, plus bug fix. Created 9 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
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 645 matching lines...) Expand 10 before | Expand all | Expand 10 after
656 // Harmony proxies. 656 // Harmony proxies.
657 function DefineProxyProperty(obj, p, attributes, should_throw) { 657 function DefineProxyProperty(obj, p, attributes, should_throw) {
658 var handler = %GetHandler(obj); 658 var handler = %GetHandler(obj);
659 var defineProperty = handler.defineProperty; 659 var defineProperty = handler.defineProperty;
660 if (IS_UNDEFINED(defineProperty)) { 660 if (IS_UNDEFINED(defineProperty)) {
661 throw MakeTypeError("handler_trap_missing", [handler, "defineProperty"]); 661 throw MakeTypeError("handler_trap_missing", [handler, "defineProperty"]);
662 } 662 }
663 var result = %_CallFunction(handler, p, attributes, defineProperty); 663 var result = %_CallFunction(handler, p, attributes, defineProperty);
664 if (!ToBoolean(result)) { 664 if (!ToBoolean(result)) {
665 if (should_throw) { 665 if (should_throw) {
666 throw MakeTypeError("handler_failed", [handler, "defineProperty"]); 666 throw MakeTypeError("handler_returned_false",
667 [handler, "defineProperty"]);
667 } else { 668 } else {
668 return false; 669 return false;
669 } 670 }
670 } 671 }
671 return true; 672 return true;
672 } 673 }
673 674
674 675
675 // ES5 8.12.9. 676 // ES5 8.12.9.
676 function DefineOwnProperty(obj, p, desc, should_throw) { 677 function DefineOwnProperty(obj, p, desc, should_throw) {
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 } 1014 }
1014 for (var i = 0; i < key_values.length; i += 2) { 1015 for (var i = 0; i < key_values.length; i += 2) {
1015 var key = key_values[i]; 1016 var key = key_values[i];
1016 var desc = key_values[i + 1]; 1017 var desc = key_values[i + 1];
1017 DefineOwnProperty(obj, key, desc, true); 1018 DefineOwnProperty(obj, key, desc, true);
1018 } 1019 }
1019 return obj; 1020 return obj;
1020 } 1021 }
1021 1022
1022 1023
1024 // Harmony proxies.
1025 function ProxyFix(obj) {
1026 var handler = %GetHandler(obj);
1027 var fix = handler.fix;
1028 if (IS_UNDEFINED(fix)) {
1029 throw MakeTypeError("handler_trap_missing", [handler, "fix"]);
1030 }
1031 var props = %_CallFunction(handler, fix);
1032 if (IS_UNDEFINED(props)) {
1033 throw MakeTypeError("handler_returned_undefined", [handler, "fix"]);
1034 }
1035 %Fix(obj);
1036 ObjectDefineProperties(obj, props);
1037 }
1038
1039
1023 // ES5 section 15.2.3.8. 1040 // ES5 section 15.2.3.8.
1024 function ObjectSeal(obj) { 1041 function ObjectSeal(obj) {
1025 if (!IS_SPEC_OBJECT(obj)) { 1042 if (!IS_SPEC_OBJECT(obj)) {
1026 throw MakeTypeError("obj_ctor_property_non_object", ["seal"]); 1043 throw MakeTypeError("obj_ctor_property_non_object", ["seal"]);
1027 } 1044 }
1045 if (%IsJSProxy(obj)) {
1046 ProxyFix(obj);
1047 }
1028 var names = ObjectGetOwnPropertyNames(obj); 1048 var names = ObjectGetOwnPropertyNames(obj);
1029 for (var i = 0; i < names.length; i++) { 1049 for (var i = 0; i < names.length; i++) {
1030 var name = names[i]; 1050 var name = names[i];
1031 var desc = GetOwnProperty(obj, name); 1051 var desc = GetOwnProperty(obj, name);
1032 if (desc.isConfigurable()) { 1052 if (desc.isConfigurable()) {
1033 desc.setConfigurable(false); 1053 desc.setConfigurable(false);
1034 DefineOwnProperty(obj, name, desc, true); 1054 DefineOwnProperty(obj, name, desc, true);
1035 } 1055 }
1036 } 1056 }
1037 return ObjectPreventExtension(obj); 1057 %PreventExtensions(obj);
1058 return obj;
1038 } 1059 }
1039 1060
1040 1061
1041 // ES5 section 15.2.3.9. 1062 // ES5 section 15.2.3.9.
1042 function ObjectFreeze(obj) { 1063 function ObjectFreeze(obj) {
1043 if (!IS_SPEC_OBJECT(obj)) { 1064 if (!IS_SPEC_OBJECT(obj)) {
1044 throw MakeTypeError("obj_ctor_property_non_object", ["freeze"]); 1065 throw MakeTypeError("obj_ctor_property_non_object", ["freeze"]);
1045 } 1066 }
1067 if (%IsJSProxy(obj)) {
1068 ProxyFix(obj);
1069 }
1046 var names = ObjectGetOwnPropertyNames(obj); 1070 var names = ObjectGetOwnPropertyNames(obj);
1047 for (var i = 0; i < names.length; i++) { 1071 for (var i = 0; i < names.length; i++) {
1048 var name = names[i]; 1072 var name = names[i];
1049 var desc = GetOwnProperty(obj, name); 1073 var desc = GetOwnProperty(obj, name);
1050 if (desc.isWritable() || desc.isConfigurable()) { 1074 if (desc.isWritable() || desc.isConfigurable()) {
1051 if (IsDataDescriptor(desc)) desc.setWritable(false); 1075 if (IsDataDescriptor(desc)) desc.setWritable(false);
1052 desc.setConfigurable(false); 1076 desc.setConfigurable(false);
1053 DefineOwnProperty(obj, name, desc, true); 1077 DefineOwnProperty(obj, name, desc, true);
1054 } 1078 }
1055 } 1079 }
1056 return ObjectPreventExtension(obj); 1080 %PreventExtensions(obj);
1081 return obj;
1057 } 1082 }
1058 1083
1059 1084
1060 // ES5 section 15.2.3.10 1085 // ES5 section 15.2.3.10
1061 function ObjectPreventExtension(obj) { 1086 function ObjectPreventExtension(obj) {
1062 if (!IS_SPEC_OBJECT(obj)) { 1087 if (!IS_SPEC_OBJECT(obj)) {
1063 throw MakeTypeError("obj_ctor_property_non_object", ["preventExtension"]); 1088 throw MakeTypeError("obj_ctor_property_non_object", ["preventExtension"]);
1064 } 1089 }
1090 if (%IsJSProxy(obj)) {
1091 ProxyFix(obj);
1092 }
1065 %PreventExtensions(obj); 1093 %PreventExtensions(obj);
1066 return obj; 1094 return obj;
1067 } 1095 }
1068 1096
1069 1097
1070 // ES5 section 15.2.3.11 1098 // ES5 section 15.2.3.11
1071 function ObjectIsSealed(obj) { 1099 function ObjectIsSealed(obj) {
1072 if (!IS_SPEC_OBJECT(obj)) { 1100 if (!IS_SPEC_OBJECT(obj)) {
1073 throw MakeTypeError("obj_ctor_property_non_object", ["isSealed"]); 1101 throw MakeTypeError("obj_ctor_property_non_object", ["isSealed"]);
1074 } 1102 }
1103 if (%IsJSProxy(obj)) {
1104 return false;
1105 }
1075 var names = ObjectGetOwnPropertyNames(obj); 1106 var names = ObjectGetOwnPropertyNames(obj);
1076 for (var i = 0; i < names.length; i++) { 1107 for (var i = 0; i < names.length; i++) {
1077 var name = names[i]; 1108 var name = names[i];
1078 var desc = GetOwnProperty(obj, name); 1109 var desc = GetOwnProperty(obj, name);
1079 if (desc.isConfigurable()) return false; 1110 if (desc.isConfigurable()) return false;
1080 } 1111 }
1081 if (!ObjectIsExtensible(obj)) { 1112 if (!ObjectIsExtensible(obj)) {
1082 return true; 1113 return true;
1083 } 1114 }
1084 return false; 1115 return false;
1085 } 1116 }
1086 1117
1087 1118
1088 // ES5 section 15.2.3.12 1119 // ES5 section 15.2.3.12
1089 function ObjectIsFrozen(obj) { 1120 function ObjectIsFrozen(obj) {
1090 if (!IS_SPEC_OBJECT(obj)) { 1121 if (!IS_SPEC_OBJECT(obj)) {
1091 throw MakeTypeError("obj_ctor_property_non_object", ["isFrozen"]); 1122 throw MakeTypeError("obj_ctor_property_non_object", ["isFrozen"]);
1092 } 1123 }
1124 if (%IsJSProxy(obj)) {
1125 return false;
1126 }
1093 var names = ObjectGetOwnPropertyNames(obj); 1127 var names = ObjectGetOwnPropertyNames(obj);
1094 for (var i = 0; i < names.length; i++) { 1128 for (var i = 0; i < names.length; i++) {
1095 var name = names[i]; 1129 var name = names[i];
1096 var desc = GetOwnProperty(obj, name); 1130 var desc = GetOwnProperty(obj, name);
1097 if (IsDataDescriptor(desc) && desc.isWritable()) return false; 1131 if (IsDataDescriptor(desc) && desc.isWritable()) return false;
1098 if (desc.isConfigurable()) return false; 1132 if (desc.isConfigurable()) return false;
1099 } 1133 }
1100 if (!ObjectIsExtensible(obj)) { 1134 if (!ObjectIsExtensible(obj)) {
1101 return true; 1135 return true;
1102 } 1136 }
1103 return false; 1137 return false;
1104 } 1138 }
1105 1139
1106 1140
1107 // ES5 section 15.2.3.13 1141 // ES5 section 15.2.3.13
1108 function ObjectIsExtensible(obj) { 1142 function ObjectIsExtensible(obj) {
1109 if (!IS_SPEC_OBJECT(obj)) { 1143 if (!IS_SPEC_OBJECT(obj)) {
1110 throw MakeTypeError("obj_ctor_property_non_object", ["isExtensible"]); 1144 throw MakeTypeError("obj_ctor_property_non_object", ["isExtensible"]);
1111 } 1145 }
1146 if (%IsJSProxy(obj)) {
1147 return true;
1148 }
1112 return %IsExtensible(obj); 1149 return %IsExtensible(obj);
1113 } 1150 }
1114 1151
1115 1152
1116 %SetCode($Object, function(x) { 1153 %SetCode($Object, function(x) {
1117 if (%_IsConstructCall()) { 1154 if (%_IsConstructCall()) {
1118 if (x == null) return this; 1155 if (x == null) return this;
1119 return ToObject(x); 1156 return ToObject(x);
1120 } else { 1157 } else {
1121 if (x == null) return { }; 1158 if (x == null) return { };
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after
1482 // ---------------------------------------------------------------------------- 1519 // ----------------------------------------------------------------------------
1483 1520
1484 function SetupFunction() { 1521 function SetupFunction() {
1485 InstallFunctions($Function.prototype, DONT_ENUM, $Array( 1522 InstallFunctions($Function.prototype, DONT_ENUM, $Array(
1486 "bind", FunctionBind, 1523 "bind", FunctionBind,
1487 "toString", FunctionToString 1524 "toString", FunctionToString
1488 )); 1525 ));
1489 } 1526 }
1490 1527
1491 SetupFunction(); 1528 SetupFunction();
OLDNEW
« src/runtime.cc ('K') | « src/runtime.cc ('k') | test/mjsunit/harmony/proxies.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698