| 
									
										
										
										
											2020-03-13 10:08:52 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2020, Andreas Kling <kling@serenityos.org> | 
					
						
							|  |  |  |  * All rights reserved. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Redistribution and use in source and binary forms, with or without | 
					
						
							|  |  |  |  * modification, are permitted provided that the following conditions are met: | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 1. Redistributions of source code must retain the above copyright notice, this | 
					
						
							|  |  |  |  *    list of conditions and the following disclaimer. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * 2. Redistributions in binary form must reproduce the above copyright notice, | 
					
						
							|  |  |  |  *    this list of conditions and the following disclaimer in the documentation | 
					
						
							|  |  |  |  *    and/or other materials provided with the distribution. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 
					
						
							|  |  |  |  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 
					
						
							|  |  |  |  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 
					
						
							|  |  |  |  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | 
					
						
							|  |  |  |  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 
					
						
							|  |  |  |  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | 
					
						
							|  |  |  |  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | 
					
						
							|  |  |  |  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | 
					
						
							|  |  |  |  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
					
						
							|  |  |  |  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-02 11:46:39 -07:00
										 |  |  | #include <LibJS/AST.h>
 | 
					
						
							| 
									
										
										
										
											2020-03-16 14:20:30 +01:00
										 |  |  | #include <LibJS/Runtime/Function.h>
 | 
					
						
							| 
									
										
										
										
											2020-03-13 10:08:52 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace JS { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ScriptFunction final : public Function { | 
					
						
							|  |  |  | public: | 
					
						
							| 
									
										
										
										
											2020-05-30 00:10:42 -05:00
										 |  |  |     static ScriptFunction* create(GlobalObject&, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, LexicalEnvironment* parent_environment, bool is_arrow_function = false); | 
					
						
							| 
									
										
										
										
											2020-04-17 19:59:32 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-30 00:10:42 -05:00
										 |  |  |     ScriptFunction(const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, LexicalEnvironment* parent_environment, Object& prototype, bool is_arrow_function = false); | 
					
						
							| 
									
										
										
										
											2020-03-13 10:08:52 +01:00
										 |  |  |     virtual ~ScriptFunction(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											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-03-28 22:48:35 +01:00
										 |  |  |     virtual Value call(Interpreter&) override; | 
					
						
							| 
									
										
										
										
											2020-04-01 18:31:24 +01:00
										 |  |  |     virtual Value construct(Interpreter&) 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-03-13 10:08:52 +01:00
										 |  |  | private: | 
					
						
							| 
									
										
										
										
											2020-06-01 16:58:54 +03:00
										 |  |  |     virtual bool is_script_function() const override { return true; } | 
					
						
							| 
									
										
										
										
											2020-03-13 10:08:52 +01:00
										 |  |  |     virtual const char* class_name() const override { return "ScriptFunction"; } | 
					
						
							| 
									
										
										
										
											2020-04-15 21:58:22 +02:00
										 |  |  |     virtual LexicalEnvironment* create_environment() override; | 
					
						
							|  |  |  |     virtual void visit_children(Visitor&) override; | 
					
						
							| 
									
										
										
										
											2020-03-13 10:08:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							| 
									
										
										
										
											2020-04-15 21:58:22 +02:00
										 |  |  |     LexicalEnvironment* m_parent_environment { nullptr }; | 
					
						
							| 
									
										
										
										
											2020-05-05 20:02:14 -07:00
										 |  |  |     i32 m_function_length; | 
					
						
							| 
									
										
										
										
											2020-05-30 00:10:42 -05:00
										 |  |  |     bool m_is_arrow_function; | 
					
						
							| 
									
										
										
										
											2020-03-13 10:08:52 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |