Revision: 22132
Author:   [email protected]
Date:     Tue Jul  1 15:47:41 2014 UTC
Log:      Make freeze & friends ignore private properties

[email protected]
BUG=v8:3419
LOG=Y

Review URL: https://codereview.chromium.org/355123006
http://code.google.com/p/v8/source/detail?r=22132

Modified:
 /branches/bleeding_edge/src/objects.cc
 /branches/bleeding_edge/test/cctest/test-types.cc
 /branches/bleeding_edge/test/mjsunit/harmony/private.js

=======================================
--- /branches/bleeding_edge/src/objects.cc      Tue Jul  1 15:02:31 2014 UTC
+++ /branches/bleeding_edge/src/objects.cc      Tue Jul  1 15:47:41 2014 UTC
@@ -5679,7 +5679,8 @@
   int capacity = dictionary->Capacity();
   for (int i = 0; i < capacity; i++) {
     Object* k = dictionary->KeyAt(i);
-    if (dictionary->IsKey(k)) {
+    if (dictionary->IsKey(k) &&
+        !(k->IsSymbol() && Symbol::cast(k)->is_private())) {
       PropertyDetails details = dictionary->DetailsAt(i);
       int attrs = DONT_DELETE;
       // READ_ONLY is an invalid attribute for JS setters/getters.
@@ -7453,17 +7454,20 @@
   if (attributes != NONE) {
     for (int i = 0; i < size; ++i) {
       Object* value = desc->GetValue(i);
+      Name* key = desc->GetKey(i);
       PropertyDetails details = desc->GetDetails(i);
-      int mask = DONT_DELETE | DONT_ENUM;
-      // READ_ONLY is an invalid attribute for JS setters/getters.
-      if (details.type() != CALLBACKS || !value->IsAccessorPair()) {
-        mask |= READ_ONLY;
+      // Bulk attribute changes never affect private properties.
+      if (!key->IsSymbol() || !Symbol::cast(key)->is_private()) {
+        int mask = DONT_DELETE | DONT_ENUM;
+        // READ_ONLY is an invalid attribute for JS setters/getters.
+        if (details.type() != CALLBACKS || !value->IsAccessorPair()) {
+          mask |= READ_ONLY;
+        }
+        details = details.CopyAddAttributes(
+            static_cast<PropertyAttributes>(attributes & mask));
       }
-      details = details.CopyAddAttributes(
-          static_cast<PropertyAttributes>(attributes & mask));
-      Descriptor inner_desc(handle(desc->GetKey(i)),
-                            handle(value, desc->GetIsolate()),
-                            details);
+      Descriptor inner_desc(
+          handle(key), handle(value, desc->GetIsolate()), details);
       descriptors->Set(i, &inner_desc, witness);
     }
   } else {
=======================================
--- /branches/bleeding_edge/test/cctest/test-types.cc Mon Jun 30 13:25:46 2014 UTC +++ /branches/bleeding_edge/test/cctest/test-types.cc Tue Jul 1 15:47:41 2014 UTC
@@ -180,7 +180,7 @@
     NumberFunction2 = Type::Function(Number, Number, Number, region);
     MethodFunction = Type::Function(String, Object, 0, region);

-    for (int i = 0; i < 50; ++i) {
+    for (int i = 0; i < 40; ++i) {
       types.push_back(Fuzz());
     }
   }
=======================================
--- /branches/bleeding_edge/test/mjsunit/harmony/private.js Tue May 6 14:48:34 2014 UTC +++ /branches/bleeding_edge/test/mjsunit/harmony/private.js Tue Jul 1 15:47:41 2014 UTC
@@ -342,3 +342,18 @@
   assertEquals(syms, [publicSymbol, publicSymbol2])
 }
 TestGetOwnPropertySymbols()
+
+
+function TestSealAndFreeze(freeze) {
+  var sym = %CreatePrivateSymbol("private")
+  var obj = {}
+  obj[sym] = 1
+  freeze(obj)
+  obj[sym] = 2
+  assertEquals(2, obj[sym])
+  assertTrue(delete obj[sym])
+  assertEquals(undefined, obj[sym])
+}
+TestSealAndFreeze(Object.seal)
+TestSealAndFreeze(Object.freeze)
+TestSealAndFreeze(Object.preventExtensions)

--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to