Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 1136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1147 {value: obj, writable: true, enumerable: false, configurable: true}); | 1147 {value: obj, writable: true, enumerable: false, configurable: true}); |
| 1148 // TODO(v8:1530): defineProperty does not handle prototype and length. | 1148 // TODO(v8:1530): defineProperty does not handle prototype and length. |
| 1149 %FunctionSetPrototype(obj, prototype); | 1149 %FunctionSetPrototype(obj, prototype); |
| 1150 obj.length = 0; | 1150 obj.length = 0; |
| 1151 } else { | 1151 } else { |
| 1152 %Fix(obj); | 1152 %Fix(obj); |
| 1153 } | 1153 } |
| 1154 ObjectDefineProperties(obj, props); | 1154 ObjectDefineProperties(obj, props); |
| 1155 } | 1155 } |
| 1156 | 1156 |
| 1157 function GetOwnPropertyNamesForSealOrFreeze(obj) { | |
| 1158 var names = ObjectGetOwnPropertyNames(obj); | |
| 1159 if (IS_SPEC_FUNCTION(obj)) { | |
|
rossberg
2012/11/16 12:28:55
IS_FUNCTION probably is more adequate here, since
arv (Not doing code reviews)
2012/11/16 14:38:06
There are more poison pills than functionObj.calle
rossberg
2012/11/16 15:52:46
Yes, but this issue affects only "caller", because
| |
| 1160 // The "caller" property on Functions is always non-writable and | |
| 1161 // non-configurable, so there's no need to check it or redefine it. | |
| 1162 // Thus, we skip it to avoid the strict-mode check the getter enforces. | |
| 1163 names = names.filter(function(name) { return name != "caller"; }); | |
| 1164 } | |
| 1165 return names; | |
| 1166 } | |
| 1167 | |
| 1157 | 1168 |
| 1158 // ES5 section 15.2.3.8. | 1169 // ES5 section 15.2.3.8. |
| 1159 function ObjectSeal(obj) { | 1170 function ObjectSeal(obj) { |
| 1160 if (!IS_SPEC_OBJECT(obj)) { | 1171 if (!IS_SPEC_OBJECT(obj)) { |
| 1161 throw MakeTypeError("called_on_non_object", ["Object.seal"]); | 1172 throw MakeTypeError("called_on_non_object", ["Object.seal"]); |
| 1162 } | 1173 } |
| 1163 if (%IsJSProxy(obj)) { | 1174 if (%IsJSProxy(obj)) { |
| 1164 ProxyFix(obj); | 1175 ProxyFix(obj); |
| 1165 } | 1176 } |
| 1166 var names = ObjectGetOwnPropertyNames(obj); | 1177 var names = GetOwnPropertyNamesForSealOrFreeze(obj); |
| 1167 for (var i = 0; i < names.length; i++) { | 1178 for (var i = 0; i < names.length; i++) { |
| 1168 var name = names[i]; | 1179 var name = names[i]; |
| 1169 var desc = GetOwnProperty(obj, name); | 1180 var desc = GetOwnProperty(obj, name); |
| 1170 if (desc.isConfigurable()) { | 1181 if (desc.isConfigurable()) { |
| 1171 desc.setConfigurable(false); | 1182 desc.setConfigurable(false); |
| 1172 DefineOwnProperty(obj, name, desc, true); | 1183 DefineOwnProperty(obj, name, desc, true); |
| 1173 } | 1184 } |
| 1174 } | 1185 } |
| 1175 %PreventExtensions(obj); | 1186 %PreventExtensions(obj); |
| 1176 return obj; | 1187 return obj; |
| 1177 } | 1188 } |
| 1178 | 1189 |
| 1179 | 1190 |
| 1180 // ES5 section 15.2.3.9. | 1191 // ES5 section 15.2.3.9. |
| 1181 function ObjectFreeze(obj) { | 1192 function ObjectFreeze(obj) { |
| 1182 if (!IS_SPEC_OBJECT(obj)) { | 1193 if (!IS_SPEC_OBJECT(obj)) { |
| 1183 throw MakeTypeError("called_on_non_object", ["Object.freeze"]); | 1194 throw MakeTypeError("called_on_non_object", ["Object.freeze"]); |
| 1184 } | 1195 } |
| 1185 if (%IsJSProxy(obj)) { | 1196 if (%IsJSProxy(obj)) { |
| 1186 ProxyFix(obj); | 1197 ProxyFix(obj); |
| 1187 } | 1198 } |
| 1188 var names = ObjectGetOwnPropertyNames(obj); | 1199 var names = GetOwnPropertyNamesForSealOrFreeze(obj); |
| 1189 for (var i = 0; i < names.length; i++) { | 1200 for (var i = 0; i < names.length; i++) { |
| 1190 var name = names[i]; | 1201 var name = names[i]; |
| 1191 var desc = GetOwnProperty(obj, name); | 1202 var desc = GetOwnProperty(obj, name); |
| 1192 if (desc.isWritable() || desc.isConfigurable()) { | 1203 if (desc.isWritable() || desc.isConfigurable()) { |
| 1193 if (IsDataDescriptor(desc)) desc.setWritable(false); | 1204 if (IsDataDescriptor(desc)) desc.setWritable(false); |
| 1194 desc.setConfigurable(false); | 1205 desc.setConfigurable(false); |
| 1195 DefineOwnProperty(obj, name, desc, true); | 1206 DefineOwnProperty(obj, name, desc, true); |
| 1196 } | 1207 } |
| 1197 } | 1208 } |
| 1198 %PreventExtensions(obj); | 1209 %PreventExtensions(obj); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1214 | 1225 |
| 1215 | 1226 |
| 1216 // ES5 section 15.2.3.11 | 1227 // ES5 section 15.2.3.11 |
| 1217 function ObjectIsSealed(obj) { | 1228 function ObjectIsSealed(obj) { |
| 1218 if (!IS_SPEC_OBJECT(obj)) { | 1229 if (!IS_SPEC_OBJECT(obj)) { |
| 1219 throw MakeTypeError("called_on_non_object", ["Object.isSealed"]); | 1230 throw MakeTypeError("called_on_non_object", ["Object.isSealed"]); |
| 1220 } | 1231 } |
| 1221 if (%IsJSProxy(obj)) { | 1232 if (%IsJSProxy(obj)) { |
| 1222 return false; | 1233 return false; |
| 1223 } | 1234 } |
| 1224 var names = ObjectGetOwnPropertyNames(obj); | 1235 var names = GetOwnPropertyNamesForSealOrFreeze(obj); |
| 1225 for (var i = 0; i < names.length; i++) { | 1236 for (var i = 0; i < names.length; i++) { |
| 1226 var name = names[i]; | 1237 var name = names[i]; |
| 1227 var desc = GetOwnProperty(obj, name); | 1238 var desc = GetOwnProperty(obj, name); |
| 1228 if (desc.isConfigurable()) return false; | 1239 if (desc.isConfigurable()) return false; |
| 1229 } | 1240 } |
| 1230 if (!ObjectIsExtensible(obj)) { | 1241 if (!ObjectIsExtensible(obj)) { |
| 1231 return true; | 1242 return true; |
| 1232 } | 1243 } |
| 1233 return false; | 1244 return false; |
| 1234 } | 1245 } |
| 1235 | 1246 |
| 1236 | 1247 |
| 1237 // ES5 section 15.2.3.12 | 1248 // ES5 section 15.2.3.12 |
| 1238 function ObjectIsFrozen(obj) { | 1249 function ObjectIsFrozen(obj) { |
| 1239 if (!IS_SPEC_OBJECT(obj)) { | 1250 if (!IS_SPEC_OBJECT(obj)) { |
| 1240 throw MakeTypeError("called_on_non_object", ["Object.isFrozen"]); | 1251 throw MakeTypeError("called_on_non_object", ["Object.isFrozen"]); |
| 1241 } | 1252 } |
| 1242 if (%IsJSProxy(obj)) { | 1253 if (%IsJSProxy(obj)) { |
| 1243 return false; | 1254 return false; |
| 1244 } | 1255 } |
| 1245 var names = ObjectGetOwnPropertyNames(obj); | 1256 var names = GetOwnPropertyNamesForSealOrFreeze(obj); |
| 1246 for (var i = 0; i < names.length; i++) { | 1257 for (var i = 0; i < names.length; i++) { |
| 1247 var name = names[i]; | 1258 var name = names[i]; |
| 1248 var desc = GetOwnProperty(obj, name); | 1259 var desc = GetOwnProperty(obj, name); |
| 1249 if (IsDataDescriptor(desc) && desc.isWritable()) return false; | 1260 if (IsDataDescriptor(desc) && desc.isWritable()) return false; |
| 1250 if (desc.isConfigurable()) return false; | 1261 if (desc.isConfigurable()) return false; |
| 1251 } | 1262 } |
| 1252 if (!ObjectIsExtensible(obj)) { | 1263 if (!ObjectIsExtensible(obj)) { |
| 1253 return true; | 1264 return true; |
| 1254 } | 1265 } |
| 1255 return false; | 1266 return false; |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1677 | 1688 |
| 1678 function SetUpFunction() { | 1689 function SetUpFunction() { |
| 1679 %CheckIsBootstrapping(); | 1690 %CheckIsBootstrapping(); |
| 1680 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1691 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
| 1681 "bind", FunctionBind, | 1692 "bind", FunctionBind, |
| 1682 "toString", FunctionToString | 1693 "toString", FunctionToString |
| 1683 )); | 1694 )); |
| 1684 } | 1695 } |
| 1685 | 1696 |
| 1686 SetUpFunction(); | 1697 SetUpFunction(); |
| OLD | NEW |