Index: src/elements.cc |
diff --git a/src/elements.cc b/src/elements.cc |
index 45be25ebd09fc499f44aaab805d551682e90b139..e1be677072bc67e58c368b1d275c8e333993005a 100644 |
--- a/src/elements.cc |
+++ b/src/elements.cc |
@@ -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. |