2021-06-09 00:08:47 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Idan Horowitz <idan.horowitz@serenityos.org>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <LibJS/Runtime/GlobalObject.h>
|
2022-02-09 18:34:16 +03:30
|
|
|
#include <LibJS/Runtime/Map.h>
|
2021-06-09 00:08:47 +03:00
|
|
|
#include <LibJS/Runtime/Object.h>
|
|
|
|
#include <LibJS/Runtime/Value.h>
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
|
|
|
class Set : public Object {
|
|
|
|
JS_OBJECT(Set, Object);
|
|
|
|
|
|
|
|
public:
|
2022-08-16 00:20:49 +01:00
|
|
|
static Set* create(Realm&);
|
2021-06-09 00:08:47 +03:00
|
|
|
|
2022-11-30 09:18:27 -05:00
|
|
|
virtual void initialize(Realm&) override;
|
2022-03-14 10:25:06 -06:00
|
|
|
virtual ~Set() override = default;
|
2021-06-09 00:08:47 +03:00
|
|
|
|
2022-02-09 18:34:16 +03:30
|
|
|
// NOTE: Unlike what the spec says, we implement Sets using an underlying map,
|
|
|
|
// so all the functions below do not directly implement the operations as
|
|
|
|
// defined by the specification.
|
|
|
|
|
2022-11-30 09:18:27 -05:00
|
|
|
void set_clear() { m_values->map_clear(); }
|
|
|
|
bool set_remove(Value const& value) { return m_values->map_remove(value); }
|
|
|
|
bool set_has(Value const& key) const { return m_values->map_has(key); }
|
|
|
|
void set_add(Value const& key) { m_values->map_set(key, js_undefined()); }
|
|
|
|
size_t set_size() const { return m_values->map_size(); }
|
2022-02-09 18:34:16 +03:30
|
|
|
|
2022-11-30 09:18:27 -05:00
|
|
|
auto begin() const { return const_cast<Map const&>(*m_values).begin(); }
|
|
|
|
auto begin() { return m_values->begin(); }
|
|
|
|
auto end() const { return m_values->end(); }
|
2021-06-09 00:08:47 +03:00
|
|
|
|
|
|
|
private:
|
2022-08-28 23:51:28 +02:00
|
|
|
explicit Set(Object& prototype);
|
|
|
|
|
2021-06-09 18:01:06 +03:00
|
|
|
virtual void visit_edges(Visitor& visitor) override;
|
|
|
|
|
2022-11-30 09:18:27 -05:00
|
|
|
GCPtr<Map> m_values;
|
2021-06-09 00:08:47 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|