2020-03-13 06:08:52 -03:00
|
|
|
/*
|
2021-06-27 17:15:58 -03:00
|
|
|
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
2020-03-13 06:08:52 -03:00
|
|
|
*
|
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>
|
2021-06-27 16:48:34 -03:00
|
|
|
#include <LibJS/Runtime/FunctionObject.h>
|
2020-03-13 06:08:52 -03:00
|
|
|
|
|
|
|
|
namespace JS {
|
|
|
|
|
|
2021-06-27 17:15:58 -03:00
|
|
|
class OrdinaryFunctionObject final : public FunctionObject {
|
|
|
|
|
JS_OBJECT(OrdinaryFunctionObject, FunctionObject);
|
2020-06-21 10:14:02 -03:00
|
|
|
|
2020-03-13 06:08:52 -03:00
|
|
|
public:
|
2021-07-01 07:24:46 -03:00
|
|
|
static OrdinaryFunctionObject* create(GlobalObject&, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, Environment* parent_scope, FunctionKind, bool is_strict, bool is_arrow_function = false);
|
2020-04-17 14:59:32 -03:00
|
|
|
|
2021-07-01 07:24:46 -03:00
|
|
|
OrdinaryFunctionObject(GlobalObject&, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, Environment* parent_scope, Object& prototype, FunctionKind, bool is_strict, bool is_arrow_function = false);
|
2020-07-22 12:50:18 -03:00
|
|
|
virtual void initialize(GlobalObject&) override;
|
2021-06-27 17:15:58 -03:00
|
|
|
virtual ~OrdinaryFunctionObject();
|
2020-03-13 06:08:52 -03:00
|
|
|
|
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;
|
2021-06-27 16:48:34 -03:00
|
|
|
virtual Value construct(FunctionObject& 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; };
|
2021-07-05 12:02:27 -03:00
|
|
|
void set_name(const FlyString& 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; };
|
|
|
|
|
|
2021-06-10 18:08:30 -03:00
|
|
|
auto& bytecode_executable() const { return m_bytecode_executable; }
|
|
|
|
|
|
2021-07-01 07:24:46 -03:00
|
|
|
virtual Environment* environment() override { return m_environment; }
|
2021-09-11 17:42:01 -03:00
|
|
|
virtual Realm* realm() const override { return m_realm; }
|
2021-06-30 11:54:47 -03:00
|
|
|
|
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:
|
2021-06-28 14:25:35 -03:00
|
|
|
virtual bool is_ordinary_function_object() const override { return true; }
|
2021-07-01 07:24:46 -03:00
|
|
|
virtual FunctionEnvironment* create_environment(FunctionObject&) 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-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;
|
2021-07-01 07:24:46 -03:00
|
|
|
Environment* m_environment { nullptr };
|
2021-09-11 17:42:01 -03:00
|
|
|
Realm* m_realm { nullptr };
|
2020-10-04 08:54:44 -03:00
|
|
|
i32 m_function_length { 0 };
|
2021-06-10 20:08:05 -03:00
|
|
|
FunctionKind m_kind { FunctionKind::Regular };
|
2020-10-04 08:54:44 -03:00
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|