LibJS: Rename ScriptFunction => OrdinaryFunctionObject

These are basically what the spec calls "ordinary function objects",
so let's have the name reflect that. :^)
This commit is contained in:
Andreas Kling 2021-06-27 22:15:58 +02:00
parent ba9d5c4d54
commit c8270dbe2e
Notes: sideshowbarker 2024-07-18 11:26:12 +09:00
17 changed files with 60 additions and 60 deletions

View file

@ -25,10 +25,10 @@
#include <LibJS/Runtime/MarkedValueList.h> #include <LibJS/Runtime/MarkedValueList.h>
#include <LibJS/Runtime/NativeFunction.h> #include <LibJS/Runtime/NativeFunction.h>
#include <LibJS/Runtime/ObjectEnvironmentRecord.h> #include <LibJS/Runtime/ObjectEnvironmentRecord.h>
#include <LibJS/Runtime/OrdinaryFunctionObject.h>
#include <LibJS/Runtime/PrimitiveString.h> #include <LibJS/Runtime/PrimitiveString.h>
#include <LibJS/Runtime/Reference.h> #include <LibJS/Runtime/Reference.h>
#include <LibJS/Runtime/RegExpObject.h> #include <LibJS/Runtime/RegExpObject.h>
#include <LibJS/Runtime/ScriptFunction.h>
#include <LibJS/Runtime/Shape.h> #include <LibJS/Runtime/Shape.h>
#include <typeinfo> #include <typeinfo>
@ -68,8 +68,8 @@ static void update_function_name(Value value, FlyString const& name)
if (!value.is_function()) if (!value.is_function())
return; return;
auto& function = value.as_function(); auto& function = value.as_function();
if (is<ScriptFunction>(function) && function.name().is_empty()) if (is<OrdinaryFunctionObject>(function) && function.name().is_empty())
static_cast<ScriptFunction&>(function).set_name(name); static_cast<OrdinaryFunctionObject&>(function).set_name(name);
} }
static String get_function_name(GlobalObject& global_object, Value value) static String get_function_name(GlobalObject& global_object, Value value)
@ -102,7 +102,7 @@ Value FunctionDeclaration::execute(Interpreter& interpreter, GlobalObject&) cons
Value FunctionExpression::execute(Interpreter& interpreter, GlobalObject& global_object) const Value FunctionExpression::execute(Interpreter& interpreter, GlobalObject& global_object) const
{ {
InterpreterNodeScope node_scope { interpreter, *this }; InterpreterNodeScope node_scope { interpreter, *this };
return ScriptFunction::create(global_object, name(), body(), parameters(), function_length(), interpreter.lexical_environment(), kind(), is_strict_mode() || interpreter.vm().in_strict_mode(), is_arrow_function()); return OrdinaryFunctionObject::create(global_object, name(), body(), parameters(), function_length(), interpreter.lexical_environment(), kind(), is_strict_mode() || interpreter.vm().in_strict_mode(), is_arrow_function());
} }
Value ExpressionStatement::execute(Interpreter& interpreter, GlobalObject& global_object) const Value ExpressionStatement::execute(Interpreter& interpreter, GlobalObject& global_object) const
@ -761,8 +761,8 @@ Value ClassExpression::execute(Interpreter& interpreter, GlobalObject& global_ob
update_function_name(class_constructor_value, m_name); update_function_name(class_constructor_value, m_name);
VERIFY(class_constructor_value.is_function() && is<ScriptFunction>(class_constructor_value.as_function())); VERIFY(class_constructor_value.is_function() && is<OrdinaryFunctionObject>(class_constructor_value.as_function()));
auto* class_constructor = static_cast<ScriptFunction*>(&class_constructor_value.as_function()); auto* class_constructor = static_cast<OrdinaryFunctionObject*>(&class_constructor_value.as_function());
class_constructor->set_is_class_constructor(); class_constructor->set_is_class_constructor();
Value super_constructor = js_undefined(); Value super_constructor = js_undefined();
if (!m_super_class.is_null()) { if (!m_super_class.is_null()) {

View file

@ -16,8 +16,8 @@
#include <LibJS/Runtime/EnvironmentRecord.h> #include <LibJS/Runtime/EnvironmentRecord.h>
#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/IteratorOperations.h> #include <LibJS/Runtime/IteratorOperations.h>
#include <LibJS/Runtime/OrdinaryFunctionObject.h>
#include <LibJS/Runtime/RegExpObject.h> #include <LibJS/Runtime/RegExpObject.h>
#include <LibJS/Runtime/ScriptFunction.h>
#include <LibJS/Runtime/Value.h> #include <LibJS/Runtime/Value.h>
namespace JS::Bytecode { namespace JS::Bytecode {
@ -312,7 +312,7 @@ void Call::execute_impl(Bytecode::Interpreter& interpreter) const
void NewFunction::execute_impl(Bytecode::Interpreter& interpreter) const void NewFunction::execute_impl(Bytecode::Interpreter& interpreter) const
{ {
auto& vm = interpreter.vm(); auto& vm = interpreter.vm();
interpreter.accumulator() = ScriptFunction::create(interpreter.global_object(), m_function_node.name(), m_function_node.body(), m_function_node.parameters(), m_function_node.function_length(), vm.lexical_environment(), m_function_node.kind(), m_function_node.is_strict_mode(), m_function_node.is_arrow_function()); interpreter.accumulator() = OrdinaryFunctionObject::create(interpreter.global_object(), m_function_node.name(), m_function_node.body(), m_function_node.parameters(), m_function_node.function_length(), vm.lexical_environment(), m_function_node.kind(), m_function_node.is_strict_mode(), m_function_node.is_arrow_function());
} }
void Return::execute_impl(Bytecode::Interpreter& interpreter) const void Return::execute_impl(Bytecode::Interpreter& interpreter) const

View file

@ -104,7 +104,7 @@ set(SOURCES
Runtime/RegExpConstructor.cpp Runtime/RegExpConstructor.cpp
Runtime/RegExpObject.cpp Runtime/RegExpObject.cpp
Runtime/RegExpPrototype.cpp Runtime/RegExpPrototype.cpp
Runtime/ScriptFunction.cpp Runtime/OrdinaryFunctionObject.cpp
Runtime/Set.cpp Runtime/Set.cpp
Runtime/SetConstructor.cpp Runtime/SetConstructor.cpp
Runtime/SetIterator.cpp Runtime/SetIterator.cpp

View file

@ -13,8 +13,8 @@
#include <LibJS/Runtime/GlobalEnvironmentRecord.h> #include <LibJS/Runtime/GlobalEnvironmentRecord.h>
#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/Object.h> #include <LibJS/Runtime/Object.h>
#include <LibJS/Runtime/OrdinaryFunctionObject.h>
#include <LibJS/Runtime/Reference.h> #include <LibJS/Runtime/Reference.h>
#include <LibJS/Runtime/ScriptFunction.h>
#include <LibJS/Runtime/Shape.h> #include <LibJS/Runtime/Shape.h>
#include <LibJS/Runtime/Value.h> #include <LibJS/Runtime/Value.h>
@ -85,7 +85,7 @@ void Interpreter::enter_scope(const ScopeNode& scope_node, ScopeType scope_type,
{ {
ScopeGuard guard([&] { ScopeGuard guard([&] {
for (auto& declaration : scope_node.functions()) { for (auto& declaration : scope_node.functions()) {
auto* function = ScriptFunction::create(global_object, declaration.name(), declaration.body(), declaration.parameters(), declaration.function_length(), lexical_environment(), declaration.kind(), declaration.is_strict_mode()); auto* function = OrdinaryFunctionObject::create(global_object, declaration.name(), declaration.body(), declaration.parameters(), declaration.function_length(), lexical_environment(), declaration.kind(), declaration.is_strict_mode());
vm().set_variable(declaration.name(), function, global_object); vm().set_variable(declaration.name(), function, global_object);
} }
}); });

View file

@ -16,7 +16,7 @@
#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/MarkedValueList.h> #include <LibJS/Runtime/MarkedValueList.h>
#include <LibJS/Runtime/NativeFunction.h> #include <LibJS/Runtime/NativeFunction.h>
#include <LibJS/Runtime/ScriptFunction.h> #include <LibJS/Runtime/OrdinaryFunctionObject.h>
namespace JS { namespace JS {
@ -120,11 +120,11 @@ JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::to_string)
String function_parameters; String function_parameters;
String function_body; String function_body;
if (is<ScriptFunction>(this_object)) { if (is<OrdinaryFunctionObject>(this_object)) {
auto& script_function = static_cast<ScriptFunction&>(*this_object); auto& ordinary_function = static_cast<OrdinaryFunctionObject&>(*this_object);
StringBuilder parameters_builder; StringBuilder parameters_builder;
auto first = true; auto first = true;
for (auto& parameter : script_function.parameters()) { for (auto& parameter : ordinary_function.parameters()) {
// FIXME: Also stringify binding patterns. // FIXME: Also stringify binding patterns.
if (auto* name_ptr = parameter.binding.get_pointer<FlyString>()) { if (auto* name_ptr = parameter.binding.get_pointer<FlyString>()) {
if (!first) if (!first)
@ -137,10 +137,10 @@ JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::to_string)
} }
} }
} }
function_name = script_function.name(); function_name = ordinary_function.name();
function_parameters = parameters_builder.build(); function_parameters = parameters_builder.build();
// FIXME: ASTNodes should be able to dump themselves to source strings - something like this: // FIXME: ASTNodes should be able to dump themselves to source strings - something like this:
// auto& body = static_cast<ScriptFunction*>(this_object)->body(); // auto& body = static_cast<OrdinaryFunctionObject*>(this_object)->body();
// function_body = body.to_source(); // function_body = body.to_source();
function_body = " ???"; function_body = " ???";
} else { } else {

View file

@ -12,7 +12,7 @@
#include <LibJS/Runtime/FunctionConstructor.h> #include <LibJS/Runtime/FunctionConstructor.h>
#include <LibJS/Runtime/GeneratorFunctionConstructor.h> #include <LibJS/Runtime/GeneratorFunctionConstructor.h>
#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/ScriptFunction.h> #include <LibJS/Runtime/OrdinaryFunctionObject.h>
namespace JS { namespace JS {
@ -62,7 +62,7 @@ Value GeneratorFunctionConstructor::construct(FunctionObject& new_target)
block.dump(executable); block.dump(executable);
} }
return ScriptFunction::create(global_object(), function->name(), function->body(), function->parameters(), function->function_length(), vm().lexical_environment(), FunctionKind::Generator, function->is_strict_mode(), false); return OrdinaryFunctionObject::create(global_object(), function->name(), function->body(), function->parameters(), function->function_length(), vm().lexical_environment(), FunctionKind::Generator, function->is_strict_mode(), false);
} }
} }

View file

@ -13,7 +13,7 @@
namespace JS { namespace JS {
GeneratorObject* GeneratorObject::create(GlobalObject& global_object, Value initial_value, ScriptFunction* generating_function, EnvironmentRecord* generating_scope, Bytecode::RegisterWindow frame) GeneratorObject* GeneratorObject::create(GlobalObject& global_object, Value initial_value, OrdinaryFunctionObject* generating_function, EnvironmentRecord* generating_scope, Bytecode::RegisterWindow frame)
{ {
// This is "g1.prototype" in figure-2 (https://tc39.es/ecma262/img/figure-2.png) // This is "g1.prototype" in figure-2 (https://tc39.es/ecma262/img/figure-2.png)
auto generating_function_proto_property = generating_function->get(global_object.vm().names.prototype).to_object(global_object); auto generating_function_proto_property = generating_function->get(global_object.vm().names.prototype).to_object(global_object);

View file

@ -7,7 +7,7 @@
#pragma once #pragma once
#include <LibJS/Runtime/Object.h> #include <LibJS/Runtime/Object.h>
#include <LibJS/Runtime/ScriptFunction.h> #include <LibJS/Runtime/OrdinaryFunctionObject.h>
namespace JS { namespace JS {
@ -15,7 +15,7 @@ class GeneratorObject final : public Object {
JS_OBJECT(GeneratorObject, Object); JS_OBJECT(GeneratorObject, Object);
public: public:
static GeneratorObject* create(GlobalObject&, Value, ScriptFunction*, EnvironmentRecord*, Bytecode::RegisterWindow); static GeneratorObject* create(GlobalObject&, Value, OrdinaryFunctionObject*, EnvironmentRecord*, Bytecode::RegisterWindow);
GeneratorObject(GlobalObject&, Object& prototype); GeneratorObject(GlobalObject&, Object& prototype);
virtual void initialize(GlobalObject&) override; virtual void initialize(GlobalObject&) override;
virtual ~GeneratorObject() override; virtual ~GeneratorObject() override;
@ -26,7 +26,7 @@ public:
private: private:
EnvironmentRecord* m_environment_record { nullptr }; EnvironmentRecord* m_environment_record { nullptr };
ScriptFunction* m_generating_function { nullptr }; OrdinaryFunctionObject* m_generating_function { nullptr };
Value m_previous_value; Value m_previous_value;
Bytecode::RegisterWindow m_frame; Bytecode::RegisterWindow m_frame;
bool m_done { false }; bool m_done { false };

View file

@ -104,9 +104,9 @@ void GlobalObject::initialize_global_object()
m_new_object_shape = vm.heap().allocate_without_global_object<Shape>(*this); m_new_object_shape = vm.heap().allocate_without_global_object<Shape>(*this);
m_new_object_shape->set_prototype_without_transition(m_object_prototype); m_new_object_shape->set_prototype_without_transition(m_object_prototype);
m_new_script_function_prototype_object_shape = vm.heap().allocate_without_global_object<Shape>(*this); m_new_ordinary_function_prototype_object_shape = vm.heap().allocate_without_global_object<Shape>(*this);
m_new_script_function_prototype_object_shape->set_prototype_without_transition(m_object_prototype); m_new_ordinary_function_prototype_object_shape->set_prototype_without_transition(m_object_prototype);
m_new_script_function_prototype_object_shape->add_property_without_transition(vm.names.constructor, Attribute::Writable | Attribute::Configurable); m_new_ordinary_function_prototype_object_shape->add_property_without_transition(vm.names.constructor, Attribute::Writable | Attribute::Configurable);
static_cast<FunctionPrototype*>(m_function_prototype)->initialize(*this); static_cast<FunctionPrototype*>(m_function_prototype)->initialize(*this);
static_cast<ObjectPrototype*>(m_object_prototype)->initialize(*this); static_cast<ObjectPrototype*>(m_object_prototype)->initialize(*this);
@ -209,7 +209,7 @@ void GlobalObject::visit_edges(Visitor& visitor)
visitor.visit(m_empty_object_shape); visitor.visit(m_empty_object_shape);
visitor.visit(m_new_object_shape); visitor.visit(m_new_object_shape);
visitor.visit(m_new_script_function_prototype_object_shape); visitor.visit(m_new_ordinary_function_prototype_object_shape);
visitor.visit(m_proxy_constructor); visitor.visit(m_proxy_constructor);
visitor.visit(m_generator_object_prototype); visitor.visit(m_generator_object_prototype);
visitor.visit(m_environment_record); visitor.visit(m_environment_record);

View file

@ -28,7 +28,7 @@ public:
Shape* empty_object_shape() { return m_empty_object_shape; } Shape* empty_object_shape() { return m_empty_object_shape; }
Shape* new_object_shape() { return m_new_object_shape; } Shape* new_object_shape() { return m_new_object_shape; }
Shape* new_script_function_prototype_object_shape() { return m_new_script_function_prototype_object_shape; } Shape* new_ordinary_function_prototype_object_shape() { return m_new_ordinary_function_prototype_object_shape; }
// Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct prototype // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct prototype
ProxyConstructor* proxy_constructor() { return m_proxy_constructor; } ProxyConstructor* proxy_constructor() { return m_proxy_constructor; }
@ -77,7 +77,7 @@ private:
Shape* m_empty_object_shape { nullptr }; Shape* m_empty_object_shape { nullptr };
Shape* m_new_object_shape { nullptr }; Shape* m_new_object_shape { nullptr };
Shape* m_new_script_function_prototype_object_shape { nullptr }; Shape* m_new_ordinary_function_prototype_object_shape { nullptr };
// Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct prototype // Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct prototype
ProxyConstructor* m_proxy_constructor { nullptr }; ProxyConstructor* m_proxy_constructor { nullptr };

View file

@ -19,12 +19,12 @@
#include <LibJS/Runtime/GeneratorObjectPrototype.h> #include <LibJS/Runtime/GeneratorObjectPrototype.h>
#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/NativeFunction.h> #include <LibJS/Runtime/NativeFunction.h>
#include <LibJS/Runtime/ScriptFunction.h> #include <LibJS/Runtime/OrdinaryFunctionObject.h>
#include <LibJS/Runtime/Value.h> #include <LibJS/Runtime/Value.h>
namespace JS { namespace JS {
static ScriptFunction* typed_this(VM& vm, GlobalObject& global_object) static OrdinaryFunctionObject* typed_this(VM& vm, GlobalObject& global_object)
{ {
auto* this_object = vm.this_value(global_object).to_object(global_object); auto* this_object = vm.this_value(global_object).to_object(global_object);
if (!this_object) if (!this_object)
@ -33,10 +33,10 @@ static ScriptFunction* typed_this(VM& vm, GlobalObject& global_object)
vm.throw_exception<TypeError>(global_object, ErrorType::NotAFunctionNoParam); vm.throw_exception<TypeError>(global_object, ErrorType::NotAFunctionNoParam);
return nullptr; return nullptr;
} }
return static_cast<ScriptFunction*>(this_object); return static_cast<OrdinaryFunctionObject*>(this_object);
} }
ScriptFunction* ScriptFunction::create(GlobalObject& global_object, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, EnvironmentRecord* parent_scope, FunctionKind kind, bool is_strict, bool is_arrow_function) OrdinaryFunctionObject* OrdinaryFunctionObject::create(GlobalObject& global_object, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, EnvironmentRecord* parent_scope, FunctionKind kind, bool is_strict, bool is_arrow_function)
{ {
Object* prototype = nullptr; Object* prototype = nullptr;
switch (kind) { switch (kind) {
@ -47,10 +47,10 @@ ScriptFunction* ScriptFunction::create(GlobalObject& global_object, const FlyStr
prototype = global_object.generator_function_prototype(); prototype = global_object.generator_function_prototype();
break; break;
} }
return global_object.heap().allocate<ScriptFunction>(global_object, global_object, name, body, move(parameters), m_function_length, parent_scope, *prototype, kind, is_strict, is_arrow_function); return global_object.heap().allocate<OrdinaryFunctionObject>(global_object, global_object, name, body, move(parameters), m_function_length, parent_scope, *prototype, kind, is_strict, is_arrow_function);
} }
ScriptFunction::ScriptFunction(GlobalObject& global_object, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 function_length, EnvironmentRecord* parent_scope, Object& prototype, FunctionKind kind, bool is_strict, bool is_arrow_function) OrdinaryFunctionObject::OrdinaryFunctionObject(GlobalObject& global_object, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 function_length, EnvironmentRecord* parent_scope, Object& prototype, FunctionKind kind, bool is_strict, bool is_arrow_function)
: FunctionObject(is_arrow_function ? vm().this_value(global_object) : Value(), {}, prototype) : FunctionObject(is_arrow_function ? vm().this_value(global_object) : Value(), {}, prototype)
, m_name(name) , m_name(name)
, m_body(body) , m_body(body)
@ -70,12 +70,12 @@ ScriptFunction::ScriptFunction(GlobalObject& global_object, const FlyString& nam
set_this_mode(ThisMode::Global); set_this_mode(ThisMode::Global);
} }
void ScriptFunction::initialize(GlobalObject& global_object) void OrdinaryFunctionObject::initialize(GlobalObject& global_object)
{ {
auto& vm = this->vm(); auto& vm = this->vm();
Base::initialize(global_object); Base::initialize(global_object);
if (!m_is_arrow_function) { if (!m_is_arrow_function) {
auto* prototype = vm.heap().allocate<Object>(global_object, *global_object.new_script_function_prototype_object_shape()); auto* prototype = vm.heap().allocate<Object>(global_object, *global_object.new_ordinary_function_prototype_object_shape());
switch (m_kind) { switch (m_kind) {
case FunctionKind::Regular: case FunctionKind::Regular:
prototype->define_property(vm.names.constructor, this, Attribute::Writable | Attribute::Configurable); prototype->define_property(vm.names.constructor, this, Attribute::Writable | Attribute::Configurable);
@ -91,17 +91,17 @@ void ScriptFunction::initialize(GlobalObject& global_object)
define_native_property(vm.names.name, name_getter, {}, Attribute::Configurable); define_native_property(vm.names.name, name_getter, {}, Attribute::Configurable);
} }
ScriptFunction::~ScriptFunction() OrdinaryFunctionObject::~OrdinaryFunctionObject()
{ {
} }
void ScriptFunction::visit_edges(Visitor& visitor) void OrdinaryFunctionObject::visit_edges(Visitor& visitor)
{ {
Base::visit_edges(visitor); Base::visit_edges(visitor);
visitor.visit(m_environment); visitor.visit(m_environment);
} }
FunctionEnvironmentRecord* ScriptFunction::create_environment_record(FunctionObject& function_being_invoked) FunctionEnvironmentRecord* OrdinaryFunctionObject::create_environment_record(FunctionObject& function_being_invoked)
{ {
HashMap<FlyString, Variable> variables; HashMap<FlyString, Variable> variables;
for (auto& parameter : m_parameters) { for (auto& parameter : m_parameters) {
@ -139,7 +139,7 @@ FunctionEnvironmentRecord* ScriptFunction::create_environment_record(FunctionObj
return environment; return environment;
} }
Value ScriptFunction::execute_function_body() Value OrdinaryFunctionObject::execute_function_body()
{ {
auto& vm = this->vm(); auto& vm = this->vm();
@ -216,7 +216,7 @@ Value ScriptFunction::execute_function_body()
} }
} }
Value ScriptFunction::call() Value OrdinaryFunctionObject::call()
{ {
if (m_is_class_constructor) { if (m_is_class_constructor) {
vm().throw_exception<TypeError>(global_object(), ErrorType::ClassConstructorWithoutNew, m_name); vm().throw_exception<TypeError>(global_object(), ErrorType::ClassConstructorWithoutNew, m_name);
@ -225,7 +225,7 @@ Value ScriptFunction::call()
return execute_function_body(); return execute_function_body();
} }
Value ScriptFunction::construct(FunctionObject&) Value OrdinaryFunctionObject::construct(FunctionObject&)
{ {
if (m_is_arrow_function || m_kind == FunctionKind::Generator) { if (m_is_arrow_function || m_kind == FunctionKind::Generator) {
vm().throw_exception<TypeError>(global_object(), ErrorType::NotAConstructor, m_name); vm().throw_exception<TypeError>(global_object(), ErrorType::NotAConstructor, m_name);
@ -234,7 +234,7 @@ Value ScriptFunction::construct(FunctionObject&)
return execute_function_body(); return execute_function_body();
} }
JS_DEFINE_NATIVE_GETTER(ScriptFunction::length_getter) JS_DEFINE_NATIVE_GETTER(OrdinaryFunctionObject::length_getter)
{ {
auto* function = typed_this(vm, global_object); auto* function = typed_this(vm, global_object);
if (!function) if (!function)
@ -242,7 +242,7 @@ JS_DEFINE_NATIVE_GETTER(ScriptFunction::length_getter)
return Value(static_cast<i32>(function->m_function_length)); return Value(static_cast<i32>(function->m_function_length));
} }
JS_DEFINE_NATIVE_GETTER(ScriptFunction::name_getter) JS_DEFINE_NATIVE_GETTER(OrdinaryFunctionObject::name_getter)
{ {
auto* function = typed_this(vm, global_object); auto* function = typed_this(vm, global_object);
if (!function) if (!function)

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org> * Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
* *
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
@ -12,15 +12,15 @@
namespace JS { namespace JS {
class ScriptFunction final : public FunctionObject { class OrdinaryFunctionObject final : public FunctionObject {
JS_OBJECT(ScriptFunction, FunctionObject); JS_OBJECT(OrdinaryFunctionObject, FunctionObject);
public: public:
static ScriptFunction* 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); 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);
ScriptFunction(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); 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);
virtual void initialize(GlobalObject&) override; virtual void initialize(GlobalObject&) override;
virtual ~ScriptFunction(); virtual ~OrdinaryFunctionObject();
const Statement& body() const { return m_body; } const Statement& body() const { return m_body; }
const Vector<FunctionNode::Parameter>& parameters() const { return m_parameters; }; const Vector<FunctionNode::Parameter>& parameters() const { return m_parameters; };

View file

@ -18,9 +18,9 @@
#include <LibJS/Runtime/GlobalObject.h> #include <LibJS/Runtime/GlobalObject.h>
#include <LibJS/Runtime/IteratorOperations.h> #include <LibJS/Runtime/IteratorOperations.h>
#include <LibJS/Runtime/NativeFunction.h> #include <LibJS/Runtime/NativeFunction.h>
#include <LibJS/Runtime/OrdinaryFunctionObject.h>
#include <LibJS/Runtime/PromiseReaction.h> #include <LibJS/Runtime/PromiseReaction.h>
#include <LibJS/Runtime/Reference.h> #include <LibJS/Runtime/Reference.h>
#include <LibJS/Runtime/ScriptFunction.h>
#include <LibJS/Runtime/Symbol.h> #include <LibJS/Runtime/Symbol.h>
#include <LibJS/Runtime/TemporaryClearException.h> #include <LibJS/Runtime/TemporaryClearException.h>
#include <LibJS/Runtime/VM.h> #include <LibJS/Runtime/VM.h>

View file

@ -242,7 +242,7 @@ bool Value::is_constructor() const
return false; return false;
if (is<NativeFunction>(as_object())) if (is<NativeFunction>(as_object()))
return static_cast<const NativeFunction&>(as_object()).has_constructor(); return static_cast<const NativeFunction&>(as_object()).has_constructor();
// ScriptFunction or BoundFunction // OrdinaryFunctionObject or BoundFunction
return true; return true;
} }

View file

@ -6,7 +6,7 @@
#include <LibJS/Interpreter.h> #include <LibJS/Interpreter.h>
#include <LibJS/Parser.h> #include <LibJS/Parser.h>
#include <LibJS/Runtime/ScriptFunction.h> #include <LibJS/Runtime/OrdinaryFunctionObject.h>
#include <LibWeb/DOM/Document.h> #include <LibWeb/DOM/Document.h>
#include <LibWeb/DOM/EventListener.h> #include <LibWeb/DOM/EventListener.h>
#include <LibWeb/HTML/EventHandler.h> #include <LibWeb/HTML/EventHandler.h>
@ -49,7 +49,7 @@ void GlobalEventHandlers::set_event_handler_attribute(const FlyString& name, HTM
dbgln("Failed to parse script in event handler attribute '{}'", name); dbgln("Failed to parse script in event handler attribute '{}'", name);
return; return;
} }
auto* function = JS::ScriptFunction::create(self.script_execution_context()->interpreter().global_object(), name, program->body(), program->parameters(), program->function_length(), nullptr, JS::FunctionKind::Regular, false, false); auto* function = JS::OrdinaryFunctionObject::create(self.script_execution_context()->interpreter().global_object(), name, program->body(), program->parameters(), program->function_length(), nullptr, JS::FunctionKind::Regular, false, false);
VERIFY(function); VERIFY(function);
listener = adopt_ref(*new DOM::EventListener(JS::make_handle(static_cast<JS::FunctionObject*>(function)))); listener = adopt_ref(*new DOM::EventListener(JS::make_handle(static_cast<JS::FunctionObject*>(function))));
} }

View file

@ -7,7 +7,7 @@
#include <LibJS/Interpreter.h> #include <LibJS/Interpreter.h>
#include <LibJS/Parser.h> #include <LibJS/Parser.h>
#include <LibJS/Runtime/FunctionObject.h> #include <LibJS/Runtime/FunctionObject.h>
#include <LibJS/Runtime/ScriptFunction.h> #include <LibJS/Runtime/OrdinaryFunctionObject.h>
#include <LibProtocol/WebSocket.h> #include <LibProtocol/WebSocket.h>
#include <LibProtocol/WebSocketClient.h> #include <LibProtocol/WebSocketClient.h>
#include <LibWeb/Bindings/EventWrapper.h> #include <LibWeb/Bindings/EventWrapper.h>
@ -246,7 +246,7 @@ void WebSocket::set_event_handler_attribute(const FlyString& name, HTML::EventHa
dbgln("Failed to parse script in event handler attribute '{}'", name); dbgln("Failed to parse script in event handler attribute '{}'", name);
return; return;
} }
auto* function = JS::ScriptFunction::create(script_execution_context()->interpreter().global_object(), name, program->body(), program->parameters(), program->function_length(), nullptr, JS::FunctionKind::Regular, false, false); auto* function = JS::OrdinaryFunctionObject::create(script_execution_context()->interpreter().global_object(), name, program->body(), program->parameters(), program->function_length(), nullptr, JS::FunctionKind::Regular, false, false);
VERIFY(function); VERIFY(function);
listener = adopt_ref(*new DOM::EventListener(JS::make_handle(static_cast<JS::FunctionObject*>(function)))); listener = adopt_ref(*new DOM::EventListener(JS::make_handle(static_cast<JS::FunctionObject*>(function))));
} }

View file

@ -33,11 +33,11 @@
#include <LibJS/Runtime/NativeFunction.h> #include <LibJS/Runtime/NativeFunction.h>
#include <LibJS/Runtime/NumberObject.h> #include <LibJS/Runtime/NumberObject.h>
#include <LibJS/Runtime/Object.h> #include <LibJS/Runtime/Object.h>
#include <LibJS/Runtime/OrdinaryFunctionObject.h>
#include <LibJS/Runtime/PrimitiveString.h> #include <LibJS/Runtime/PrimitiveString.h>
#include <LibJS/Runtime/Promise.h> #include <LibJS/Runtime/Promise.h>
#include <LibJS/Runtime/ProxyObject.h> #include <LibJS/Runtime/ProxyObject.h>
#include <LibJS/Runtime/RegExpObject.h> #include <LibJS/Runtime/RegExpObject.h>
#include <LibJS/Runtime/ScriptFunction.h>
#include <LibJS/Runtime/Set.h> #include <LibJS/Runtime/Set.h>
#include <LibJS/Runtime/Shape.h> #include <LibJS/Runtime/Shape.h>
#include <LibJS/Runtime/StringObject.h> #include <LibJS/Runtime/StringObject.h>
@ -237,8 +237,8 @@ static void print_object(JS::Object& object, HashTable<JS::Object*>& seen_object
static void print_function(const JS::Object& object, HashTable<JS::Object*>&) static void print_function(const JS::Object& object, HashTable<JS::Object*>&)
{ {
print_type(object.class_name()); print_type(object.class_name());
if (is<JS::ScriptFunction>(object)) if (is<JS::OrdinaryFunctionObject>(object))
out(" {}", static_cast<const JS::ScriptFunction&>(object).name()); out(" {}", static_cast<const JS::OrdinaryFunctionObject&>(object).name());
else if (is<JS::NativeFunction>(object)) else if (is<JS::NativeFunction>(object))
out(" {}", static_cast<const JS::NativeFunction&>(object).name()); out(" {}", static_cast<const JS::NativeFunction&>(object).name());
} }