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

Side by Side Diff: src/v8natives.js

Issue 776143005: Optimize Object.seal and Object.preventExtensions (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Add nonextensible and sealed as special transitions Created 6 years 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 | « src/transitions-inl.h ('k') | test/mjsunit/object-freeze.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 1214 matching lines...) Expand 10 before | Expand all | Expand 10 after
1225 %FunctionSetPrototype(obj, prototype); 1225 %FunctionSetPrototype(obj, prototype);
1226 obj.length = 0; 1226 obj.length = 0;
1227 } else { 1227 } else {
1228 %Fix(obj); 1228 %Fix(obj);
1229 } 1229 }
1230 ObjectDefineProperties(obj, props); 1230 ObjectDefineProperties(obj, props);
1231 } 1231 }
1232 1232
1233 1233
1234 // ES5 section 15.2.3.8. 1234 // ES5 section 15.2.3.8.
1235 function ObjectSeal(obj) { 1235 function ObjectSealJS(obj) {
1236 if (!IS_SPEC_OBJECT(obj)) { 1236 if (!IS_SPEC_OBJECT(obj)) {
1237 throw MakeTypeError("called_on_non_object", ["Object.seal"]); 1237 throw MakeTypeError("called_on_non_object", ["Object.seal"]);
1238 } 1238 }
1239 if (%_IsJSProxy(obj)) { 1239 var isProxy = %_IsJSProxy(obj);
1240 ProxyFix(obj); 1240 if (isProxy || %HasSloppyArgumentsElements(obj) || %IsObserved(obj)) {
1241 if (isProxy) {
1242 ProxyFix(obj);
1243 }
1244 var names = ObjectGetOwnPropertyNames(obj);
1245 for (var i = 0; i < names.length; i++) {
1246 var name = names[i];
1247 var desc = GetOwnPropertyJS(obj, name);
1248 if (desc.isConfigurable()) {
1249 desc.setConfigurable(false);
1250 DefineOwnProperty(obj, name, desc, true);
1251 }
1252 }
1253 %PreventExtensions(obj);
1254 } else {
1255 // TODO(adamk): Is it worth going to this fast path if the
1256 // object's properties are already in dictionary mode?
1257 %ObjectSeal(obj);
1241 } 1258 }
1242 var names = ObjectGetOwnPropertyNames(obj);
1243 for (var i = 0; i < names.length; i++) {
1244 var name = names[i];
1245 var desc = GetOwnPropertyJS(obj, name);
1246 if (desc.isConfigurable()) {
1247 desc.setConfigurable(false);
1248 DefineOwnProperty(obj, name, desc, true);
1249 }
1250 }
1251 %PreventExtensions(obj);
1252 return obj; 1259 return obj;
1253 } 1260 }
1254 1261
1255 1262
1256 // ES5 section 15.2.3.9. 1263 // ES5 section 15.2.3.9.
1257 function ObjectFreezeJS(obj) { 1264 function ObjectFreezeJS(obj) {
1258 if (!IS_SPEC_OBJECT(obj)) { 1265 if (!IS_SPEC_OBJECT(obj)) {
1259 throw MakeTypeError("called_on_non_object", ["Object.freeze"]); 1266 throw MakeTypeError("called_on_non_object", ["Object.freeze"]);
1260 } 1267 }
1261 var isProxy = %_IsJSProxy(obj); 1268 var isProxy = %_IsJSProxy(obj);
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 "getPrototypeOf", ObjectGetPrototypeOf, 1430 "getPrototypeOf", ObjectGetPrototypeOf,
1424 "setPrototypeOf", ObjectSetPrototypeOf, 1431 "setPrototypeOf", ObjectSetPrototypeOf,
1425 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor, 1432 "getOwnPropertyDescriptor", ObjectGetOwnPropertyDescriptor,
1426 "getOwnPropertyNames", ObjectGetOwnPropertyNames, 1433 "getOwnPropertyNames", ObjectGetOwnPropertyNames,
1427 // getOwnPropertySymbols is added in symbol.js. 1434 // getOwnPropertySymbols is added in symbol.js.
1428 "is", ObjectIs, 1435 "is", ObjectIs,
1429 "isExtensible", ObjectIsExtensible, 1436 "isExtensible", ObjectIsExtensible,
1430 "isFrozen", ObjectIsFrozen, 1437 "isFrozen", ObjectIsFrozen,
1431 "isSealed", ObjectIsSealed, 1438 "isSealed", ObjectIsSealed,
1432 "preventExtensions", ObjectPreventExtension, 1439 "preventExtensions", ObjectPreventExtension,
1433 "seal", ObjectSeal 1440 "seal", ObjectSealJS
1434 // deliverChangeRecords, getNotifier, observe and unobserve are added 1441 // deliverChangeRecords, getNotifier, observe and unobserve are added
1435 // in object-observe.js. 1442 // in object-observe.js.
1436 )); 1443 ));
1437 } 1444 }
1438 1445
1439 SetUpObject(); 1446 SetUpObject();
1440 1447
1441 1448
1442 // ---------------------------------------------------------------------------- 1449 // ----------------------------------------------------------------------------
1443 // Boolean 1450 // Boolean
(...skipping 446 matching lines...) Expand 10 before | Expand all | Expand 10 after
1890 } 1897 }
1891 if (!IS_SPEC_FUNCTION(method)) { 1898 if (!IS_SPEC_FUNCTION(method)) {
1892 throw MakeTypeError('not_iterable', [obj]); 1899 throw MakeTypeError('not_iterable', [obj]);
1893 } 1900 }
1894 var iterator = %_CallFunction(obj, method); 1901 var iterator = %_CallFunction(obj, method);
1895 if (!IS_SPEC_OBJECT(iterator)) { 1902 if (!IS_SPEC_OBJECT(iterator)) {
1896 throw MakeTypeError('not_an_iterator', [iterator]); 1903 throw MakeTypeError('not_an_iterator', [iterator]);
1897 } 1904 }
1898 return iterator; 1905 return iterator;
1899 } 1906 }
OLDNEW
« no previous file with comments | « src/transitions-inl.h ('k') | test/mjsunit/object-freeze.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698