LibJS: Let set_array_like_size() switch to generic storage if necessary

This is already considered in put()/insert()/append_all() but not
set_array_like_size(), which crashed the interpreter with an assertion
when creating an array with more than SPARSE_ARRAY_THRESHOLD (200)
initial elements as the simple storage was being resized beyond its
limit.

Fixes #3382.
This commit is contained in:
Linus Groh 2020-09-01 19:45:29 +01:00 committed by Andreas Kling
parent 28ff8f3376
commit ae9d64e544
2 changed files with 8 additions and 1 deletions

View file

@ -346,6 +346,13 @@ void IndexedProperties::append_all(Object* this_object, const IndexedProperties&
}
}
void IndexedProperties::set_array_like_size(size_t new_size)
{
if (m_storage->is_simple_storage() && new_size > SPARSE_ARRAY_THRESHOLD)
switch_to_generic_storage();
m_storage->set_array_like_size(new_size);
}
Vector<ValueAndAttributes> IndexedProperties::values_unordered() const
{
if (m_storage->is_simple_storage()) {

View file

@ -162,7 +162,7 @@ public:
size_t size() const { return m_storage->size(); }
bool is_empty() const { return size() == 0; }
size_t array_like_size() const { return m_storage->array_like_size(); }
void set_array_like_size(size_t new_size) { m_storage->set_array_like_size(new_size); };
void set_array_like_size(size_t);
Vector<ValueAndAttributes> values_unordered() const;