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

Side by Side Diff: src/v8natives.js

Issue 1011823003: [es6] don't throw if argument is non-object (O.freeze, O.seal, O.preventExtensions) (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: remove phantom edit Created 5 years, 8 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
« no previous file with comments | « no previous file | test/mjsunit/messages.js » ('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 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 1237 matching lines...) Expand 10 before | Expand all | Expand 10 after
1248 obj.length = 0; 1248 obj.length = 0;
1249 } else { 1249 } else {
1250 %Fix(obj); 1250 %Fix(obj);
1251 } 1251 }
1252 ObjectDefineProperties(obj, props); 1252 ObjectDefineProperties(obj, props);
1253 } 1253 }
1254 1254
1255 1255
1256 // ES5 section 15.2.3.8. 1256 // ES5 section 15.2.3.8.
1257 function ObjectSealJS(obj) { 1257 function ObjectSealJS(obj) {
1258 if (!IS_SPEC_OBJECT(obj)) { 1258 if (!IS_SPEC_OBJECT(obj)) return obj;
1259 throw MakeTypeError(kCalledOnNonObject, "Object.seal");
1260 }
1261 var isProxy = %_IsJSProxy(obj); 1259 var isProxy = %_IsJSProxy(obj);
1262 if (isProxy || %HasSloppyArgumentsElements(obj) || %IsObserved(obj)) { 1260 if (isProxy || %HasSloppyArgumentsElements(obj) || %IsObserved(obj)) {
1263 if (isProxy) { 1261 if (isProxy) {
1264 ProxyFix(obj); 1262 ProxyFix(obj);
1265 } 1263 }
1266 var names = ObjectGetOwnPropertyNames(obj); 1264 var names = ObjectGetOwnPropertyNames(obj);
1267 for (var i = 0; i < names.length; i++) { 1265 for (var i = 0; i < names.length; i++) {
1268 var name = names[i]; 1266 var name = names[i];
1269 var desc = GetOwnPropertyJS(obj, name); 1267 var desc = GetOwnPropertyJS(obj, name);
1270 if (desc.isConfigurable()) { 1268 if (desc.isConfigurable()) {
1271 desc.setConfigurable(false); 1269 desc.setConfigurable(false);
1272 DefineOwnProperty(obj, name, desc, true); 1270 DefineOwnProperty(obj, name, desc, true);
1273 } 1271 }
1274 } 1272 }
1275 %PreventExtensions(obj); 1273 %PreventExtensions(obj);
1276 } else { 1274 } else {
1277 // TODO(adamk): Is it worth going to this fast path if the 1275 // TODO(adamk): Is it worth going to this fast path if the
1278 // object's properties are already in dictionary mode? 1276 // object's properties are already in dictionary mode?
1279 %ObjectSeal(obj); 1277 %ObjectSeal(obj);
1280 } 1278 }
1281 return obj; 1279 return obj;
1282 } 1280 }
1283 1281
1284 1282
1285 // ES5 section 15.2.3.9. 1283 // ES5 section 15.2.3.9.
1286 function ObjectFreezeJS(obj) { 1284 function ObjectFreezeJS(obj) {
1287 if (!IS_SPEC_OBJECT(obj)) { 1285 if (!IS_SPEC_OBJECT(obj)) return obj;
1288 throw MakeTypeError(kCalledOnNonObject, "Object.freeze");
1289 }
1290 var isProxy = %_IsJSProxy(obj); 1286 var isProxy = %_IsJSProxy(obj);
1291 if (isProxy || %HasSloppyArgumentsElements(obj) || %IsObserved(obj)) { 1287 if (isProxy || %HasSloppyArgumentsElements(obj) || %IsObserved(obj)) {
1292 if (isProxy) { 1288 if (isProxy) {
1293 ProxyFix(obj); 1289 ProxyFix(obj);
1294 } 1290 }
1295 var names = ObjectGetOwnPropertyNames(obj); 1291 var names = ObjectGetOwnPropertyNames(obj);
1296 for (var i = 0; i < names.length; i++) { 1292 for (var i = 0; i < names.length; i++) {
1297 var name = names[i]; 1293 var name = names[i];
1298 var desc = GetOwnPropertyJS(obj, name); 1294 var desc = GetOwnPropertyJS(obj, name);
1299 if (desc.isWritable() || desc.isConfigurable()) { 1295 if (desc.isWritable() || desc.isConfigurable()) {
1300 if (IsDataDescriptor(desc)) desc.setWritable(false); 1296 if (IsDataDescriptor(desc)) desc.setWritable(false);
1301 desc.setConfigurable(false); 1297 desc.setConfigurable(false);
1302 DefineOwnProperty(obj, name, desc, true); 1298 DefineOwnProperty(obj, name, desc, true);
1303 } 1299 }
1304 } 1300 }
1305 %PreventExtensions(obj); 1301 %PreventExtensions(obj);
1306 } else { 1302 } else {
1307 // TODO(adamk): Is it worth going to this fast path if the 1303 // TODO(adamk): Is it worth going to this fast path if the
1308 // object's properties are already in dictionary mode? 1304 // object's properties are already in dictionary mode?
1309 %ObjectFreeze(obj); 1305 %ObjectFreeze(obj);
1310 } 1306 }
1311 return obj; 1307 return obj;
1312 } 1308 }
1313 1309
1314 1310
1315 // ES5 section 15.2.3.10 1311 // ES5 section 15.2.3.10
1316 function ObjectPreventExtension(obj) { 1312 function ObjectPreventExtension(obj) {
1317 if (!IS_SPEC_OBJECT(obj)) { 1313 if (!IS_SPEC_OBJECT(obj)) return obj;
1318 throw MakeTypeError(kCalledOnNonObject, "Object.preventExtension");
1319 }
1320 if (%_IsJSProxy(obj)) { 1314 if (%_IsJSProxy(obj)) {
1321 ProxyFix(obj); 1315 ProxyFix(obj);
1322 } 1316 }
1323 %PreventExtensions(obj); 1317 %PreventExtensions(obj);
1324 return obj; 1318 return obj;
1325 } 1319 }
1326 1320
1327 1321
1328 // ES5 section 15.2.3.11 1322 // ES5 section 15.2.3.11
1329 function ObjectIsSealed(obj) { 1323 function ObjectIsSealed(obj) {
1330 if (!IS_SPEC_OBJECT(obj)) { 1324 if (!IS_SPEC_OBJECT(obj)) return true;
1331 throw MakeTypeError(kCalledOnNonObject, "Object.isSealed");
1332 }
1333 if (%_IsJSProxy(obj)) { 1325 if (%_IsJSProxy(obj)) {
1334 return false; 1326 return false;
1335 } 1327 }
1336 if (%IsExtensible(obj)) { 1328 if (%IsExtensible(obj)) {
1337 return false; 1329 return false;
1338 } 1330 }
1339 var names = ObjectGetOwnPropertyNames(obj); 1331 var names = ObjectGetOwnPropertyNames(obj);
1340 for (var i = 0; i < names.length; i++) { 1332 for (var i = 0; i < names.length; i++) {
1341 var name = names[i]; 1333 var name = names[i];
1342 var desc = GetOwnPropertyJS(obj, name); 1334 var desc = GetOwnPropertyJS(obj, name);
1343 if (desc.isConfigurable()) { 1335 if (desc.isConfigurable()) {
1344 return false; 1336 return false;
1345 } 1337 }
1346 } 1338 }
1347 return true; 1339 return true;
1348 } 1340 }
1349 1341
1350 1342
1351 // ES5 section 15.2.3.12 1343 // ES5 section 15.2.3.12
1352 function ObjectIsFrozen(obj) { 1344 function ObjectIsFrozen(obj) {
1353 if (!IS_SPEC_OBJECT(obj)) { 1345 if (!IS_SPEC_OBJECT(obj)) return true;
1354 throw MakeTypeError(kCalledOnNonObject, "Object.isFrozen");
1355 }
1356 if (%_IsJSProxy(obj)) { 1346 if (%_IsJSProxy(obj)) {
1357 return false; 1347 return false;
1358 } 1348 }
1359 if (%IsExtensible(obj)) { 1349 if (%IsExtensible(obj)) {
1360 return false; 1350 return false;
1361 } 1351 }
1362 var names = ObjectGetOwnPropertyNames(obj); 1352 var names = ObjectGetOwnPropertyNames(obj);
1363 for (var i = 0; i < names.length; i++) { 1353 for (var i = 0; i < names.length; i++) {
1364 var name = names[i]; 1354 var name = names[i];
1365 var desc = GetOwnPropertyJS(obj, name); 1355 var desc = GetOwnPropertyJS(obj, name);
1366 if (IsDataDescriptor(desc) && desc.isWritable()) return false; 1356 if (IsDataDescriptor(desc) && desc.isWritable()) return false;
1367 if (desc.isConfigurable()) return false; 1357 if (desc.isConfigurable()) return false;
1368 } 1358 }
1369 return true; 1359 return true;
1370 } 1360 }
1371 1361
1372 1362
1373 // ES5 section 15.2.3.13 1363 // ES5 section 15.2.3.13
1374 function ObjectIsExtensible(obj) { 1364 function ObjectIsExtensible(obj) {
1375 if (!IS_SPEC_OBJECT(obj)) { 1365 if (!IS_SPEC_OBJECT(obj)) return false;
1376 throw MakeTypeError(kCalledOnNonObject, "Object.isExtensible");
1377 }
1378 if (%_IsJSProxy(obj)) { 1366 if (%_IsJSProxy(obj)) {
1379 return true; 1367 return true;
1380 } 1368 }
1381 return %IsExtensible(obj); 1369 return %IsExtensible(obj);
1382 } 1370 }
1383 1371
1384 1372
1385 // ECMA-262, Edition 6, section 19.1.2.10 1373 // ECMA-262, Edition 6, section 19.1.2.10
1386 function ObjectIs(obj1, obj2) { 1374 function ObjectIs(obj1, obj2) {
1387 return SameValue(obj1, obj2); 1375 return SameValue(obj1, obj2);
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
1910 } 1898 }
1911 if (!IS_SPEC_FUNCTION(method)) { 1899 if (!IS_SPEC_FUNCTION(method)) {
1912 throw MakeTypeError(kNotIterable, obj); 1900 throw MakeTypeError(kNotIterable, obj);
1913 } 1901 }
1914 var iterator = %_CallFunction(obj, method); 1902 var iterator = %_CallFunction(obj, method);
1915 if (!IS_SPEC_OBJECT(iterator)) { 1903 if (!IS_SPEC_OBJECT(iterator)) {
1916 throw MakeTypeError(kNotAnIterator, iterator); 1904 throw MakeTypeError(kNotAnIterator, iterator);
1917 } 1905 }
1918 return iterator; 1906 return iterator;
1919 } 1907 }
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/messages.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698