From 08ff148bc38de2db28781b6f37f55c3b1ee66421 Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Wed, 16 Jun 2021 00:01:03 +0300 Subject: [PATCH] LibJS: Use OrderedHashTable instead of HashTable in the Set built-in This ensures insertion-order iteration. --- Userland/Libraries/LibJS/Runtime/Set.h | 6 +++--- Userland/Libraries/LibJS/Runtime/SetIterator.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Set.h b/Userland/Libraries/LibJS/Runtime/Set.h index 4f3fc0cf68..ea06df52ed 100644 --- a/Userland/Libraries/LibJS/Runtime/Set.h +++ b/Userland/Libraries/LibJS/Runtime/Set.h @@ -22,13 +22,13 @@ public: explicit Set(Object& prototype); virtual ~Set() override; - HashTable const& values() const { return m_values; }; - HashTable& values() { return m_values; }; + OrderedHashTable const& values() const { return m_values; }; + OrderedHashTable& values() { return m_values; }; private: virtual void visit_edges(Visitor& visitor) override; - HashTable m_values; // FIXME: Replace with a HashTable that maintains a linked list of insertion order for correct iteration order + OrderedHashTable m_values; }; } diff --git a/Userland/Libraries/LibJS/Runtime/SetIterator.h b/Userland/Libraries/LibJS/Runtime/SetIterator.h index 873d81676f..114316339d 100644 --- a/Userland/Libraries/LibJS/Runtime/SetIterator.h +++ b/Userland/Libraries/LibJS/Runtime/SetIterator.h @@ -33,7 +33,7 @@ private: Set& m_set; bool m_done { false }; Object::PropertyKind m_iteration_kind; - HashTable::Iterator m_iterator; + OrderedHashTable::Iterator m_iterator; }; }