diff options
author | Andreas Kling <kling@serenityos.org> | 2021-10-07 12:05:13 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-10-07 12:05:13 +0200 |
commit | df674023d67759b04bb83d43714dcf0857cd18ec (patch) | |
tree | 5f2172dcb9abe480a15ebab3465b65db12b684b1 /Userland/Libraries/LibJS | |
parent | 41a072bded25b0993f315bc86e11cae8419f3231 (diff) | |
download | serenity-df674023d67759b04bb83d43714dcf0857cd18ec.zip |
LibJS: Add fast_is<T>() for FunctionExpression and ClassExpression
Spotted RTTI for these two above 1% in a profile.
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r-- | Userland/Libraries/LibJS/AST.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/AST.h b/Userland/Libraries/LibJS/AST.h index acb8851fbe..f80035f926 100644 --- a/Userland/Libraries/LibJS/AST.h +++ b/Userland/Libraries/LibJS/AST.h @@ -63,6 +63,8 @@ public: virtual bool is_new_expression() const { return false; } virtual bool is_member_expression() const { return false; } virtual bool is_super_expression() const { return false; } + virtual bool is_function_expression() const { return false; } + virtual bool is_class_expression() const { return false; } virtual bool is_expression_statement() const { return false; } virtual bool is_identifier() const { return false; } virtual bool is_scope_node() const { return false; } @@ -521,6 +523,9 @@ public: bool has_name() const { return !name().is_empty(); } Value instantiate_ordinary_function_expression(Interpreter& interpreter, GlobalObject& global_object, FlyString given_name) const; + +private: + virtual bool is_function_expression() const override { return true; } }; class ErrorExpression final : public Expression { @@ -1079,6 +1084,8 @@ public: ThrowCompletionOr<Value> class_definition_evaluation(Interpreter& interpreter, GlobalObject& global_object, FlyString const& binding_name = {}, FlyString const& class_name = {}) const; private: + virtual bool is_class_expression() const override { return true; } + String m_name; RefPtr<FunctionExpression> m_constructor; RefPtr<Expression> m_super_class; @@ -1763,6 +1770,12 @@ template<> inline bool ASTNode::fast_is<SuperExpression>() const { return is_super_expression(); } template<> +inline bool ASTNode::fast_is<FunctionExpression>() const { return is_function_expression(); } + +template<> +inline bool ASTNode::fast_is<ClassExpression>() const { return is_class_expression(); } + +template<> inline bool ASTNode::fast_is<Identifier>() const { return is_identifier(); } template<> |