1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:17:45 +00:00

LibWeb+LibWasm: Implement the WebAssembly.Table object

This commit is contained in:
Ali Mohammad Pur 2021-09-04 04:40:57 +04:30 committed by Ali Mohammad Pur
parent d52a26de3f
commit 09dd397160
9 changed files with 433 additions and 1 deletions

View file

@ -301,6 +301,23 @@ public:
auto& elements() { return m_elements; }
auto& type() const { return m_type; }
bool grow(size_t size_to_grow, Reference const& fill_value)
{
if (size_to_grow == 0)
return true;
auto new_size = m_elements.size() + size_to_grow;
if (auto max = m_type.limits().max(); max.has_value()) {
if (max.value() < new_size)
return false;
}
auto previous_size = m_elements.size();
if (!m_elements.try_resize(new_size))
return false;
for (size_t i = previous_size; i < m_elements.size(); ++i)
m_elements[i] = fill_value;
return true;
}
private:
Vector<Optional<Reference>> m_elements;
TableType const& m_type;