mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-30 20:59:16 +00:00
LibWasm: Improve table support
Implements `table.get`, `table.set`, `elem.drop`, `table.size`, and `table.grow`. Also fixes a few issues when generating ref-related spectests. Also changes the `TableInstance` type to use `Vector<Reference>` instead of `Vector<Optional<Reference>>`, because the ability to be null is already encoded in the `Reference` type.
This commit is contained in:
parent
3ca6dfba48
commit
d906255cbb
Notes:
sideshowbarker
2024-07-18 03:35:30 +09:00
Author: https://github.com/dzfrias
Commit: d906255cbb
Pull-request: https://github.com/SerenityOS/serenity/pull/24492
Reviewed-by: https://github.com/alimpfard
6 changed files with 82 additions and 29 deletions
|
@ -61,6 +61,10 @@ public:
|
|||
: m_ref(move(ref))
|
||||
{
|
||||
}
|
||||
explicit Reference()
|
||||
: m_ref(Reference::Null { ValueType(ValueType::Kind::FunctionReference) })
|
||||
{
|
||||
}
|
||||
|
||||
auto& ref() const { return m_ref; }
|
||||
|
||||
|
@ -370,7 +374,7 @@ using FunctionInstance = Variant<WasmFunction, HostFunction>;
|
|||
|
||||
class TableInstance {
|
||||
public:
|
||||
explicit TableInstance(TableType const& type, Vector<Optional<Reference>> elements)
|
||||
explicit TableInstance(TableType const& type, Vector<Reference> elements)
|
||||
: m_elements(move(elements))
|
||||
, m_type(type)
|
||||
{
|
||||
|
@ -380,15 +384,18 @@ public:
|
|||
auto& elements() { return m_elements; }
|
||||
auto& type() const { return m_type; }
|
||||
|
||||
bool grow(size_t size_to_grow, Reference const& fill_value)
|
||||
bool grow(u32 size_to_grow, Reference const& fill_value)
|
||||
{
|
||||
if (size_to_grow == 0)
|
||||
return true;
|
||||
auto new_size = m_elements.size() + size_to_grow;
|
||||
size_t 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;
|
||||
}
|
||||
if (new_size >= NumericLimits<u32>::max()) {
|
||||
return false;
|
||||
}
|
||||
auto previous_size = m_elements.size();
|
||||
if (m_elements.try_resize(new_size).is_error())
|
||||
return false;
|
||||
|
@ -398,7 +405,7 @@ public:
|
|||
}
|
||||
|
||||
private:
|
||||
Vector<Optional<Reference>> m_elements;
|
||||
Vector<Reference> m_elements;
|
||||
TableType m_type;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue