LibJS: Add Object::fast_is<Set>() and Object::fast_is<Map>()

These are often hit by object serialization code path.
This commit is contained in:
Aliaksandr Kalenik 2025-09-25 18:12:16 +02:00 committed by Alexander Kalenik
parent aec20e032b
commit b549d51cdc
Notes: github-actions[bot] 2025-09-26 15:27:03 +00:00
3 changed files with 12 additions and 0 deletions

View file

@ -25,6 +25,8 @@ public:
virtual ~Map() override = default;
virtual bool is_map_object() const final { return true; }
void map_clear();
bool map_remove(Value const&);
Optional<Value> map_get(Value const&) const;
@ -116,4 +118,7 @@ private:
HashMap<Value, Value, ValueTraits> m_entries;
};
template<>
inline bool Object::fast_is<Map>() const { return is_map_object(); }
}

View file

@ -227,6 +227,8 @@ public:
virtual bool is_ecmascript_function_object() const { return false; }
virtual bool is_array_iterator() const { return false; }
virtual bool is_raw_json_object() const { return false; }
virtual bool is_set_object() const { return false; }
virtual bool is_map_object() const { return false; }
virtual bool eligible_for_own_property_enumeration_fast_path() const { return true; }

View file

@ -24,6 +24,8 @@ public:
virtual void initialize(Realm&) override;
virtual ~Set() override = default;
virtual bool is_set_object() const final { return true; }
// 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.
@ -59,4 +61,7 @@ struct SetRecord {
ThrowCompletionOr<SetRecord> get_set_record(VM&, Value);
bool set_data_has(GC::Ref<Set>, Value);
template<>
inline bool Object::fast_is<Set>() const { return is_set_object(); }
}