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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/transitions-inl.h ('k') | test/mjsunit/object-freeze.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/v8natives.js
diff --git a/src/v8natives.js b/src/v8natives.js
index 02294b340ab4607557f55daee6886c46b34d9e92..44ad6de622fc73e7687259b23e7b0a388537b993 100644
--- a/src/v8natives.js
+++ b/src/v8natives.js
@@ -1232,23 +1232,30 @@ function ProxyFix(obj) {
// ES5 section 15.2.3.8.
-function ObjectSeal(obj) {
+function ObjectSealJS(obj) {
if (!IS_SPEC_OBJECT(obj)) {
throw MakeTypeError("called_on_non_object", ["Object.seal"]);
}
- if (%_IsJSProxy(obj)) {
- ProxyFix(obj);
- }
- var names = ObjectGetOwnPropertyNames(obj);
- for (var i = 0; i < names.length; i++) {
- var name = names[i];
- var desc = GetOwnPropertyJS(obj, name);
- if (desc.isConfigurable()) {
- desc.setConfigurable(false);
- DefineOwnProperty(obj, name, desc, true);
+ var isProxy = %_IsJSProxy(obj);
+ if (isProxy || %HasSloppyArgumentsElements(obj) || %IsObserved(obj)) {
+ if (isProxy) {
+ ProxyFix(obj);
}
+ var names = ObjectGetOwnPropertyNames(obj);
+ for (var i = 0; i < names.length; i++) {
+ var name = names[i];
+ var desc = GetOwnPropertyJS(obj, name);
+ if (desc.isConfigurable()) {
+ desc.setConfigurable(false);
+ DefineOwnProperty(obj, name, desc, true);
+ }
+ }
+ %PreventExtensions(obj);
+ } else {
+ // TODO(adamk): Is it worth going to this fast path if the
+ // object's properties are already in dictionary mode?
+ %ObjectSeal(obj);
}
- %PreventExtensions(obj);
return obj;
}
@@ -1430,7 +1437,7 @@ function SetUpObject() {
"isFrozen", ObjectIsFrozen,
"isSealed", ObjectIsSealed,
"preventExtensions", ObjectPreventExtension,
- "seal", ObjectSeal
+ "seal", ObjectSealJS
// deliverChangeRecords, getNotifier, observe and unobserve are added
// in object-observe.js.
));
« 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