Consistently order receiver and holder argument in ElementAccessor.
authordanno@chromium.org <danno@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 6 Mar 2012 12:22:18 +0000 (12:22 +0000)
committerdanno@chromium.org <danno@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 6 Mar 2012 12:22:18 +0000 (12:22 +0000)
R=jkummerow@chromium.org

Review URL: https://chromiumcodereview.appspot.com/9605006

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10943 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/elements.cc
src/elements.h
src/objects.cc

index 45be25ebd09fc499f44aaab805d551682e90b139..e1be677072bc67e58c368b1d275c8e333993005a 100644 (file)
@@ -105,33 +105,56 @@ template <typename ElementsAccessorSubclass, typename BackingStoreClass>
 class ElementsAccessorBase : public ElementsAccessor {
  protected:
   explicit ElementsAccessorBase(const char* name) : ElementsAccessor(name) { }
-  virtual MaybeObject* Get(FixedArrayBase* backing_store,
+
+  static bool HasElementImpl(Object* receiver,
+                             JSObject* holder,
+                             uint32_t key,
+                             BackingStoreClass* backing_store) {
+    MaybeObject* element =
+        ElementsAccessorSubclass::GetImpl(receiver, holder, key, backing_store);
+    return !element->IsTheHole();
+  }
+
+  virtual bool HasElement(Object* receiver,
+                          JSObject* holder,
+                          uint32_t key,
+                          FixedArrayBase* backing_store) {
+    if (backing_store == NULL) {
+      backing_store = holder->elements();
+    }
+    return ElementsAccessorSubclass::HasElementImpl(
+        receiver, holder, key, BackingStoreClass::cast(backing_store));
+  }
+
+  virtual MaybeObject* Get(Object* receiver,
+                           JSObject* holder,
                            uint32_t key,
-                           JSObject* obj,
-                           Object* receiver) {
+                           FixedArrayBase* backing_store) {
+    if (backing_store == NULL) {
+      backing_store = holder->elements();
+    }
     return ElementsAccessorSubclass::GetImpl(
-        BackingStoreClass::cast(backing_store), key, obj, receiver);
+        receiver, holder, key, BackingStoreClass::cast(backing_store));
   }
 
-  static MaybeObject* GetImpl(BackingStoreClass* backing_store,
-                              uint32_t key,
+  static MaybeObject* GetImpl(Object* receiver,
                               JSObject* obj,
-                              Object* receiver) {
+                              uint32_t key,
+                              BackingStoreClass* backing_store) {
     return (key < ElementsAccessorSubclass::GetCapacityImpl(backing_store))
            ? backing_store->get(key)
            : backing_store->GetHeap()->the_hole_value();
   }
 
-  virtual MaybeObject* SetLength(JSObject* obj,
+  virtual MaybeObject* SetLength(JSArray* array,
                                  Object* length) {
-    ASSERT(obj->IsJSArray());
     return ElementsAccessorSubclass::SetLengthImpl(
-        BackingStoreClass::cast(obj->elements()), obj, length);
+        array, length, BackingStoreClass::cast(array->elements()));
   }
 
-  static MaybeObject* SetLengthImpl(BackingStoreClass* backing_store,
-                                    JSObject* obj,
-                                    Object* length);
+  static MaybeObject* SetLengthImpl(JSObject* obj,
+                                    Object* length,
+                                    BackingStoreClass* backing_store);
 
   virtual MaybeObject* SetCapacityAndLength(JSArray* array,
                                             int capacity,
@@ -153,10 +176,10 @@ class ElementsAccessorBase : public ElementsAccessor {
                               uint32_t key,
                               JSReceiver::DeleteMode mode) = 0;
 
-  virtual MaybeObject* AddElementsToFixedArray(FixedArrayBase* from,
-                                               FixedArray* to,
+  virtual MaybeObject* AddElementsToFixedArray(Object* receiver,
                                                JSObject* holder,
-                                               Object* receiver) {
+                                               FixedArray* to,
+                                               FixedArrayBase* from) {
     int len0 = to->length();
 #ifdef DEBUG
     if (FLAG_enable_slow_asserts) {
@@ -165,6 +188,9 @@ class ElementsAccessorBase : public ElementsAccessor {
       }
     }
 #endif
+    if (from == NULL) {
+      from = holder->elements();
+    }
     BackingStoreClass* backing_store = BackingStoreClass::cast(from);
     uint32_t len1 = ElementsAccessorSubclass::GetCapacityImpl(backing_store);
 
@@ -178,10 +204,10 @@ class ElementsAccessorBase : public ElementsAccessor {
       uint32_t key =
           ElementsAccessorSubclass::GetKeyForIndexImpl(backing_store, y);
       if (ElementsAccessorSubclass::HasElementImpl(
-              backing_store, key, holder, receiver)) {
+              receiver, holder, key, backing_store)) {
         MaybeObject* maybe_value =
-            ElementsAccessorSubclass::GetImpl(backing_store, key,
-                                              holder, receiver);
+            ElementsAccessorSubclass::GetImpl(receiver, holder,
+                                              key, backing_store);
         Object* value;
         if (!maybe_value->ToObject(&value)) return maybe_value;
         ASSERT(!value->IsTheHole());
@@ -215,10 +241,10 @@ class ElementsAccessorBase : public ElementsAccessor {
       uint32_t key =
           ElementsAccessorSubclass::GetKeyForIndexImpl(backing_store, y);
       if (ElementsAccessorSubclass::HasElementImpl(
-          backing_store, key, holder, receiver)) {
+              receiver, holder, key, backing_store)) {
         MaybeObject* maybe_value =
-            ElementsAccessorSubclass::GetImpl(backing_store, key,
-                                              holder, receiver);
+            ElementsAccessorSubclass::GetImpl(receiver, holder,
+                                              key, backing_store);
         Object* value;
         if (!maybe_value->ToObject(&value)) return maybe_value;
         if (!value->IsTheHole() && !HasKey(to, value)) {
@@ -241,23 +267,6 @@ class ElementsAccessorBase : public ElementsAccessor {
         BackingStoreClass::cast(backing_store));
   }
 
-  static bool HasElementImpl(BackingStoreClass* backing_store,
-                             uint32_t key,
-                             JSObject* holder,
-                             Object* receiver) {
-    MaybeObject* element =
-        ElementsAccessorSubclass::GetImpl(backing_store, key, holder, receiver);
-    return !element->IsTheHole();
-  }
-
-  virtual bool HasElement(FixedArrayBase* backing_store,
-                          uint32_t key,
-                          JSObject* holder,
-                          Object* receiver) {
-    return ElementsAccessorSubclass::HasElementImpl(
-        BackingStoreClass::cast(backing_store), key, holder, receiver);
-  }
-
   static uint32_t GetKeyForIndexImpl(BackingStoreClass* backing_store,
                                      uint32_t index) {
     return index;
@@ -454,10 +463,10 @@ class FastDoubleElementsAccessor
     return obj->GetHeap()->true_value();
   }
 
-  static bool HasElementImpl(FixedDoubleArray* backing_store,
-                             uint32_t key,
+  static bool HasElementImpl(Object* receiver,
                              JSObject* holder,
-                             Object* receiver) {
+                             uint32_t key,
+                             FixedDoubleArray* backing_store) {
     return !backing_store->is_the_hole(key);
   }
 };
@@ -478,19 +487,19 @@ class ExternalElementsAccessor
   friend class ElementsAccessorBase<ExternalElementsAccessorSubclass,
                                     ExternalArray>;
 
-  static MaybeObject* GetImpl(ExternalArray* backing_store,
-                              uint32_t key,
+  static MaybeObject* GetImpl(Object* receiver,
                               JSObject* obj,
-                              Object* receiver) {
+                              uint32_t key,
+                              ExternalArray* backing_store) {
     return
         key < ExternalElementsAccessorSubclass::GetCapacityImpl(backing_store)
         ? backing_store->get(key)
         : backing_store->GetHeap()->undefined_value();
   }
 
-  static MaybeObject* SetLengthImpl(ExternalArray* backing_store,
-                                    JSObject* obj,
-                                    Object* length) {
+  static MaybeObject* SetLengthImpl(JSObject* obj,
+                                    Object* length,
+                                    ExternalArray* backing_store) {
     // External arrays do not support changing their length.
     UNREACHABLE();
     return obj;
@@ -503,10 +512,10 @@ class ExternalElementsAccessor
     return obj->GetHeap()->true_value();
   }
 
-  static bool HasElementImpl(ExternalArray* backing_store,
-                             uint32_t key,
+  static bool HasElementImpl(Object* receiver,
                              JSObject* holder,
-                             Object* receiver) {
+                             uint32_t key,
+                             ExternalArray* backing_store) {
     uint32_t capacity =
         ExternalElementsAccessorSubclass::GetCapacityImpl(backing_store);
     return key < capacity;
@@ -724,10 +733,10 @@ class DictionaryElementsAccessor
     return DeleteCommon(obj, key, mode);
   }
 
-  static MaybeObject* GetImpl(SeededNumberDictionary* backing_store,
-                              uint32_t key,
+  static MaybeObject* GetImpl(Object* receiver,
                               JSObject* obj,
-                              Object* receiver) {
+                              uint32_t key,
+                              SeededNumberDictionary* backing_store) {
     int entry = backing_store->FindEntry(key);
     if (entry != SeededNumberDictionary::kNotFound) {
       Object* element = backing_store->ValueAt(entry);
@@ -744,10 +753,10 @@ class DictionaryElementsAccessor
     return obj->GetHeap()->the_hole_value();
   }
 
-  static bool HasElementImpl(SeededNumberDictionary* backing_store,
-                             uint32_t key,
+  static bool HasElementImpl(Object* receiver,
                              JSObject* holder,
-                             Object* receiver) {
+                             uint32_t key,
+                             SeededNumberDictionary* backing_store) {
     return backing_store->FindEntry(key) !=
         SeededNumberDictionary::kNotFound;
   }
@@ -771,10 +780,10 @@ class NonStrictArgumentsElementsAccessor
   friend class ElementsAccessorBase<NonStrictArgumentsElementsAccessor,
                                     FixedArray>;
 
-  static MaybeObject* GetImpl(FixedArray* parameter_map,
-                              uint32_t key,
+  static MaybeObject* GetImpl(Object* receiver,
                               JSObject* obj,
-                              Object* receiver) {
+                              uint32_t key,
+                              FixedArray* parameter_map) {
     Object* probe = GetParameterMapArg(obj, parameter_map, key);
     if (!probe->IsTheHole()) {
       Context* context = Context::cast(parameter_map->get(0));
@@ -785,7 +794,7 @@ class NonStrictArgumentsElementsAccessor
       // Object is not mapped, defer to the arguments.
       FixedArray* arguments = FixedArray::cast(parameter_map->get(1));
       MaybeObject* maybe_result = ElementsAccessor::ForArray(arguments)->Get(
-          arguments, key, obj, receiver);
+          receiver, obj, key, arguments);
       Object* result;
       if (!maybe_result->ToObject(&result)) return maybe_result;
       // Elements of the arguments object in slow mode might be slow aliases.
@@ -801,9 +810,9 @@ class NonStrictArgumentsElementsAccessor
     }
   }
 
-  static MaybeObject* SetLengthImpl(FixedArray* parameter_map,
-                                    JSObject* obj,
-                                    Object* length) {
+  static MaybeObject* SetLengthImpl(JSObject* obj,
+                                    Object* length,
+                                    FixedArray* parameter_map) {
     // TODO(mstarzinger): This was never implemented but will be used once we
     // correctly implement [[DefineOwnProperty]] on arrays.
     UNIMPLEMENTED();
@@ -842,17 +851,17 @@ class NonStrictArgumentsElementsAccessor
     return index;
   }
 
-  static bool HasElementImpl(FixedArray* parameter_map,
-                             uint32_t key,
+  static bool HasElementImpl(Object* receiver,
                              JSObject* holder,
-                             Object* receiver) {
+                             uint32_t key,
+                             FixedArray* parameter_map) {
     Object* probe = GetParameterMapArg(holder, parameter_map, key);
     if (!probe->IsTheHole()) {
       return true;
     } else {
       FixedArrayBase* arguments = FixedArrayBase::cast(parameter_map->get(1));
       ElementsAccessor* accessor = ElementsAccessor::ForArray(arguments);
-      return !accessor->Get(arguments, key, holder, receiver)->IsTheHole();
+      return !accessor->Get(receiver, holder, key, arguments)->IsTheHole();
     }
   }
 
@@ -952,9 +961,9 @@ void ElementsAccessor::InitializeOncePerProcess() {
 
 template <typename ElementsAccessorSubclass, typename BackingStoreClass>
 MaybeObject* ElementsAccessorBase<ElementsAccessorSubclass, BackingStoreClass>::
-    SetLengthImpl(BackingStoreClass* backing_store,
-                  JSObject* obj,
-                  Object* length) {
+    SetLengthImpl(JSObject* obj,
+                  Object* length,
+                  BackingStoreClass* backing_store) {
   JSArray* array = JSArray::cast(obj);
 
   // Fast case: The new length fits into a Smi.
index c6d2d4b3bb340a18d3f3da1101859125ebfc7e59..036df5f709459aa81f6cfadbe6553357740c9382 100644 (file)
@@ -42,17 +42,32 @@ class ElementsAccessor {
 
   virtual const char* name() const { return name_; }
 
-  virtual MaybeObject* Get(FixedArrayBase* backing_store,
-                           uint32_t key,
+  // Returns true if a holder contains an element with the specified key
+  // without iterating up the prototype chain.  The caller can optionally pass
+  // in the backing store to use for the check, which must be compatible with
+  // the ElementsKind of the ElementsAccessor. If backing_store is NULL, the
+  // holder->elements() is used as the backing store.
+  virtual bool HasElement(Object* receiver,
+                          JSObject* holder,
+                          uint32_t key,
+                          FixedArrayBase* backing_store = NULL) = 0;
+
+  // Returns the element with the specified key or undefined if there is no such
+  // element. This method doesn't iterate up the prototype chain.  The caller
+  // can optionally pass in the backing store to use for the check, which must
+  // be compatible with the ElementsKind of the ElementsAccessor. If
+  // backing_store is NULL, the holder->elements() is used as the backing store.
+  virtual MaybeObject* Get(Object* receiver,
                            JSObject* holder,
-                           Object* receiver) = 0;
+                           uint32_t key,
+                           FixedArrayBase* backing_store = NULL) = 0;
 
   // Modifies the length data property as specified for JSArrays and resizes the
   // underlying backing store accordingly. The method honors the semantics of
   // changing array sizes as defined in EcmaScript 5.1 15.4.5.2, i.e. array that
   // have non-deletable elements can only be shrunk to the size of highest
   // element that is non-deletable.
-  virtual MaybeObject* SetLength(JSObject* holder,
+  virtual MaybeObject* SetLength(JSArray* holder,
                                  Object* new_length) = 0;
 
   // Modifies both the length and capacity of a JSArray, resizing the underlying
@@ -65,19 +80,15 @@ class ElementsAccessor {
                                             int capacity,
                                             int length) = 0;
 
+  // Deletes an element in an object, returning a new elements backing store.
   virtual MaybeObject* Delete(JSObject* holder,
                               uint32_t key,
                               JSReceiver::DeleteMode mode) = 0;
 
-  virtual bool HasElement(FixedArrayBase* backing_store,
-                          uint32_t key,
-                          JSObject* holder,
-                          Object* receiver) = 0;
-
-  virtual MaybeObject* AddElementsToFixedArray(FixedArrayBase* from,
-                                               FixedArray* to,
+  virtual MaybeObject* AddElementsToFixedArray(Object* receiver,
                                                JSObject* holder,
-                                               Object* receiver) = 0;
+                                               FixedArray* to,
+                                               FixedArrayBase* from = NULL) = 0;
 
   // Returns a shared ElementsAccessor for the specified ElementsKind.
   static ElementsAccessor* ForKind(ElementsKind elements_kind) {
index 5205bcb35bbdb781edf82f74661336fb43d4e1c7..940120541e4ca51be3861fa72dca83c97b44fa80 100644 (file)
@@ -691,10 +691,7 @@ MaybeObject* Object::GetElementWithReceiver(Object* receiver, uint32_t index) {
 
     if (js_object->elements() != heap->empty_fixed_array()) {
       MaybeObject* result = js_object->GetElementsAccessor()->Get(
-          js_object->elements(),
-          index,
-          js_object,
-          receiver);
+          receiver, js_object, index);
       if (result != heap->the_hole_value()) return result;
     }
   }
@@ -5551,7 +5548,7 @@ MaybeObject* PolymorphicCodeCacheHashTable::Put(MapHandleList* maps,
 MaybeObject* FixedArray::AddKeysFromJSArray(JSArray* array) {
   ElementsAccessor* accessor = array->GetElementsAccessor();
   MaybeObject* maybe_result =
-      accessor->AddElementsToFixedArray(array->elements(), this, array, array);
+      accessor->AddElementsToFixedArray(array, array, this);
   FixedArray* result;
   if (!maybe_result->To<FixedArray>(&result)) return maybe_result;
 #ifdef DEBUG
@@ -5569,7 +5566,7 @@ MaybeObject* FixedArray::AddKeysFromJSArray(JSArray* array) {
 MaybeObject* FixedArray::UnionOfKeys(FixedArray* other) {
   ElementsAccessor* accessor = ElementsAccessor::ForArray(other);
   MaybeObject* maybe_result =
-      accessor->AddElementsToFixedArray(other, this, NULL, NULL);
+      accessor->AddElementsToFixedArray(NULL, NULL, this, other);
   FixedArray* result;
   if (!maybe_result->To<FixedArray>(&result)) return maybe_result;
 #ifdef DEBUG
@@ -8895,7 +8892,7 @@ bool JSObject::HasElementWithInterceptor(JSReceiver* receiver, uint32_t index) {
   }
 
   if (holder_handle->GetElementsAccessor()->HasElement(
-          holder_handle->elements(), index, *holder_handle, *receiver_handle)) {
+          *receiver_handle, *holder_handle, index)) {
     return true;
   }
 
@@ -9033,7 +9030,7 @@ bool JSObject::HasElementWithReceiver(JSReceiver* receiver, uint32_t index) {
   }
 
   ElementsAccessor* accessor = GetElementsAccessor();
-  if (accessor->HasElement(elements(), index, this, receiver)) {
+  if (accessor->HasElement(receiver, this, index)) {
     return true;
   }
 
@@ -9894,10 +9891,9 @@ MaybeObject* JSObject::GetElementWithInterceptor(Object* receiver,
 
   Heap* heap = holder_handle->GetHeap();
   ElementsAccessor* handler = holder_handle->GetElementsAccessor();
-  MaybeObject* raw_result = handler->Get(holder_handle->elements(),
-                                         index,
+  MaybeObject* raw_result = handler->Get(*this_handle,
                                          *holder_handle,
-                                         *this_handle);
+                                         index);
   if (raw_result != heap->the_hole_value()) return raw_result;
 
   RETURN_IF_SCHEDULED_EXCEPTION(isolate);