Revision: 12512
Author:   [email protected]
Date:     Fri Sep 14 06:15:43 2012
Log: CNLT with descriptors but no valid enum fields has to clear the EnumCache.

Review URL: https://chromiumcodereview.appspot.com/10928204
http://code.google.com/p/v8/source/detail?r=12512

Added:
/branches/bleeding_edge/test/mjsunit/regress/regress-cntl-descriptors-enum.js
Modified:
 /branches/bleeding_edge/src/objects.cc
 /branches/bleeding_edge/src/objects.h

=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/mjsunit/regress/regress-cntl-descriptors-enum.js Fri Sep 14 06:15:43 2012
@@ -0,0 +1,46 @@
+// Copyright 2012 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+//     * Redistributions of source code must retain the above copyright
+//       notice, this list of conditions and the following disclaimer.
+//     * Redistributions in binary form must reproduce the above
+//       copyright notice, this list of conditions and the following
+//       disclaimer in the documentation and/or other materials provided
+//       with the distribution.
+//     * Neither the name of Google Inc. nor the names of its
+//       contributors may be used to endorse or promote products derived
+//       from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Flags: --allow-natives-syntax --expose-gc
+
+DontEnum = 2;
+
+var o = {};
+%SetProperty(o, "a", 0, DontEnum);
+
+var o2 = {};
+%SetProperty(o2, "a", 0, DontEnum);
+
+assertTrue(%HaveSameMap(o, o2));
+
+o.y = 2;
+
+for (var v in o) { print(v); }
+o = {};
+gc();
+
+for (var v in o2) { print(v); }
=======================================
--- /branches/bleeding_edge/src/objects.cc      Thu Sep 13 09:48:31 2012
+++ /branches/bleeding_edge/src/objects.cc      Fri Sep 14 06:15:43 2012
@@ -6086,6 +6086,11 @@
   result->set(kEnumCacheIndex, Smi::FromInt(0));
   return result;
 }
+
+
+void DescriptorArray::ClearEnumCache() {
+  set(kEnumCacheIndex, Smi::FromInt(0));
+}


 void DescriptorArray::SetEnumCache(FixedArray* bridge_storage,
@@ -7489,19 +7494,24 @@

   if (descriptors_owner_died) {
     if (number_of_own_descriptors > 0) {
- int live_enum = NumberOfDescribedProperties(OWN_DESCRIPTORS, DONT_ENUM);
       int number_of_descriptors = descriptors->number_of_descriptors();
       int to_trim = number_of_descriptors - number_of_own_descriptors;
       if (to_trim > 0) {
         RightTrimFixedArray<FROM_GC>(
             heap, descriptors, to_trim * DescriptorArray::kDescriptorSize);
         if (descriptors->HasEnumCache()) {
-          FixedArray* enum_cache =
-              FixedArray::cast(descriptors->GetEnumCache());
-          to_trim = enum_cache->length() - live_enum;
-          if (to_trim > 0) {
-            RightTrimFixedArray<FROM_GC>(
- heap, FixedArray::cast(descriptors->GetEnumCache()), to_trim);
+          int live_enum =
+              NumberOfDescribedProperties(OWN_DESCRIPTORS, DONT_ENUM);
+          if (live_enum == 0) {
+            descriptors->ClearEnumCache();
+          } else {
+            FixedArray* enum_cache =
+                FixedArray::cast(descriptors->GetEnumCache());
+            to_trim = enum_cache->length() - live_enum;
+            if (to_trim > 0) {
+              RightTrimFixedArray<FROM_GC>(
+ heap, FixedArray::cast(descriptors->GetEnumCache()), to_trim);
+            }
           }
         }
         descriptors->Sort();
=======================================
--- /branches/bleeding_edge/src/objects.h       Wed Sep 12 09:43:57 2012
+++ /branches/bleeding_edge/src/objects.h       Fri Sep 14 06:15:43 2012
@@ -2508,6 +2508,8 @@
     return HeapObject::RawField(reinterpret_cast<HeapObject*>(this),
                                 kEnumCacheOffset);
   }
+
+  void ClearEnumCache();

   // Initialize or change the enum cache,
   // using the supplied storage for the small "bridge".

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to