diff options
-rw-r--r-- | Userland/Libraries/LibJS/AST.h | 66 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.h | 3 |
2 files changed, 69 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/AST.h b/Userland/Libraries/LibJS/AST.h index f4f5bd9fa2..684ff58106 100644 --- a/Userland/Libraries/LibJS/AST.h +++ b/Userland/Libraries/LibJS/AST.h @@ -67,7 +67,18 @@ public: virtual bool is_identifier() const { return false; } virtual bool is_scope_node() const { return false; } virtual bool is_program() const { return false; } + virtual bool is_class_declaration() const { return false; } virtual bool is_function_declaration() const { return false; } + virtual bool is_variable_declaration() const { return false; } + virtual bool is_import_call() const { return false; } + virtual bool is_array_expression() const { return false; } + virtual bool is_object_expression() const { return false; } + virtual bool is_string_literal() const { return false; } + virtual bool is_update_expression() const { return false; } + virtual bool is_call_expression() const { return false; } + virtual bool is_labelled_statement() const { return false; } + virtual bool is_iteration_statement() const { return false; } + virtual bool is_class_method() const { return false; } protected: explicit ASTNode(SourceRange source_range) @@ -106,6 +117,8 @@ public: NonnullRefPtr<Statement>& labelled_item() { return m_labelled_item; } private: + virtual bool is_labelled_statement() const final { return true; } + FlyString m_label; NonnullRefPtr<Statement> m_labelled_item; }; @@ -126,6 +139,9 @@ public: using Statement::Statement; virtual Completion loop_evaluation(Interpreter&, GlobalObject&, Vector<FlyString> const&) const = 0; + +private: + virtual bool is_iteration_statement() const final { return true; } }; class EmptyStatement final : public Statement { @@ -1124,6 +1140,8 @@ public: bool is_use_strict_directive() const { return m_is_use_strict_directive; }; private: + virtual bool is_string_literal() const override { return true; } + String m_value; bool m_is_use_strict_directive; }; @@ -1272,6 +1290,7 @@ public: virtual Optional<FlyString> private_bound_identifier() const override; private: + virtual bool is_class_method() const override { return true; } NonnullRefPtr<Expression> m_key; NonnullRefPtr<FunctionExpression> m_function; Kind m_kind; @@ -1387,6 +1406,8 @@ public: StringView name() const { return m_class_expression->name(); } private: + virtual bool is_class_declaration() const override { return true; } + friend ExportStatement; NonnullRefPtr<ClassExpression> m_class_expression; @@ -1439,6 +1460,8 @@ public: Expression const& callee() const { return m_callee; } protected: + virtual bool is_call_expression() const override { return true; } + Completion throw_type_error_for_callee(Interpreter&, GlobalObject&, Value callee_value, StringView call_type) const; NonnullRefPtr<Expression> m_callee; @@ -1546,6 +1569,8 @@ public: virtual void generate_bytecode(Bytecode::Generator&) const override; private: + virtual bool is_update_expression() const override { return true; } + UpdateOp m_op; NonnullRefPtr<Expression> m_argument; bool m_prefixed; @@ -1614,6 +1639,8 @@ public: virtual bool is_lexical_declaration() const override { return m_declaration_kind != DeclarationKind::Var; } private: + virtual bool is_variable_declaration() const override { return true; } + DeclarationKind m_declaration_kind; NonnullRefPtrVector<VariableDeclarator> m_declarations; }; @@ -1672,6 +1699,8 @@ public: Optional<SourceRange> const& invalid_property_range() const { return m_first_invalid_property_range; } private: + virtual bool is_object_expression() const override { return true; } + NonnullRefPtrVector<ObjectProperty> m_properties; Optional<SourceRange> m_first_invalid_property_range; }; @@ -1691,6 +1720,8 @@ public: virtual void generate_bytecode(Bytecode::Generator&) const override; private: + virtual bool is_array_expression() const override { return true; } + Vector<RefPtr<Expression>> m_elements; }; @@ -1851,6 +1882,8 @@ public: virtual Completion execute(Interpreter&, GlobalObject&) const override; private: + virtual bool is_import_call() const override { return true; } + NonnullRefPtr<Expression> m_specifier; RefPtr<Expression> m_options; }; @@ -2071,6 +2104,39 @@ template<> inline bool ASTNode::fast_is<Program>() const { return is_program(); } template<> +inline bool ASTNode::fast_is<ClassDeclaration>() const { return is_class_declaration(); } + +template<> inline bool ASTNode::fast_is<FunctionDeclaration>() const { return is_function_declaration(); } +template<> +inline bool ASTNode::fast_is<VariableDeclaration>() const { return is_variable_declaration(); } + +template<> +inline bool ASTNode::fast_is<ArrayExpression>() const { return is_array_expression(); } + +template<> +inline bool ASTNode::fast_is<ObjectExpression>() const { return is_object_expression(); } + +template<> +inline bool ASTNode::fast_is<ImportCall>() const { return is_import_call(); } + +template<> +inline bool ASTNode::fast_is<StringLiteral>() const { return is_string_literal(); } + +template<> +inline bool ASTNode::fast_is<UpdateExpression>() const { return is_update_expression(); } + +template<> +inline bool ASTNode::fast_is<CallExpression>() const { return is_call_expression(); } + +template<> +inline bool ASTNode::fast_is<LabelledStatement>() const { return is_labelled_statement(); } + +template<> +inline bool ASTNode::fast_is<IterationStatement>() const { return is_iteration_statement(); } + +template<> +inline bool ASTNode::fast_is<ClassMethod>() const { return is_class_method(); } + } diff --git a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.h b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.h index e220d5cdca..a72cfdaa48 100644 --- a/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.h +++ b/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.h @@ -134,4 +134,7 @@ private: FunctionKind m_kind : 3 { FunctionKind::Normal }; }; +template<> +inline bool Object::fast_is<ECMAScriptFunctionObject>() const { return is_ecmascript_function_object(); } + } |