/* * Copyright (c) 2021, Idan Horowitz * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include namespace JS { struct ValueTraits : public Traits { static unsigned hash(Value value) { VERIFY(!value.is_empty()); if (value.is_string()) return value.as_string().string().hash(); if (value.is_bigint()) return value.as_bigint().big_integer().hash(); return u64_hash(value.encoded()); // FIXME: Is this the best way to hash pointers, doubles & ints? } static bool equals(const Value a, const Value b) { return same_value_zero(a, b); } }; class Set : public Object { JS_OBJECT(Set, Object); public: static Set* create(GlobalObject&); explicit Set(Object& prototype); virtual ~Set() override; static Set* typed_this(VM&, GlobalObject&); HashTable const& values() const { return m_values; }; HashTable& values() { return m_values; }; private: HashTable m_values; // FIXME: Replace with a HashTable that maintains a linked list of insertion order for correct iteration order }; }