m_vectorLength = initialCapacity;
m_storage->m_numValuesInVector = 0;
m_storage->m_sparseValueMap = 0;
- m_storage->lazyCreationData = 0;
+ m_storage->subclassData = 0;
m_storage->reportedMapCapacity = 0;
JSValue* vector = m_storage->m_vector;
m_vectorLength = initialCapacity;
m_storage->m_numValuesInVector = initialCapacity;
m_storage->m_sparseValueMap = 0;
- m_storage->lazyCreationData = 0;
+ m_storage->subclassData = 0;
m_storage->reportedMapCapacity = 0;
size_t i = 0;
return (da > db) - (da < db);
}
-typedef std::pair<JSValue, UString> ValueStringPair;
-
static int compareByStringPairForQSort(const void* a, const void* b)
{
const ValueStringPair* va = static_cast<const ValueStringPair*>(a);
throwOutOfMemoryError(exec);
return;
}
+
+ Heap::heap(this)->pushTempSortVector(&values);
for (size_t i = 0; i < lengthNotIncludingUndefined; i++) {
JSValue value = m_storage->m_vector[i];
values[i].first = value;
}
- // FIXME: While calling these toString functions, the array could be mutated.
- // In that case, objects pointed to by values in this vector might get garbage-collected!
-
// FIXME: The following loop continues to call toString on subsequent values even after
// a toString call raises an exception.
for (size_t i = 0; i < lengthNotIncludingUndefined; i++)
values[i].second = values[i].first.toString(exec);
- if (exec->hadException())
+ if (exec->hadException()) {
+ Heap::heap(this)->popTempSortVector(&values);
return;
+ }
// FIXME: Since we sort by string value, a fast algorithm might be to use a radix sort. That would be O(N) rather
// than O(N log N).
qsort(values.begin(), values.size(), sizeof(ValueStringPair), compareByStringPairForQSort);
#endif
- // FIXME: If the toString function changed the length of the array, this might be
- // modifying the vector incorrectly.
-
+ // If the toString function changed the length of the array or vector storage,
+ // increase the length to handle the orignal number of actual values.
+ if (m_vectorLength < lengthNotIncludingUndefined)
+ increaseVectorLength(lengthNotIncludingUndefined);
+ if (m_storage->m_length < lengthNotIncludingUndefined)
+ m_storage->m_length = lengthNotIncludingUndefined;
+
for (size_t i = 0; i < lengthNotIncludingUndefined; i++)
m_storage->m_vector[i] = values[i].first;
+ Heap::heap(this)->popTempSortVector(&values);
+
checkConsistency(SortConsistencyCheck);
}
void JSArray::copyToRegisters(ExecState* exec, Register* buffer, uint32_t maxSize)
{
- ASSERT(m_storage->m_length == maxSize);
+ ASSERT(m_storage->m_length >= maxSize);
UNUSED_PARAM(maxSize);
JSValue* vector = m_storage->m_vector;
- unsigned vectorEnd = min(m_storage->m_length, m_vectorLength);
+ unsigned vectorEnd = min(maxSize, m_vectorLength);
unsigned i = 0;
for (; i < vectorEnd; ++i) {
JSValue& v = vector[i];
buffer[i] = v;
}
- for (; i < m_storage->m_length; ++i)
+ for (; i < maxSize; ++i)
buffer[i] = get(exec, i);
}
return numDefined;
}
-void* JSArray::lazyCreationData()
+void* JSArray::subclassData() const
{
- return m_storage->lazyCreationData;
+ return m_storage->subclassData;
}
-void JSArray::setLazyCreationData(void* d)
+void JSArray::setSubclassData(void* d)
{
- m_storage->lazyCreationData = d;
+ m_storage->subclassData = d;
}
#if CHECK_ARRAY_CONSISTENCY