Skip to content

Commit b549d51

Browse files
LibJS: Add Object::fast_is<Set>() and Object::fast_is<Map>()
These are often hit by object serialization code path.
1 parent aec20e0 commit b549d51

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

Libraries/LibJS/Runtime/Map.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ class JS_API Map : public Object {
2525

2626
virtual ~Map() override = default;
2727

28+
virtual bool is_map_object() const final { return true; }
29+
2830
void map_clear();
2931
bool map_remove(Value const&);
3032
Optional<Value> map_get(Value const&) const;
@@ -116,4 +118,7 @@ class JS_API Map : public Object {
116118
HashMap<Value, Value, ValueTraits> m_entries;
117119
};
118120

121+
template<>
122+
inline bool Object::fast_is<Map>() const { return is_map_object(); }
123+
119124
}

Libraries/LibJS/Runtime/Object.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ class JS_API Object : public Cell
227227
virtual bool is_ecmascript_function_object() const { return false; }
228228
virtual bool is_array_iterator() const { return false; }
229229
virtual bool is_raw_json_object() const { return false; }
230+
virtual bool is_set_object() const { return false; }
231+
virtual bool is_map_object() const { return false; }
230232

231233
virtual bool eligible_for_own_property_enumeration_fast_path() const { return true; }
232234

Libraries/LibJS/Runtime/Set.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class JS_API Set : public Object {
2424
virtual void initialize(Realm&) override;
2525
virtual ~Set() override = default;
2626

27+
virtual bool is_set_object() const final { return true; }
28+
2729
// NOTE: Unlike what the spec says, we implement Sets using an underlying map,
2830
// so all the functions below do not directly implement the operations as
2931
// defined by the specification.
@@ -59,4 +61,7 @@ struct SetRecord {
5961
ThrowCompletionOr<SetRecord> get_set_record(VM&, Value);
6062
bool set_data_has(GC::Ref<Set>, Value);
6163

64+
template<>
65+
inline bool Object::fast_is<Set>() const { return is_set_object(); }
66+
6267
}

0 commit comments

Comments
 (0)