diff --git a/Userland/Libraries/LibJS/AST.h b/Userland/Libraries/LibJS/AST.h index 5f459fd9871..62ae3d13de8 100644 --- a/Userland/Libraries/LibJS/AST.h +++ b/Userland/Libraries/LibJS/AST.h @@ -50,6 +50,17 @@ public: String class_name() const; + template + bool fast_is() const = delete; + + 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_expression_statement() const { return false; } + virtual bool is_identifier() const { return false; } + virtual bool is_scope_node() const { return false; } + virtual bool is_program() const { return false; } + protected: ASTNode(SourceRange source_range) : m_source_range(move(source_range)) @@ -108,6 +119,8 @@ public: Expression const& expression() const { return m_expression; }; private: + virtual bool is_expression_statement() const override { return true; } + NonnullRefPtr m_expression; }; @@ -142,6 +155,8 @@ protected: } private: + virtual bool is_scope_node() const final { return true; } + NonnullRefPtrVector m_children; NonnullRefPtrVector m_variables; NonnullRefPtrVector m_functions; @@ -160,6 +175,8 @@ public: void set_strict_mode() { m_is_strict_mode = true; } private: + virtual bool is_program() const override { return true; } + bool m_is_strict_mode { false }; }; @@ -765,6 +782,8 @@ public: virtual void generate_bytecode(Bytecode::Generator&) const override; private: + virtual bool is_identifier() const override { return true; } + FlyString m_string; }; @@ -808,6 +827,8 @@ public: virtual Value execute(Interpreter&, GlobalObject&) const override; virtual void dump(int indent) const override; + + virtual bool is_super_expression() const override { return true; } }; class ClassExpression final : public Expression { @@ -908,6 +929,8 @@ public: : CallExpression(move(source_range), move(callee), move(arguments)) { } + + virtual bool is_new_expression() const override { return true; } }; enum class AssignmentOp { @@ -1176,6 +1199,8 @@ public: String to_string_approximation() const; private: + virtual bool is_member_expression() const override { return true; } + NonnullRefPtr m_object; NonnullRefPtr m_property; bool m_computed { false }; @@ -1378,4 +1403,25 @@ void BindingPattern::for_each_assigned_name(C&& callback) const } } +template<> +inline bool ASTNode::fast_is() const { return is_new_expression(); } + +template<> +inline bool ASTNode::fast_is() const { return is_member_expression(); } + +template<> +inline bool ASTNode::fast_is() const { return is_super_expression(); } + +template<> +inline bool ASTNode::fast_is() const { return is_identifier(); } + +template<> +inline bool ASTNode::fast_is() const { return is_expression_statement(); } + +template<> +inline bool ASTNode::fast_is() const { return is_scope_node(); } + +template<> +inline bool ASTNode::fast_is() const { return is_program(); } + } diff --git a/Userland/Libraries/LibJS/Runtime/LexicalEnvironment.h b/Userland/Libraries/LibJS/Runtime/LexicalEnvironment.h index 73f8170e866..73a5018a324 100644 --- a/Userland/Libraries/LibJS/Runtime/LexicalEnvironment.h +++ b/Userland/Libraries/LibJS/Runtime/LexicalEnvironment.h @@ -66,6 +66,7 @@ public: EnvironmentRecordType type() const { return m_environment_record_type; } private: + virtual bool is_lexical_environment() const override { return true; } virtual void visit_edges(Visitor&) override; EnvironmentRecordType m_environment_record_type : 8 { EnvironmentRecordType::Declarative }; @@ -78,4 +79,7 @@ private: Function* m_current_function { nullptr }; }; +template<> +inline bool Object::fast_is() const { return is_lexical_environment(); } + } diff --git a/Userland/Libraries/LibJS/Runtime/NativeFunction.h b/Userland/Libraries/LibJS/Runtime/NativeFunction.h index 397789fd6e6..93661a3fafc 100644 --- a/Userland/Libraries/LibJS/Runtime/NativeFunction.h +++ b/Userland/Libraries/LibJS/Runtime/NativeFunction.h @@ -35,9 +35,13 @@ protected: private: virtual LexicalEnvironment* create_environment() override final; + virtual bool is_native_function() const final { return true; } FlyString m_name; AK::Function m_native_function; }; +template<> +inline bool Object::fast_is() const { return is_native_function(); } + } diff --git a/Userland/Libraries/LibJS/Runtime/Object.h b/Userland/Libraries/LibJS/Runtime/Object.h index e69328b9694..798a3372df7 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.h +++ b/Userland/Libraries/LibJS/Runtime/Object.h @@ -106,6 +106,9 @@ public: virtual bool is_typed_array() 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; } + virtual bool is_native_function() const { return false; } + virtual bool is_lexical_environment() const { return false; } virtual const char* class_name() const override { return "Object"; } virtual void visit_edges(Cell::Visitor&) override; diff --git a/Userland/Libraries/LibJS/Runtime/ProxyObject.h b/Userland/Libraries/LibJS/Runtime/ProxyObject.h index 09cec70756f..f540a429d78 100644 --- a/Userland/Libraries/LibJS/Runtime/ProxyObject.h +++ b/Userland/Libraries/LibJS/Runtime/ProxyObject.h @@ -46,10 +46,14 @@ private: virtual void visit_edges(Visitor&) override; virtual bool is_function() const override { return m_target.is_function(); } + virtual bool is_proxy_object() const final { return true; } Object& m_target; Object& m_handler; bool m_is_revoked { false }; }; +template<> +inline bool Object::fast_is() const { return is_proxy_object(); } + }