mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 11:36:10 +00:00
LibJS: Add fast_is<T> helpers for all the primitive wrapper objects
The JS runtime is full of checks for is<NumberObject> and friends. They were showing up in a Speedometer profile as ~1% spent in dynamic_cast, and this basically chops that down to nothing.
This commit is contained in:
parent
3cc5b1a6a5
commit
c12f8b80dc
Notes:
github-actions[bot]
2025-03-25 23:58:13 +00:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/c12f8b80dc1 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4081 Reviewed-by: https://github.com/AtkinsSJ Reviewed-by: https://github.com/shannonbooth
7 changed files with 35 additions and 0 deletions
|
@ -26,9 +26,14 @@ public:
|
|||
private:
|
||||
BigIntObject(BigInt&, Object& prototype);
|
||||
|
||||
virtual bool is_bigint_object() const final { return true; }
|
||||
|
||||
virtual void visit_edges(Visitor&) override;
|
||||
|
||||
GC::Ref<BigInt> m_bigint;
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool Object::fast_is<BigIntObject>() const { return is_bigint_object(); }
|
||||
|
||||
}
|
||||
|
|
|
@ -25,7 +25,12 @@ protected:
|
|||
BooleanObject(bool, Object& prototype);
|
||||
|
||||
private:
|
||||
virtual bool is_boolean_object() const final { return true; }
|
||||
|
||||
bool m_value { false };
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool Object::fast_is<BooleanObject>() const { return is_boolean_object(); }
|
||||
|
||||
}
|
||||
|
|
|
@ -31,9 +31,14 @@ public:
|
|||
private:
|
||||
Date(double date_value, Object& prototype);
|
||||
|
||||
virtual bool is_date() const final { return true; }
|
||||
|
||||
double m_date_value { 0 }; // [[DateValue]]
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool Object::fast_is<Date>() const { return is_date(); }
|
||||
|
||||
// 21.4.1.22 Time Zone Identifier Record, https://tc39.es/ecma262/#sec-time-zone-identifier-record
|
||||
struct TimeZoneIdentifier {
|
||||
String identifier; // [[Identifier]]
|
||||
|
|
|
@ -47,10 +47,15 @@ protected:
|
|||
explicit Error(Object& prototype);
|
||||
|
||||
private:
|
||||
virtual bool is_error() const final { return true; }
|
||||
|
||||
void populate_stack();
|
||||
Vector<TracebackFrame, 32> m_traceback;
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool Object::fast_is<Error>() const { return is_error(); }
|
||||
|
||||
// NOTE: Making these inherit from Error is not required by the spec but
|
||||
// our way of implementing the [[ErrorData]] internal slot, which is
|
||||
// used in Object.prototype.toString().
|
||||
|
|
|
@ -25,7 +25,12 @@ protected:
|
|||
NumberObject(double, Object& prototype);
|
||||
|
||||
private:
|
||||
virtual bool is_number_object() const final { return true; }
|
||||
|
||||
double m_value { 0 };
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool Object::fast_is<NumberObject>() const { return is_number_object(); }
|
||||
|
||||
}
|
||||
|
|
|
@ -190,6 +190,12 @@ public:
|
|||
|
||||
virtual bool is_dom_node() const { return false; }
|
||||
virtual bool is_function() const { return false; }
|
||||
virtual bool is_error() const { return false; }
|
||||
virtual bool is_date() const { return false; }
|
||||
virtual bool is_number_object() const { return false; }
|
||||
virtual bool is_boolean_object() const { return false; }
|
||||
virtual bool is_regexp_object() const { return false; }
|
||||
virtual bool is_bigint_object() const { return false; }
|
||||
virtual bool is_string_object() const { return false; }
|
||||
virtual bool is_global_object() const { return false; }
|
||||
virtual bool is_proxy_object() const { return false; }
|
||||
|
|
|
@ -74,6 +74,7 @@ private:
|
|||
RegExpObject(Object& prototype);
|
||||
RegExpObject(Regex<ECMA262> regex, String pattern, String flags, Object& prototype);
|
||||
|
||||
virtual bool is_regexp_object() const final { return true; }
|
||||
virtual void visit_edges(Visitor&) override;
|
||||
|
||||
String m_pattern;
|
||||
|
@ -85,6 +86,9 @@ private:
|
|||
Optional<Regex<ECMA262>> m_regex;
|
||||
};
|
||||
|
||||
template<>
|
||||
inline bool Object::fast_is<RegExpObject>() const { return is_regexp_object(); }
|
||||
|
||||
AK_ENUM_BITWISE_OPERATORS(RegExpObject::Flags);
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue