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

Side by Side Diff: src/v8natives.js

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