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