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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 var receiver = this; | 325 var receiver = this; |
326 if (receiver == null && !IS_UNDETECTABLE(receiver)) { | 326 if (receiver == null && !IS_UNDETECTABLE(receiver)) { |
327 receiver = %GlobalReceiver(global); | 327 receiver = %GlobalReceiver(global); |
328 } | 328 } |
329 return %LookupAccessor(ToObject(receiver), ToString(name), SETTER); | 329 return %LookupAccessor(ToObject(receiver), ToString(name), SETTER); |
330 } | 330 } |
331 | 331 |
332 | 332 |
333 function ObjectKeys(obj) { | 333 function ObjectKeys(obj) { |
334 if (!IS_SPEC_OBJECT(obj)) { | 334 if (!IS_SPEC_OBJECT(obj)) { |
335 throw MakeTypeError("obj_ctor_property_non_object", ["keys"]); | 335 throw MakeTypeError("called_on_non_object", ["Object.keys"]); |
336 } | 336 } |
337 if (%IsJSProxy(obj)) { | 337 if (%IsJSProxy(obj)) { |
338 var handler = %GetHandler(obj); | 338 var handler = %GetHandler(obj); |
339 var names = CallTrap0(handler, "keys", DerivedKeysTrap); | 339 var names = CallTrap0(handler, "keys", DerivedKeysTrap); |
340 return ToStringArray(names); | 340 return ToStringArray(names); |
341 } | 341 } |
342 return %LocalKeys(obj); | 342 return %LocalKeys(obj); |
343 } | 343 } |
344 | 344 |
345 | 345 |
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
936 return DefineArrayProperty(obj, p, desc, should_throw); | 936 return DefineArrayProperty(obj, p, desc, should_throw); |
937 } else { | 937 } else { |
938 return DefineObjectProperty(obj, p, desc, should_throw); | 938 return DefineObjectProperty(obj, p, desc, should_throw); |
939 } | 939 } |
940 } | 940 } |
941 | 941 |
942 | 942 |
943 // ES5 section 15.2.3.2. | 943 // ES5 section 15.2.3.2. |
944 function ObjectGetPrototypeOf(obj) { | 944 function ObjectGetPrototypeOf(obj) { |
945 if (!IS_SPEC_OBJECT(obj)) { | 945 if (!IS_SPEC_OBJECT(obj)) { |
946 throw MakeTypeError("obj_ctor_property_non_object", ["getPrototypeOf"]); | 946 throw MakeTypeError("called_on_non_object", ["Object.getPrototypeOf"]); |
947 } | 947 } |
948 return %GetPrototype(obj); | 948 return %GetPrototype(obj); |
949 } | 949 } |
950 | 950 |
951 | 951 |
952 // ES5 section 15.2.3.3 | 952 // ES5 section 15.2.3.3 |
953 function ObjectGetOwnPropertyDescriptor(obj, p) { | 953 function ObjectGetOwnPropertyDescriptor(obj, p) { |
954 if (!IS_SPEC_OBJECT(obj)) { | 954 if (!IS_SPEC_OBJECT(obj)) { |
955 throw MakeTypeError("obj_ctor_property_non_object", | 955 throw MakeTypeError("called_on_non_object", |
956 ["getOwnPropertyDescriptor"]); | 956 ["Object.getOwnPropertyDescriptor"]); |
957 } | 957 } |
958 var desc = GetOwnProperty(obj, p); | 958 var desc = GetOwnProperty(obj, p); |
959 return FromPropertyDescriptor(desc); | 959 return FromPropertyDescriptor(desc); |
960 } | 960 } |
961 | 961 |
962 | 962 |
963 // For Harmony proxies | 963 // For Harmony proxies |
964 function ToStringArray(obj, trap) { | 964 function ToStringArray(obj, trap) { |
965 if (!IS_SPEC_OBJECT(obj)) { | 965 if (!IS_SPEC_OBJECT(obj)) { |
966 throw MakeTypeError("proxy_non_object_prop_names", [obj, trap]); | 966 throw MakeTypeError("proxy_non_object_prop_names", [obj, trap]); |
967 } | 967 } |
968 var n = ToUint32(obj.length); | 968 var n = ToUint32(obj.length); |
969 var array = new $Array(n); | 969 var array = new $Array(n); |
970 var names = {}; // TODO(rossberg): use sets once they are ready. | 970 var names = {}; // TODO(rossberg): use sets once they are ready. |
971 for (var index = 0; index < n; index++) { | 971 for (var index = 0; index < n; index++) { |
972 var s = ToString(obj[index]); | 972 var s = ToString(obj[index]); |
973 if (s in names) { | 973 if (s in names) { |
974 throw MakeTypeError("proxy_repeated_prop_name", [obj, trap, s]); | 974 throw MakeTypeError("proxy_repeated_prop_name", [obj, trap, s]); |
975 } | 975 } |
976 array[index] = s; | 976 array[index] = s; |
977 names[s] = 0; | 977 names[s] = 0; |
978 } | 978 } |
979 return array; | 979 return array; |
980 } | 980 } |
981 | 981 |
982 | 982 |
983 // ES5 section 15.2.3.4. | 983 // ES5 section 15.2.3.4. |
984 function ObjectGetOwnPropertyNames(obj) { | 984 function ObjectGetOwnPropertyNames(obj) { |
985 if (!IS_SPEC_OBJECT(obj)) { | 985 if (!IS_SPEC_OBJECT(obj)) { |
986 throw MakeTypeError("obj_ctor_property_non_object", | 986 throw MakeTypeError("called_on_non_object", ["Object.getOwnPropertyNames"]); |
987 ["getOwnPropertyNames"]); | |
988 } | 987 } |
989 // Special handling for proxies. | 988 // Special handling for proxies. |
990 if (%IsJSProxy(obj)) { | 989 if (%IsJSProxy(obj)) { |
991 var handler = %GetHandler(obj); | 990 var handler = %GetHandler(obj); |
992 var names = CallTrap0(handler, "getOwnPropertyNames", void 0); | 991 var names = CallTrap0(handler, "getOwnPropertyNames", void 0); |
993 return ToStringArray(names, "getOwnPropertyNames"); | 992 return ToStringArray(names, "getOwnPropertyNames"); |
994 } | 993 } |
995 | 994 |
996 // Find all the indexed properties. | 995 // Find all the indexed properties. |
997 | 996 |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1050 var obj = new $Object(); | 1049 var obj = new $Object(); |
1051 obj.__proto__ = proto; | 1050 obj.__proto__ = proto; |
1052 if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties); | 1051 if (!IS_UNDEFINED(properties)) ObjectDefineProperties(obj, properties); |
1053 return obj; | 1052 return obj; |
1054 } | 1053 } |
1055 | 1054 |
1056 | 1055 |
1057 // ES5 section 15.2.3.6. | 1056 // ES5 section 15.2.3.6. |
1058 function ObjectDefineProperty(obj, p, attributes) { | 1057 function ObjectDefineProperty(obj, p, attributes) { |
1059 if (!IS_SPEC_OBJECT(obj)) { | 1058 if (!IS_SPEC_OBJECT(obj)) { |
1060 throw MakeTypeError("obj_ctor_property_non_object", ["defineProperty"]); | 1059 throw MakeTypeError("called_on_non_object", ["Object.defineProperty"]); |
1061 } | 1060 } |
1062 var name = ToString(p); | 1061 var name = ToString(p); |
1063 if (%IsJSProxy(obj)) { | 1062 if (%IsJSProxy(obj)) { |
1064 // Clone the attributes object for protection. | 1063 // Clone the attributes object for protection. |
1065 // TODO(rossberg): not spec'ed yet, so not sure if this should involve | 1064 // TODO(rossberg): not spec'ed yet, so not sure if this should involve |
1066 // non-own properties as it does (or non-enumerable ones, as it doesn't?). | 1065 // non-own properties as it does (or non-enumerable ones, as it doesn't?). |
1067 var attributesClone = {}; | 1066 var attributesClone = {}; |
1068 for (var a in attributes) { | 1067 for (var a in attributes) { |
1069 attributesClone[a] = attributes[a]; | 1068 attributesClone[a] = attributes[a]; |
1070 } | 1069 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1102 names.push(key); | 1101 names.push(key); |
1103 } | 1102 } |
1104 } | 1103 } |
1105 return names; | 1104 return names; |
1106 } | 1105 } |
1107 | 1106 |
1108 | 1107 |
1109 // ES5 section 15.2.3.7. | 1108 // ES5 section 15.2.3.7. |
1110 function ObjectDefineProperties(obj, properties) { | 1109 function ObjectDefineProperties(obj, properties) { |
1111 if (!IS_SPEC_OBJECT(obj)) { | 1110 if (!IS_SPEC_OBJECT(obj)) { |
1112 throw MakeTypeError("obj_ctor_property_non_object", ["defineProperties"]); | 1111 throw MakeTypeError("called_on_non_object", ["Object.defineProperties"]); |
1113 } | 1112 } |
1114 var props = ToObject(properties); | 1113 var props = ToObject(properties); |
1115 var names = GetOwnEnumerablePropertyNames(props); | 1114 var names = GetOwnEnumerablePropertyNames(props); |
1116 var descriptors = new InternalArray(); | 1115 var descriptors = new InternalArray(); |
1117 for (var i = 0; i < names.length; i++) { | 1116 for (var i = 0; i < names.length; i++) { |
1118 descriptors.push(ToPropertyDescriptor(props[names[i]])); | 1117 descriptors.push(ToPropertyDescriptor(props[names[i]])); |
1119 } | 1118 } |
1120 for (var i = 0; i < names.length; i++) { | 1119 for (var i = 0; i < names.length; i++) { |
1121 DefineOwnProperty(obj, names[i], descriptors[i], true); | 1120 DefineOwnProperty(obj, names[i], descriptors[i], true); |
1122 } | 1121 } |
(...skipping 26 matching lines...) Expand all Loading... |
1149 } else { | 1148 } else { |
1150 %Fix(obj); | 1149 %Fix(obj); |
1151 } | 1150 } |
1152 ObjectDefineProperties(obj, props); | 1151 ObjectDefineProperties(obj, props); |
1153 } | 1152 } |
1154 | 1153 |
1155 | 1154 |
1156 // ES5 section 15.2.3.8. | 1155 // ES5 section 15.2.3.8. |
1157 function ObjectSeal(obj) { | 1156 function ObjectSeal(obj) { |
1158 if (!IS_SPEC_OBJECT(obj)) { | 1157 if (!IS_SPEC_OBJECT(obj)) { |
1159 throw MakeTypeError("obj_ctor_property_non_object", ["seal"]); | 1158 throw MakeTypeError("called_on_non_object", ["Object.seal"]); |
1160 } | 1159 } |
1161 if (%IsJSProxy(obj)) { | 1160 if (%IsJSProxy(obj)) { |
1162 ProxyFix(obj); | 1161 ProxyFix(obj); |
1163 } | 1162 } |
1164 var names = ObjectGetOwnPropertyNames(obj); | 1163 var names = ObjectGetOwnPropertyNames(obj); |
1165 for (var i = 0; i < names.length; i++) { | 1164 for (var i = 0; i < names.length; i++) { |
1166 var name = names[i]; | 1165 var name = names[i]; |
1167 var desc = GetOwnProperty(obj, name); | 1166 var desc = GetOwnProperty(obj, name); |
1168 if (desc.isConfigurable()) { | 1167 if (desc.isConfigurable()) { |
1169 desc.setConfigurable(false); | 1168 desc.setConfigurable(false); |
1170 DefineOwnProperty(obj, name, desc, true); | 1169 DefineOwnProperty(obj, name, desc, true); |
1171 } | 1170 } |
1172 } | 1171 } |
1173 %PreventExtensions(obj); | 1172 %PreventExtensions(obj); |
1174 return obj; | 1173 return obj; |
1175 } | 1174 } |
1176 | 1175 |
1177 | 1176 |
1178 // ES5 section 15.2.3.9. | 1177 // ES5 section 15.2.3.9. |
1179 function ObjectFreeze(obj) { | 1178 function ObjectFreeze(obj) { |
1180 if (!IS_SPEC_OBJECT(obj)) { | 1179 if (!IS_SPEC_OBJECT(obj)) { |
1181 throw MakeTypeError("obj_ctor_property_non_object", ["freeze"]); | 1180 throw MakeTypeError("called_on_non_object", ["Object.freeze"]); |
1182 } | 1181 } |
1183 if (%IsJSProxy(obj)) { | 1182 if (%IsJSProxy(obj)) { |
1184 ProxyFix(obj); | 1183 ProxyFix(obj); |
1185 } | 1184 } |
1186 var names = ObjectGetOwnPropertyNames(obj); | 1185 var names = ObjectGetOwnPropertyNames(obj); |
1187 for (var i = 0; i < names.length; i++) { | 1186 for (var i = 0; i < names.length; i++) { |
1188 var name = names[i]; | 1187 var name = names[i]; |
1189 var desc = GetOwnProperty(obj, name); | 1188 var desc = GetOwnProperty(obj, name); |
1190 if (desc.isWritable() || desc.isConfigurable()) { | 1189 if (desc.isWritable() || desc.isConfigurable()) { |
1191 if (IsDataDescriptor(desc)) desc.setWritable(false); | 1190 if (IsDataDescriptor(desc)) desc.setWritable(false); |
1192 desc.setConfigurable(false); | 1191 desc.setConfigurable(false); |
1193 DefineOwnProperty(obj, name, desc, true); | 1192 DefineOwnProperty(obj, name, desc, true); |
1194 } | 1193 } |
1195 } | 1194 } |
1196 %PreventExtensions(obj); | 1195 %PreventExtensions(obj); |
1197 return obj; | 1196 return obj; |
1198 } | 1197 } |
1199 | 1198 |
1200 | 1199 |
1201 // ES5 section 15.2.3.10 | 1200 // ES5 section 15.2.3.10 |
1202 function ObjectPreventExtension(obj) { | 1201 function ObjectPreventExtension(obj) { |
1203 if (!IS_SPEC_OBJECT(obj)) { | 1202 if (!IS_SPEC_OBJECT(obj)) { |
1204 throw MakeTypeError("obj_ctor_property_non_object", ["preventExtension"]); | 1203 throw MakeTypeError("called_on_non_object", ["Object.preventExtension"]); |
1205 } | 1204 } |
1206 if (%IsJSProxy(obj)) { | 1205 if (%IsJSProxy(obj)) { |
1207 ProxyFix(obj); | 1206 ProxyFix(obj); |
1208 } | 1207 } |
1209 %PreventExtensions(obj); | 1208 %PreventExtensions(obj); |
1210 return obj; | 1209 return obj; |
1211 } | 1210 } |
1212 | 1211 |
1213 | 1212 |
1214 // ES5 section 15.2.3.11 | 1213 // ES5 section 15.2.3.11 |
1215 function ObjectIsSealed(obj) { | 1214 function ObjectIsSealed(obj) { |
1216 if (!IS_SPEC_OBJECT(obj)) { | 1215 if (!IS_SPEC_OBJECT(obj)) { |
1217 throw MakeTypeError("obj_ctor_property_non_object", ["isSealed"]); | 1216 throw MakeTypeError("called_on_non_object", ["Object.isSealed"]); |
1218 } | 1217 } |
1219 if (%IsJSProxy(obj)) { | 1218 if (%IsJSProxy(obj)) { |
1220 return false; | 1219 return false; |
1221 } | 1220 } |
1222 var names = ObjectGetOwnPropertyNames(obj); | 1221 var names = ObjectGetOwnPropertyNames(obj); |
1223 for (var i = 0; i < names.length; i++) { | 1222 for (var i = 0; i < names.length; i++) { |
1224 var name = names[i]; | 1223 var name = names[i]; |
1225 var desc = GetOwnProperty(obj, name); | 1224 var desc = GetOwnProperty(obj, name); |
1226 if (desc.isConfigurable()) return false; | 1225 if (desc.isConfigurable()) return false; |
1227 } | 1226 } |
1228 if (!ObjectIsExtensible(obj)) { | 1227 if (!ObjectIsExtensible(obj)) { |
1229 return true; | 1228 return true; |
1230 } | 1229 } |
1231 return false; | 1230 return false; |
1232 } | 1231 } |
1233 | 1232 |
1234 | 1233 |
1235 // ES5 section 15.2.3.12 | 1234 // ES5 section 15.2.3.12 |
1236 function ObjectIsFrozen(obj) { | 1235 function ObjectIsFrozen(obj) { |
1237 if (!IS_SPEC_OBJECT(obj)) { | 1236 if (!IS_SPEC_OBJECT(obj)) { |
1238 throw MakeTypeError("obj_ctor_property_non_object", ["isFrozen"]); | 1237 throw MakeTypeError("called_on_non_object", ["Object.isFrozen"]); |
1239 } | 1238 } |
1240 if (%IsJSProxy(obj)) { | 1239 if (%IsJSProxy(obj)) { |
1241 return false; | 1240 return false; |
1242 } | 1241 } |
1243 var names = ObjectGetOwnPropertyNames(obj); | 1242 var names = ObjectGetOwnPropertyNames(obj); |
1244 for (var i = 0; i < names.length; i++) { | 1243 for (var i = 0; i < names.length; i++) { |
1245 var name = names[i]; | 1244 var name = names[i]; |
1246 var desc = GetOwnProperty(obj, name); | 1245 var desc = GetOwnProperty(obj, name); |
1247 if (IsDataDescriptor(desc) && desc.isWritable()) return false; | 1246 if (IsDataDescriptor(desc) && desc.isWritable()) return false; |
1248 if (desc.isConfigurable()) return false; | 1247 if (desc.isConfigurable()) return false; |
1249 } | 1248 } |
1250 if (!ObjectIsExtensible(obj)) { | 1249 if (!ObjectIsExtensible(obj)) { |
1251 return true; | 1250 return true; |
1252 } | 1251 } |
1253 return false; | 1252 return false; |
1254 } | 1253 } |
1255 | 1254 |
1256 | 1255 |
1257 // ES5 section 15.2.3.13 | 1256 // ES5 section 15.2.3.13 |
1258 function ObjectIsExtensible(obj) { | 1257 function ObjectIsExtensible(obj) { |
1259 if (!IS_SPEC_OBJECT(obj)) { | 1258 if (!IS_SPEC_OBJECT(obj)) { |
1260 throw MakeTypeError("obj_ctor_property_non_object", ["isExtensible"]); | 1259 throw MakeTypeError("called_on_non_object", ["Object.isExtensible"]); |
1261 } | 1260 } |
1262 if (%IsJSProxy(obj)) { | 1261 if (%IsJSProxy(obj)) { |
1263 return true; | 1262 return true; |
1264 } | 1263 } |
1265 return %IsExtensible(obj); | 1264 return %IsExtensible(obj); |
1266 } | 1265 } |
1267 | 1266 |
1268 | 1267 |
1269 %SetCode($Object, function(x) { | 1268 %SetCode($Object, function(x) { |
1270 if (%_IsConstructCall()) { | 1269 if (%_IsConstructCall()) { |
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1646 | 1645 |
1647 function SetUpFunction() { | 1646 function SetUpFunction() { |
1648 %CheckIsBootstrapping(); | 1647 %CheckIsBootstrapping(); |
1649 InstallFunctions($Function.prototype, DONT_ENUM, $Array( | 1648 InstallFunctions($Function.prototype, DONT_ENUM, $Array( |
1650 "bind", FunctionBind, | 1649 "bind", FunctionBind, |
1651 "toString", FunctionToString | 1650 "toString", FunctionToString |
1652 )); | 1651 )); |
1653 } | 1652 } |
1654 | 1653 |
1655 SetUpFunction(); | 1654 SetUpFunction(); |
OLD | NEW |