OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This file relies on the fact that the following declarations have been made | 5 // This file relies on the fact that the following declarations have been made |
6 // in runtime.js: | 6 // in runtime.js: |
7 // var $Object = global.Object; | 7 // var $Object = global.Object; |
8 // var $Boolean = global.Boolean; | 8 // var $Boolean = global.Boolean; |
9 // var $Number = global.Number; | 9 // var $Number = global.Number; |
10 // var $Function = global.Function; | 10 // var $Function = global.Function; |
(...skipping 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1234 obj.length = 0; | 1234 obj.length = 0; |
1235 } else { | 1235 } else { |
1236 %Fix(obj); | 1236 %Fix(obj); |
1237 } | 1237 } |
1238 ObjectDefineProperties(obj, props); | 1238 ObjectDefineProperties(obj, props); |
1239 } | 1239 } |
1240 | 1240 |
1241 | 1241 |
1242 // ES5 section 15.2.3.8. | 1242 // ES5 section 15.2.3.8. |
1243 function ObjectSealJS(obj) { | 1243 function ObjectSealJS(obj) { |
1244 if (!IS_SPEC_OBJECT(obj)) { | 1244 if (!IS_SPEC_OBJECT(obj)) return obj; |
1245 throw MakeTypeError("called_on_non_object", ["Object.seal"]); | |
1246 } | |
1247 var isProxy = %_IsJSProxy(obj); | 1245 var isProxy = %_IsJSProxy(obj); |
1248 if (isProxy || %HasSloppyArgumentsElements(obj) || %IsObserved(obj)) { | 1246 if (isProxy || %HasSloppyArgumentsElements(obj) || %IsObserved(obj)) { |
1249 if (isProxy) { | 1247 if (isProxy) { |
1250 ProxyFix(obj); | 1248 ProxyFix(obj); |
1251 } | 1249 } |
1252 var names = ObjectGetOwnPropertyNames(obj); | 1250 var names = ObjectGetOwnPropertyNames(obj); |
1253 for (var i = 0; i < names.length; i++) { | 1251 for (var i = 0; i < names.length; i++) { |
1254 var name = names[i]; | 1252 var name = names[i]; |
1255 var desc = GetOwnPropertyJS(obj, name); | 1253 var desc = GetOwnPropertyJS(obj, name); |
1256 if (desc.isConfigurable()) { | 1254 if (desc.isConfigurable()) { |
1257 desc.setConfigurable(false); | 1255 desc.setConfigurable(false); |
1258 DefineOwnProperty(obj, name, desc, true); | 1256 DefineOwnProperty(obj, name, desc, true); |
1259 } | 1257 } |
1260 } | 1258 } |
1261 %PreventExtensions(obj); | 1259 %PreventExtensions(obj); |
1262 } else { | 1260 } else { |
1263 // TODO(adamk): Is it worth going to this fast path if the | 1261 // TODO(adamk): Is it worth going to this fast path if the |
1264 // object's properties are already in dictionary mode? | 1262 // object's properties are already in dictionary mode? |
1265 %ObjectSeal(obj); | 1263 %ObjectSeal(obj); |
1266 } | 1264 } |
1267 return obj; | 1265 return obj; |
1268 } | 1266 } |
1269 | 1267 |
1270 | 1268 |
1271 // ES5 section 15.2.3.9. | 1269 // ES5 section 15.2.3.9. |
1272 function ObjectFreezeJS(obj) { | 1270 function ObjectFreezeJS(obj) { |
1273 if (!IS_SPEC_OBJECT(obj)) { | 1271 if (!IS_SPEC_OBJECT(obj)) return obj; |
1274 throw MakeTypeError("called_on_non_object", ["Object.freeze"]); | |
1275 } | |
1276 var isProxy = %_IsJSProxy(obj); | 1272 var isProxy = %_IsJSProxy(obj); |
1277 if (isProxy || %HasSloppyArgumentsElements(obj) || %IsObserved(obj)) { | 1273 if (isProxy || %HasSloppyArgumentsElements(obj) || %IsObserved(obj)) { |
1278 if (isProxy) { | 1274 if (isProxy) { |
1279 ProxyFix(obj); | 1275 ProxyFix(obj); |
1280 } | 1276 } |
1281 var names = ObjectGetOwnPropertyNames(obj); | 1277 var names = ObjectGetOwnPropertyNames(obj); |
1282 for (var i = 0; i < names.length; i++) { | 1278 for (var i = 0; i < names.length; i++) { |
1283 var name = names[i]; | 1279 var name = names[i]; |
1284 var desc = GetOwnPropertyJS(obj, name); | 1280 var desc = GetOwnPropertyJS(obj, name); |
1285 if (desc.isWritable() || desc.isConfigurable()) { | 1281 if (desc.isWritable() || desc.isConfigurable()) { |
1286 if (IsDataDescriptor(desc)) desc.setWritable(false); | 1282 if (IsDataDescriptor(desc)) desc.setWritable(false); |
1287 desc.setConfigurable(false); | 1283 desc.setConfigurable(false); |
1288 DefineOwnProperty(obj, name, desc, true); | 1284 DefineOwnProperty(obj, name, desc, true); |
1289 } | 1285 } |
1290 } | 1286 } |
1291 %PreventExtensions(obj); | 1287 %PreventExtensions(obj); |
1292 } else { | 1288 } else { |
1293 // TODO(adamk): Is it worth going to this fast path if the | 1289 // TODO(adamk): Is it worth going to this fast path if the |
1294 // object's properties are already in dictionary mode? | 1290 // object's properties are already in dictionary mode? |
1295 %ObjectFreeze(obj); | 1291 %ObjectFreeze(obj); |
1296 } | 1292 } |
1297 return obj; | 1293 return obj; |
1298 } | 1294 } |
1299 | 1295 |
1300 | 1296 |
1301 // ES5 section 15.2.3.10 | 1297 // ES5 section 15.2.3.10 |
1302 function ObjectPreventExtension(obj) { | 1298 function ObjectPreventExtension(obj) { |
1303 if (!IS_SPEC_OBJECT(obj)) { | 1299 if (!IS_SPEC_OBJECT(obj)) return obj; |
1304 throw MakeTypeError("called_on_non_object", ["Object.preventExtension"]); | |
1305 } | |
1306 if (%_IsJSProxy(obj)) { | 1300 if (%_IsJSProxy(obj)) { |
1307 ProxyFix(obj); | 1301 ProxyFix(obj); |
1308 } | 1302 } |
1309 %PreventExtensions(obj); | 1303 %PreventExtensions(obj); |
1310 return obj; | 1304 return obj; |
1311 } | 1305 } |
1312 | 1306 |
1313 | 1307 |
1314 // ES5 section 15.2.3.11 | 1308 // ES5 section 15.2.3.11 |
1315 function ObjectIsSealed(obj) { | 1309 function ObjectIsSealed(obj) { |
1316 if (!IS_SPEC_OBJECT(obj)) { | 1310 if (!IS_SPEC_OBJECT(obj)) return true; |
1317 throw MakeTypeError("called_on_non_object", ["Object.isSealed"]); | |
1318 } | |
1319 if (%_IsJSProxy(obj)) { | 1311 if (%_IsJSProxy(obj)) { |
1320 return false; | 1312 return false; |
1321 } | 1313 } |
1322 if (%IsExtensible(obj)) { | 1314 if (%IsExtensible(obj)) { |
1323 return false; | 1315 return false; |
1324 } | 1316 } |
1325 var names = ObjectGetOwnPropertyNames(obj); | 1317 var names = ObjectGetOwnPropertyNames(obj); |
1326 for (var i = 0; i < names.length; i++) { | 1318 for (var i = 0; i < names.length; i++) { |
1327 var name = names[i]; | 1319 var name = names[i]; |
1328 var desc = GetOwnPropertyJS(obj, name); | 1320 var desc = GetOwnPropertyJS(obj, name); |
1329 if (desc.isConfigurable()) { | 1321 if (desc.isConfigurable()) { |
1330 return false; | 1322 return false; |
1331 } | 1323 } |
1332 } | 1324 } |
1333 return true; | 1325 return true; |
1334 } | 1326 } |
1335 | 1327 |
1336 | 1328 |
1337 // ES5 section 15.2.3.12 | 1329 // ES5 section 15.2.3.12 |
1338 function ObjectIsFrozen(obj) { | 1330 function ObjectIsFrozen(obj) { |
1339 if (!IS_SPEC_OBJECT(obj)) { | 1331 if (!IS_SPEC_OBJECT(obj)) return true; |
1340 throw MakeTypeError("called_on_non_object", ["Object.isFrozen"]); | |
1341 } | |
1342 if (%_IsJSProxy(obj)) { | 1332 if (%_IsJSProxy(obj)) { |
1343 return false; | 1333 return false; |
1344 } | 1334 } |
1345 if (%IsExtensible(obj)) { | 1335 if (%IsExtensible(obj)) { |
1346 return false; | 1336 return false; |
1347 } | 1337 } |
1348 var names = ObjectGetOwnPropertyNames(obj); | 1338 var names = ObjectGetOwnPropertyNames(obj); |
1349 for (var i = 0; i < names.length; i++) { | 1339 for (var i = 0; i < names.length; i++) { |
1350 var name = names[i]; | 1340 var name = names[i]; |
1351 var desc = GetOwnPropertyJS(obj, name); | 1341 var desc = GetOwnPropertyJS(obj, name); |
1352 if (IsDataDescriptor(desc) && desc.isWritable()) return false; | 1342 if (IsDataDescriptor(desc) && desc.isWritable()) return false; |
1353 if (desc.isConfigurable()) return false; | 1343 if (desc.isConfigurable()) return false; |
1354 } | 1344 } |
1355 return true; | 1345 return true; |
1356 } | 1346 } |
1357 | 1347 |
1358 | 1348 |
1359 // ES5 section 15.2.3.13 | 1349 // ES5 section 15.2.3.13 |
1360 function ObjectIsExtensible(obj) { | 1350 function ObjectIsExtensible(obj) { |
1361 if (!IS_SPEC_OBJECT(obj)) { | 1351 if (!IS_SPEC_OBJECT(obj)) return false; |
1362 throw MakeTypeError("called_on_non_object", ["Object.isExtensible"]); | |
1363 } | |
1364 if (%_IsJSProxy(obj)) { | 1352 if (%_IsJSProxy(obj)) { |
1365 return true; | 1353 return true; |
1366 } | 1354 } |
1367 return %IsExtensible(obj); | 1355 return %IsExtensible(obj); |
1368 } | 1356 } |
1369 | 1357 |
1370 | 1358 |
1371 // ECMA-262, Edition 6, section 19.1.2.10 | 1359 // ECMA-262, Edition 6, section 19.1.2.10 |
1372 function ObjectIs(obj1, obj2) { | 1360 function ObjectIs(obj1, obj2) { |
1373 return SameValue(obj1, obj2); | 1361 return SameValue(obj1, obj2); |
(...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1894 } | 1882 } |
1895 if (!IS_SPEC_FUNCTION(method)) { | 1883 if (!IS_SPEC_FUNCTION(method)) { |
1896 throw MakeTypeError('not_iterable', [obj]); | 1884 throw MakeTypeError('not_iterable', [obj]); |
1897 } | 1885 } |
1898 var iterator = %_CallFunction(obj, method); | 1886 var iterator = %_CallFunction(obj, method); |
1899 if (!IS_SPEC_OBJECT(iterator)) { | 1887 if (!IS_SPEC_OBJECT(iterator)) { |
1900 throw MakeTypeError('not_an_iterator', [iterator]); | 1888 throw MakeTypeError('not_an_iterator', [iterator]); |
1901 } | 1889 } |
1902 return iterator; | 1890 return iterator; |
1903 } | 1891 } |
OLD | NEW |