diff options
author | davidot <david.tuin@gmail.com> | 2021-06-25 16:55:38 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-06-26 18:16:53 +0100 |
commit | b38fb418f8bbecdc10500f8436ad613fb0e36f35 (patch) | |
tree | eda3cf8fb77a1d7e2c48bb27199caf750561eb68 /Userland/Libraries/LibJS/Runtime/IndexedProperties.cpp | |
parent | c7aaf40a3596f3220d9bf6dd8b7247086f5dff74 (diff) | |
download | serenity-b38fb418f8bbecdc10500f8436ad613fb0e36f35.zip |
LibJS: Don't remove non-configurable items in Array when setting length
Diffstat (limited to 'Userland/Libraries/LibJS/Runtime/IndexedProperties.cpp')
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/IndexedProperties.cpp | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/IndexedProperties.cpp b/Userland/Libraries/LibJS/Runtime/IndexedProperties.cpp index a8d50882d0..ae492d600c 100644 --- a/Userland/Libraries/LibJS/Runtime/IndexedProperties.cpp +++ b/Userland/Libraries/LibJS/Runtime/IndexedProperties.cpp @@ -168,13 +168,32 @@ ValueAndAttributes GenericIndexedPropertyStorage::take_last() void GenericIndexedPropertyStorage::set_array_like_size(size_t new_size) { - m_array_size = new_size; + if (new_size == m_array_size) + return; + + if (new_size >= m_array_size) { + m_array_size = new_size; + return; + } + + size_t highest_index = 0; + bool any_left = false; HashMap<u32, ValueAndAttributes> new_sparse_elements; for (auto& entry : m_sparse_elements) { - if (entry.key < new_size) + if (entry.key < new_size || !entry.value.attributes.is_configurable()) { new_sparse_elements.set(entry.key, entry.value); + any_left = true; + highest_index = max(highest_index, (size_t)entry.key); + } } + + if (any_left) { + m_array_size = max(highest_index + 1, new_size); + } else { + m_array_size = new_size; + } + m_sparse_elements = move(new_sparse_elements); } |