1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:37:36 +00:00

LibJS: Implement Sets using Maps

This implements ordered sets using Maps with a sentinel value, and
includes some extra set tests.
Fixes #11004.

Co-Authored-By: davidot <davidot@serenityos.org>
This commit is contained in:
Ali Mohammad Pur 2022-02-09 18:34:16 +03:30 committed by Linus Groh
parent 4a73ec07c5
commit 3bfcd7b52d
8 changed files with 133 additions and 21 deletions

View file

@ -375,13 +375,12 @@ static void print_map(JS::Object const& object, HashTable<JS::Object*>& seen_obj
static void print_set(JS::Object const& object, HashTable<JS::Object*>& seen_objects)
{
auto& set = static_cast<JS::Set const&>(object);
auto& values = set.values();
print_type("Set");
js_out(" {{");
bool first = true;
for (auto& value : values) {
for (auto& entry : set) {
print_separator(first);
print_value(value, seen_objects);
print_value(entry.key, seen_objects);
}
if (!first)
js_out(" ");