Browse Source

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.
Linus Groh 4 years ago
parent
commit
ae9d64e544

+ 7 - 0
Libraries/LibJS/Runtime/IndexedProperties.cpp

@@ -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()) {

+ 1 - 1
Libraries/LibJS/Runtime/IndexedProperties.h

@@ -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;