| 
									
										
										
										
											2020-03-13 10:08:52 +01:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2021-06-27 22:15:58 +02:00
										 |  |  |  * Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org> | 
					
						
							| 
									
										
										
										
											2020-03-13 10:08:52 +01:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2021-04-22 01:24:48 -07:00
										 |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							| 
									
										
										
										
											2020-03-13 10:08:52 +01:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-02 11:46:39 -07:00
										 |  |  | #include <LibJS/AST.h>
 | 
					
						
							| 
									
										
										
										
											2021-06-09 06:49:58 +04:30
										 |  |  | #include <LibJS/Bytecode/Generator.h>
 | 
					
						
							| 
									
										
										
										
											2021-06-27 21:48:34 +02:00
										 |  |  | #include <LibJS/Runtime/FunctionObject.h>
 | 
					
						
							| 
									
										
										
										
											2020-03-13 10:08:52 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace JS { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-27 22:15:58 +02:00
										 |  |  | class OrdinaryFunctionObject final : public FunctionObject { | 
					
						
							|  |  |  |     JS_OBJECT(OrdinaryFunctionObject, FunctionObject); | 
					
						
							| 
									
										
										
										
											2020-06-21 15:14:02 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-13 10:08:52 +01:00
										 |  |  | public: | 
					
						
							| 
									
										
										
										
											2021-06-27 22:15:58 +02:00
										 |  |  |     static OrdinaryFunctionObject* create(GlobalObject&, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, EnvironmentRecord* parent_scope, FunctionKind, bool is_strict, bool is_arrow_function = false); | 
					
						
							| 
									
										
										
										
											2020-04-17 19:59:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-27 22:15:58 +02:00
										 |  |  |     OrdinaryFunctionObject(GlobalObject&, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, EnvironmentRecord* parent_scope, Object& prototype, FunctionKind, bool is_strict, bool is_arrow_function = false); | 
					
						
							| 
									
										
										
										
											2020-07-22 17:50:18 +02:00
										 |  |  |     virtual void initialize(GlobalObject&) override; | 
					
						
							| 
									
										
										
										
											2021-06-27 22:15:58 +02:00
										 |  |  |     virtual ~OrdinaryFunctionObject(); | 
					
						
							| 
									
										
										
										
											2020-03-13 10:08:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-05 11:11:07 +02:00
										 |  |  |     const Statement& body() const { return m_body; } | 
					
						
							| 
									
										
										
										
											2020-05-02 11:46:39 -07:00
										 |  |  |     const Vector<FunctionNode::Parameter>& parameters() const { return m_parameters; }; | 
					
						
							| 
									
										
										
										
											2020-03-13 10:08:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-09-27 17:24:14 +02:00
										 |  |  |     virtual Value call() override; | 
					
						
							| 
									
										
										
										
											2021-06-27 21:48:34 +02:00
										 |  |  |     virtual Value construct(FunctionObject& new_target) override; | 
					
						
							| 
									
										
										
										
											2020-03-13 10:08:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-11 12:56:20 +01:00
										 |  |  |     virtual const FlyString& name() const override { return m_name; }; | 
					
						
							| 
									
										
										
										
											2020-05-02 20:28:48 +01:00
										 |  |  |     void set_name(const FlyString& name) { m_name = name; }; | 
					
						
							| 
									
										
										
										
											2020-04-11 12:56:20 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-11 21:37:40 +00:00
										 |  |  |     void set_is_class_constructor() { m_is_class_constructor = true; }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-11 01:38:30 +04:30
										 |  |  |     auto& bytecode_executable() const { return m_bytecode_executable; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-06-25 21:22:37 +02:00
										 |  |  |     virtual EnvironmentRecord* environment() override { return m_environment; } | 
					
						
							| 
									
										
										
										
											2021-06-22 13:30:48 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-04 13:54:44 +02:00
										 |  |  | protected: | 
					
						
							|  |  |  |     virtual bool is_strict_mode() const final { return m_is_strict; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-13 10:08:52 +01:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2021-06-28 13:26:01 +02:00
										 |  |  |     virtual bool is_ordinary_function_object() const { return true; } | 
					
						
							| 
									
										
										
										
											2021-06-27 21:48:34 +02:00
										 |  |  |     virtual FunctionEnvironmentRecord* create_environment_record(FunctionObject&) override; | 
					
						
							| 
									
										
										
										
											2020-11-28 14:33:36 +01:00
										 |  |  |     virtual void visit_edges(Visitor&) override; | 
					
						
							| 
									
										
										
										
											2020-03-13 10:08:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-11-11 21:37:40 +00:00
										 |  |  |     Value execute_function_body(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-20 13:55:34 +02:00
										 |  |  |     JS_DECLARE_NATIVE_GETTER(length_getter); | 
					
						
							|  |  |  |     JS_DECLARE_NATIVE_GETTER(name_getter); | 
					
						
							| 
									
										
										
										
											2020-04-04 14:34:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-11 12:56:20 +01:00
										 |  |  |     FlyString m_name; | 
					
						
							| 
									
										
										
										
											2020-04-05 11:11:07 +02:00
										 |  |  |     NonnullRefPtr<Statement> m_body; | 
					
						
							| 
									
										
										
										
											2020-05-02 11:46:39 -07:00
										 |  |  |     const Vector<FunctionNode::Parameter> m_parameters; | 
					
						
							| 
									
										
										
										
											2021-06-09 09:11:20 +02:00
										 |  |  |     Optional<Bytecode::Executable> m_bytecode_executable; | 
					
						
							| 
									
										
										
										
											2021-06-25 21:22:37 +02:00
										 |  |  |     EnvironmentRecord* m_environment { nullptr }; | 
					
						
							| 
									
										
										
										
											2020-10-04 13:54:44 +02:00
										 |  |  |     i32 m_function_length { 0 }; | 
					
						
							| 
									
										
										
										
											2021-06-11 03:38:05 +04:30
										 |  |  |     FunctionKind m_kind { FunctionKind::Regular }; | 
					
						
							| 
									
										
										
										
											2020-10-04 13:54:44 +02:00
										 |  |  |     bool m_is_strict { false }; | 
					
						
							|  |  |  |     bool m_is_arrow_function { false }; | 
					
						
							| 
									
										
										
										
											2020-11-11 21:37:40 +00:00
										 |  |  |     bool m_is_class_constructor { false }; | 
					
						
							| 
									
										
										
										
											2020-03-13 10:08:52 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |