ladybird/Userland/Libraries/LibJS/Runtime/ECMAScriptFunctionObject.h
Linus Groh e37cf73300 LibJS: Rename OrdinaryFunctionObject to ECMAScriptFunctionObject
The old name is the result of the perhaps somewhat confusingly named
abstract operation OrdinaryFunctionCreate(), which creates an "ordinary
object" (https://tc39.es/ecma262/#ordinary-object) in contrast to an
"exotic object" (https://tc39.es/ecma262/#exotic-object).

However, the term "Ordinary Function" is not used anywhere in the spec,
instead the created object is referred to as an "ECMAScript Function
Object" (https://tc39.es/ecma262/#sec-ecmascript-function-objects), so
let's call it that.

The "ordinary" vs. "exotic" distinction is important because there are
also "Built-in Function Objects", which can be either implemented as
ordinary ECMAScript function objects, or as exotic objects (our
NativeFunction).

More work needs to be done to move a lot of infrastructure to
ECMAScriptFunctionObject in order to make FunctionObject nothing more
than an interface for objects that implement [[Call]] and optionally
[[Construct]].
2021-09-25 17:51:30 +02:00

65 lines
2.5 KiB
C++

/*
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibJS/AST.h>
#include <LibJS/Bytecode/Generator.h>
#include <LibJS/Runtime/FunctionObject.h>
namespace JS {
// 10.2 ECMAScript Function Objects, https://tc39.es/ecma262/#sec-ecmascript-function-objects
class ECMAScriptFunctionObject final : public FunctionObject {
JS_OBJECT(ECMAScriptFunctionObject, FunctionObject);
public:
static ECMAScriptFunctionObject* 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);
ECMAScriptFunctionObject(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);
virtual void initialize(GlobalObject&) override;
virtual ~ECMAScriptFunctionObject();
const Statement& body() const { return m_body; }
const Vector<FunctionNode::Parameter>& parameters() const { return m_parameters; };
virtual Value call() override;
virtual Value construct(FunctionObject& new_target) override;
virtual const FlyString& name() const override { return m_name; };
void set_name(const FlyString& name);
void set_is_class_constructor() { m_is_class_constructor = true; };
auto& bytecode_executable() const { return m_bytecode_executable; }
virtual Environment* environment() override { return m_environment; }
virtual Realm* realm() const override { return m_realm; }
protected:
virtual bool is_strict_mode() const final { return m_is_strict; }
private:
virtual bool is_ecmascript_function_object() const override { return true; }
virtual FunctionEnvironment* create_environment(FunctionObject&) override;
virtual void visit_edges(Visitor&) override;
Value execute_function_body();
FlyString m_name;
NonnullRefPtr<Statement> m_body;
const Vector<FunctionNode::Parameter> m_parameters;
Optional<Bytecode::Executable> m_bytecode_executable;
Environment* m_environment { nullptr };
Realm* m_realm { nullptr };
i32 m_function_length { 0 };
FunctionKind m_kind { FunctionKind::Regular };
bool m_is_strict { false };
bool m_is_arrow_function { false };
bool m_is_class_constructor { false };
};
}