From 8af095f7974dde5776ad55d06ca881af06d8dbe0 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Wed, 6 Aug 2025 08:03:24 +0200 Subject: [PATCH] LibWasm: Make Wasm::Validator::Stack hold a Vector instead of inheriting --- Libraries/LibWasm/AbstractMachine/Validator.h | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/Libraries/LibWasm/AbstractMachine/Validator.h b/Libraries/LibWasm/AbstractMachine/Validator.h index f06db4d950d..64b32befac4 100644 --- a/Libraries/LibWasm/AbstractMachine/Validator.h +++ b/Libraries/LibWasm/AbstractMachine/Validator.h @@ -201,21 +201,27 @@ public: // This is a wrapper that can model "polymorphic" stacks, // by treating unknown stack entries as a potentially infinite number of entries - class Stack : private Vector { + class Stack { template friend struct AK::Formatter; public: - Stack(Vector const& frames) + explicit Stack(Vector const& frames) : m_frames(frames) { } - using Vector::is_empty; - using Vector::last; - using Vector::at; - using Vector::size; - using Vector::resize; + bool is_empty() const { return m_entries.is_empty(); } + auto& last() const { return m_entries.last(); } + auto& last() { return m_entries.last(); } + auto& at(size_t index) const { return m_entries.at(index); } + auto& at(size_t index) { return m_entries.at(index); } + size_t size() const { return m_entries.size(); } + void resize(size_t size) + { + m_entries.resize(size); + m_max_known_size = max(m_max_known_size, size); + } ErrorOr take_last() { @@ -223,11 +229,11 @@ public: return StackEntry(); if (size() == m_frames.last().initial_size) return Errors::invalid("stack state"sv, ""sv, ""sv); - return Vector::take_last(); + return m_entries.take_last(); } void append(StackEntry entry) { - Vector::append(entry); + m_entries.append(entry); m_max_known_size = max(m_max_known_size, size()); } @@ -258,12 +264,13 @@ public: Vector release_vector() { m_max_known_size = 0; - return exchange(static_cast&>(*this), Vector {}); + return exchange(m_entries, Vector {}); } size_t max_known_size() const { return m_max_known_size; } private: + Vector m_entries; Vector const& m_frames; size_t m_max_known_size { 0 }; }; @@ -374,7 +381,7 @@ template<> struct AK::Formatter : public AK::Formatter> { ErrorOr format(FormatBuilder& builder, Wasm::Validator::Stack const& value) { - return Formatter>::format(builder, static_cast const&>(value)); + return Formatter>::format(builder, value.m_entries); } };