mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 21:22:46 +00:00 
			
		
		
		
	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]].
This commit is contained in:
		
							parent
							
								
									d787775806
								
							
						
					
					
						commit
						e37cf73300
					
				
					 19 changed files with 55 additions and 57 deletions
				
			
		|  | @ -18,6 +18,7 @@ | |||
| #include <LibJS/Runtime/Accessor.h> | ||||
| #include <LibJS/Runtime/Array.h> | ||||
| #include <LibJS/Runtime/BigInt.h> | ||||
| #include <LibJS/Runtime/ECMAScriptFunctionObject.h> | ||||
| #include <LibJS/Runtime/Error.h> | ||||
| #include <LibJS/Runtime/FunctionEnvironment.h> | ||||
| #include <LibJS/Runtime/GlobalObject.h> | ||||
|  | @ -25,7 +26,6 @@ | |||
| #include <LibJS/Runtime/MarkedValueList.h> | ||||
| #include <LibJS/Runtime/NativeFunction.h> | ||||
| #include <LibJS/Runtime/ObjectEnvironment.h> | ||||
| #include <LibJS/Runtime/OrdinaryFunctionObject.h> | ||||
| #include <LibJS/Runtime/PrimitiveString.h> | ||||
| #include <LibJS/Runtime/Reference.h> | ||||
| #include <LibJS/Runtime/RegExpObject.h> | ||||
|  | @ -68,8 +68,8 @@ static void update_function_name(Value value, FlyString const& name) | |||
|     if (!value.is_function()) | ||||
|         return; | ||||
|     auto& function = value.as_function(); | ||||
|     if (is<OrdinaryFunctionObject>(function) && function.name().is_empty()) | ||||
|         static_cast<OrdinaryFunctionObject&>(function).set_name(name); | ||||
|     if (is<ECMAScriptFunctionObject>(function) && function.name().is_empty()) | ||||
|         static_cast<ECMAScriptFunctionObject&>(function).set_name(name); | ||||
| } | ||||
| 
 | ||||
| static String get_function_name(GlobalObject& global_object, Value value) | ||||
|  | @ -111,7 +111,7 @@ Value FunctionExpression::execute(Interpreter& interpreter, GlobalObject& global | |||
|         func_env->create_immutable_binding(global_object, name(), false); | ||||
|     } | ||||
| 
 | ||||
|     auto closure = OrdinaryFunctionObject::create(global_object, name(), body(), parameters(), function_length(), func_env, kind(), is_strict_mode(), is_arrow_function()); | ||||
|     auto closure = ECMAScriptFunctionObject::create(global_object, name(), body(), parameters(), function_length(), func_env, kind(), is_strict_mode(), is_arrow_function()); | ||||
| 
 | ||||
|     if (has_identifier) | ||||
|         func_env->initialize_binding(global_object, name(), closure); | ||||
|  | @ -874,8 +874,8 @@ Value ClassExpression::execute(Interpreter& interpreter, GlobalObject& global_ob | |||
| 
 | ||||
|     update_function_name(class_constructor_value, m_name); | ||||
| 
 | ||||
|     VERIFY(class_constructor_value.is_function() && is<OrdinaryFunctionObject>(class_constructor_value.as_function())); | ||||
|     auto* class_constructor = static_cast<OrdinaryFunctionObject*>(&class_constructor_value.as_function()); | ||||
|     VERIFY(class_constructor_value.is_function() && is<ECMAScriptFunctionObject>(class_constructor_value.as_function())); | ||||
|     auto* class_constructor = static_cast<ECMAScriptFunctionObject*>(&class_constructor_value.as_function()); | ||||
|     class_constructor->set_is_class_constructor(); | ||||
|     Value super_constructor = js_undefined(); | ||||
|     if (!m_super_class.is_null()) { | ||||
|  | @ -970,7 +970,7 @@ Value ClassExpression::execute(Interpreter& interpreter, GlobalObject& global_ob | |||
|             auto copy_initializer = field.initializer(); | ||||
|             auto body = create_ast_node<ExpressionStatement>(field.initializer()->source_range(), copy_initializer.release_nonnull()); | ||||
|             // FIXME: A potential optimization is not creating the functions here since these are never directly accessible.
 | ||||
|             initializer = OrdinaryFunctionObject::create(interpreter.global_object(), property_key.to_display_string(), *body, {}, 0, interpreter.lexical_environment(), FunctionKind::Regular, false); | ||||
|             initializer = ECMAScriptFunctionObject::create(interpreter.global_object(), property_key.to_display_string(), *body, {}, 0, interpreter.lexical_environment(), FunctionKind::Regular, false); | ||||
|             initializer->set_home_object(field.is_static() ? class_constructor : &class_prototype.as_object()); | ||||
|         } | ||||
| 
 | ||||
|  |  | |||
|  | @ -12,10 +12,10 @@ | |||
| #include <LibJS/Runtime/Array.h> | ||||
| #include <LibJS/Runtime/BigInt.h> | ||||
| #include <LibJS/Runtime/DeclarativeEnvironment.h> | ||||
| #include <LibJS/Runtime/ECMAScriptFunctionObject.h> | ||||
| #include <LibJS/Runtime/Environment.h> | ||||
| #include <LibJS/Runtime/GlobalObject.h> | ||||
| #include <LibJS/Runtime/IteratorOperations.h> | ||||
| #include <LibJS/Runtime/OrdinaryFunctionObject.h> | ||||
| #include <LibJS/Runtime/RegExpObject.h> | ||||
| #include <LibJS/Runtime/Value.h> | ||||
| 
 | ||||
|  | @ -318,7 +318,7 @@ void Call::execute_impl(Bytecode::Interpreter& interpreter) const | |||
| void NewFunction::execute_impl(Bytecode::Interpreter& interpreter) const | ||||
| { | ||||
|     auto& vm = interpreter.vm(); | ||||
|     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()); | ||||
|     interpreter.accumulator() = ECMAScriptFunctionObject::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 | ||||
|  |  | |||
|  | @ -53,6 +53,7 @@ set(SOURCES | |||
|     Runtime/DateConstructor.cpp | ||||
|     Runtime/DatePrototype.cpp | ||||
|     Runtime/DeclarativeEnvironment.cpp | ||||
|     Runtime/ECMAScriptFunctionObject.cpp | ||||
|     Runtime/Environment.cpp | ||||
|     Runtime/Error.cpp | ||||
|     Runtime/ErrorConstructor.cpp | ||||
|  | @ -105,7 +106,6 @@ set(SOURCES | |||
|     Runtime/ObjectConstructor.cpp | ||||
|     Runtime/ObjectEnvironment.cpp | ||||
|     Runtime/ObjectPrototype.cpp | ||||
|     Runtime/OrdinaryFunctionObject.cpp | ||||
|     Runtime/PrimitiveString.cpp | ||||
|     Runtime/Promise.cpp | ||||
|     Runtime/PromiseConstructor.cpp | ||||
|  |  | |||
|  | @ -8,10 +8,10 @@ | |||
| #include <AK/ScopeGuard.h> | ||||
| #include <LibJS/AST.h> | ||||
| #include <LibJS/Interpreter.h> | ||||
| #include <LibJS/Runtime/ECMAScriptFunctionObject.h> | ||||
| #include <LibJS/Runtime/FunctionEnvironment.h> | ||||
| #include <LibJS/Runtime/GlobalEnvironment.h> | ||||
| #include <LibJS/Runtime/GlobalObject.h> | ||||
| #include <LibJS/Runtime/OrdinaryFunctionObject.h> | ||||
| #include <LibJS/Runtime/Reference.h> | ||||
| #include <LibJS/Runtime/Shape.h> | ||||
| #include <LibJS/Runtime/Value.h> | ||||
|  | @ -100,7 +100,7 @@ void Interpreter::enter_scope(const ScopeNode& scope_node, ScopeType scope_type, | |||
|             lexical_environment()->put_into_environment(declaration.name(), { js_undefined(), DeclarationKind::Var }); | ||||
|         } | ||||
|         for (auto& declaration : scope_node.functions()) { | ||||
|             auto* function = OrdinaryFunctionObject::create(global_object, declaration.name(), declaration.body(), declaration.parameters(), declaration.function_length(), lexical_environment(), declaration.kind(), declaration.is_strict_mode()); | ||||
|             auto* function = ECMAScriptFunctionObject::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); | ||||
|         } | ||||
|     }); | ||||
|  |  | |||
|  | @ -12,18 +12,18 @@ | |||
| #include <LibJS/Bytecode/Interpreter.h> | ||||
| #include <LibJS/Interpreter.h> | ||||
| #include <LibJS/Runtime/Array.h> | ||||
| #include <LibJS/Runtime/ECMAScriptFunctionObject.h> | ||||
| #include <LibJS/Runtime/Error.h> | ||||
| #include <LibJS/Runtime/FunctionEnvironment.h> | ||||
| #include <LibJS/Runtime/GeneratorObject.h> | ||||
| #include <LibJS/Runtime/GeneratorObjectPrototype.h> | ||||
| #include <LibJS/Runtime/GlobalObject.h> | ||||
| #include <LibJS/Runtime/NativeFunction.h> | ||||
| #include <LibJS/Runtime/OrdinaryFunctionObject.h> | ||||
| #include <LibJS/Runtime/Value.h> | ||||
| 
 | ||||
| namespace JS { | ||||
| 
 | ||||
| OrdinaryFunctionObject* OrdinaryFunctionObject::create(GlobalObject& global_object, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, Environment* parent_scope, FunctionKind kind, bool is_strict, bool is_arrow_function) | ||||
| ECMAScriptFunctionObject* ECMAScriptFunctionObject::create(GlobalObject& global_object, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, Environment* parent_scope, FunctionKind kind, bool is_strict, bool is_arrow_function) | ||||
| { | ||||
|     Object* prototype = nullptr; | ||||
|     switch (kind) { | ||||
|  | @ -34,10 +34,10 @@ OrdinaryFunctionObject* OrdinaryFunctionObject::create(GlobalObject& global_obje | |||
|         prototype = global_object.generator_function_prototype(); | ||||
|         break; | ||||
|     } | ||||
|     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); | ||||
|     return global_object.heap().allocate<ECMAScriptFunctionObject>(global_object, global_object, name, body, move(parameters), m_function_length, parent_scope, *prototype, kind, is_strict, is_arrow_function); | ||||
| } | ||||
| 
 | ||||
| OrdinaryFunctionObject::OrdinaryFunctionObject(GlobalObject& global_object, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 function_length, Environment* parent_scope, Object& prototype, FunctionKind kind, bool is_strict, bool is_arrow_function) | ||||
| ECMAScriptFunctionObject::ECMAScriptFunctionObject(GlobalObject& global_object, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 function_length, Environment* parent_scope, Object& prototype, FunctionKind kind, bool is_strict, bool is_arrow_function) | ||||
|     : FunctionObject(is_arrow_function ? vm().this_value(global_object) : Value(), {}, prototype) | ||||
|     , m_name(name) | ||||
|     , m_body(body) | ||||
|  | @ -69,7 +69,7 @@ OrdinaryFunctionObject::OrdinaryFunctionObject(GlobalObject& global_object, cons | |||
|     })); | ||||
| } | ||||
| 
 | ||||
| void OrdinaryFunctionObject::initialize(GlobalObject& global_object) | ||||
| void ECMAScriptFunctionObject::initialize(GlobalObject& global_object) | ||||
| { | ||||
|     auto& vm = this->vm(); | ||||
|     Base::initialize(global_object); | ||||
|  | @ -90,18 +90,18 @@ void OrdinaryFunctionObject::initialize(GlobalObject& global_object) | |||
|     define_property_or_throw(vm.names.name, { .value = js_string(vm, m_name.is_null() ? "" : m_name), .writable = false, .enumerable = false, .configurable = true }); | ||||
| } | ||||
| 
 | ||||
| OrdinaryFunctionObject::~OrdinaryFunctionObject() | ||||
| ECMAScriptFunctionObject::~ECMAScriptFunctionObject() | ||||
| { | ||||
| } | ||||
| 
 | ||||
| void OrdinaryFunctionObject::visit_edges(Visitor& visitor) | ||||
| void ECMAScriptFunctionObject::visit_edges(Visitor& visitor) | ||||
| { | ||||
|     Base::visit_edges(visitor); | ||||
|     visitor.visit(m_environment); | ||||
|     visitor.visit(m_realm); | ||||
| } | ||||
| 
 | ||||
| FunctionEnvironment* OrdinaryFunctionObject::create_environment(FunctionObject& function_being_invoked) | ||||
| FunctionEnvironment* ECMAScriptFunctionObject::create_environment(FunctionObject& function_being_invoked) | ||||
| { | ||||
|     HashMap<FlyString, Variable> variables; | ||||
|     for (auto& parameter : m_parameters) { | ||||
|  | @ -140,7 +140,7 @@ FunctionEnvironment* OrdinaryFunctionObject::create_environment(FunctionObject& | |||
|     return environment; | ||||
| } | ||||
| 
 | ||||
| Value OrdinaryFunctionObject::execute_function_body() | ||||
| Value ECMAScriptFunctionObject::execute_function_body() | ||||
| { | ||||
|     auto& vm = this->vm(); | ||||
| 
 | ||||
|  | @ -217,7 +217,7 @@ Value OrdinaryFunctionObject::execute_function_body() | |||
|     } | ||||
| } | ||||
| 
 | ||||
| Value OrdinaryFunctionObject::call() | ||||
| Value ECMAScriptFunctionObject::call() | ||||
| { | ||||
|     if (m_is_class_constructor) { | ||||
|         vm().throw_exception<TypeError>(global_object(), ErrorType::ClassConstructorWithoutNew, m_name); | ||||
|  | @ -226,7 +226,7 @@ Value OrdinaryFunctionObject::call() | |||
|     return execute_function_body(); | ||||
| } | ||||
| 
 | ||||
| Value OrdinaryFunctionObject::construct(FunctionObject&) | ||||
| Value ECMAScriptFunctionObject::construct(FunctionObject&) | ||||
| { | ||||
|     if (m_is_arrow_function || m_kind == FunctionKind::Generator) { | ||||
|         vm().throw_exception<TypeError>(global_object(), ErrorType::NotAConstructor, m_name); | ||||
|  | @ -235,7 +235,7 @@ Value OrdinaryFunctionObject::construct(FunctionObject&) | |||
|     return execute_function_body(); | ||||
| } | ||||
| 
 | ||||
| void OrdinaryFunctionObject::set_name(const FlyString& name) | ||||
| void ECMAScriptFunctionObject::set_name(const FlyString& name) | ||||
| { | ||||
|     VERIFY(!name.is_null()); | ||||
|     auto& vm = this->vm(); | ||||
|  | @ -12,15 +12,16 @@ | |||
| 
 | ||||
| namespace JS { | ||||
| 
 | ||||
| class OrdinaryFunctionObject final : public FunctionObject { | ||||
|     JS_OBJECT(OrdinaryFunctionObject, FunctionObject); | ||||
| // 10.2 ECMAScript Function Objects, https://tc39.es/ecma262/#sec-ecmascript-function-objects
 | ||||
| class ECMAScriptFunctionObject final : public FunctionObject { | ||||
|     JS_OBJECT(ECMAScriptFunctionObject, FunctionObject); | ||||
| 
 | ||||
| public: | ||||
|     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); | ||||
|     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); | ||||
| 
 | ||||
|     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); | ||||
|     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 ~OrdinaryFunctionObject(); | ||||
|     virtual ~ECMAScriptFunctionObject(); | ||||
| 
 | ||||
|     const Statement& body() const { return m_body; } | ||||
|     const Vector<FunctionNode::Parameter>& parameters() const { return m_parameters; }; | ||||
|  | @ -42,7 +43,7 @@ protected: | |||
|     virtual bool is_strict_mode() const final { return m_is_strict; } | ||||
| 
 | ||||
| private: | ||||
|     virtual bool is_ordinary_function_object() const override { return true; } | ||||
|     virtual bool is_ecmascript_function_object() const override { return true; } | ||||
|     virtual FunctionEnvironment* create_environment(FunctionObject&) override; | ||||
|     virtual void visit_edges(Visitor&) override; | ||||
| 
 | ||||
|  | @ -11,7 +11,6 @@ | |||
| 
 | ||||
| namespace JS { | ||||
| 
 | ||||
| // 10.2 ECMAScript Function Objects, https://tc39.es/ecma262/#sec-ecmascript-function-objects
 | ||||
| class FunctionObject : public Object { | ||||
|     JS_OBJECT(Function, Object); | ||||
| 
 | ||||
|  |  | |||
|  | @ -9,13 +9,13 @@ | |||
| #include <LibJS/Interpreter.h> | ||||
| #include <LibJS/Runtime/AbstractOperations.h> | ||||
| #include <LibJS/Runtime/BoundFunction.h> | ||||
| #include <LibJS/Runtime/ECMAScriptFunctionObject.h> | ||||
| #include <LibJS/Runtime/Error.h> | ||||
| #include <LibJS/Runtime/FunctionObject.h> | ||||
| #include <LibJS/Runtime/FunctionPrototype.h> | ||||
| #include <LibJS/Runtime/GlobalObject.h> | ||||
| #include <LibJS/Runtime/MarkedValueList.h> | ||||
| #include <LibJS/Runtime/NativeFunction.h> | ||||
| #include <LibJS/Runtime/OrdinaryFunctionObject.h> | ||||
| 
 | ||||
| namespace JS { | ||||
| 
 | ||||
|  | @ -117,11 +117,11 @@ JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::to_string) | |||
|     String function_parameters; | ||||
|     String function_body; | ||||
| 
 | ||||
|     if (is<OrdinaryFunctionObject>(this_object)) { | ||||
|         auto& ordinary_function = static_cast<OrdinaryFunctionObject&>(*this_object); | ||||
|     if (is<ECMAScriptFunctionObject>(this_object)) { | ||||
|         auto& function = static_cast<ECMAScriptFunctionObject&>(*this_object); | ||||
|         StringBuilder parameters_builder; | ||||
|         auto first = true; | ||||
|         for (auto& parameter : ordinary_function.parameters()) { | ||||
|         for (auto& parameter : function.parameters()) { | ||||
|             // FIXME: Also stringify binding patterns.
 | ||||
|             if (auto* name_ptr = parameter.binding.get_pointer<FlyString>()) { | ||||
|                 if (!first) | ||||
|  | @ -134,10 +134,10 @@ JS_DEFINE_NATIVE_FUNCTION(FunctionPrototype::to_string) | |||
|                 } | ||||
|             } | ||||
|         } | ||||
|         function_name = ordinary_function.name(); | ||||
|         function_name = function.name(); | ||||
|         function_parameters = parameters_builder.build(); | ||||
|         // FIXME: ASTNodes should be able to dump themselves to source strings - something like this:
 | ||||
|         // auto& body = static_cast<OrdinaryFunctionObject*>(this_object)->body();
 | ||||
|         // auto& body = static_cast<ECMAScriptFunctionObject*>(this_object)->body();
 | ||||
|         // function_body = body.to_source();
 | ||||
|         function_body = "  ???"; | ||||
|     } else { | ||||
|  |  | |||
|  | @ -9,10 +9,10 @@ | |||
| #include <LibJS/Bytecode/Interpreter.h> | ||||
| #include <LibJS/Lexer.h> | ||||
| #include <LibJS/Parser.h> | ||||
| #include <LibJS/Runtime/ECMAScriptFunctionObject.h> | ||||
| #include <LibJS/Runtime/FunctionConstructor.h> | ||||
| #include <LibJS/Runtime/GeneratorFunctionConstructor.h> | ||||
| #include <LibJS/Runtime/GlobalObject.h> | ||||
| #include <LibJS/Runtime/OrdinaryFunctionObject.h> | ||||
| 
 | ||||
| namespace JS { | ||||
| 
 | ||||
|  | @ -62,7 +62,7 @@ Value GeneratorFunctionConstructor::construct(FunctionObject& new_target) | |||
|             block.dump(executable); | ||||
|     } | ||||
| 
 | ||||
|     return OrdinaryFunctionObject::create(global_object(), function->name(), function->body(), function->parameters(), function->function_length(), vm().lexical_environment(), FunctionKind::Generator, function->is_strict_mode(), false); | ||||
|     return ECMAScriptFunctionObject::create(global_object(), function->name(), function->body(), function->parameters(), function->function_length(), vm().lexical_environment(), FunctionKind::Generator, function->is_strict_mode(), false); | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -13,7 +13,7 @@ | |||
| 
 | ||||
| namespace JS { | ||||
| 
 | ||||
| GeneratorObject* GeneratorObject::create(GlobalObject& global_object, Value initial_value, OrdinaryFunctionObject* generating_function, Environment* generating_scope, Bytecode::RegisterWindow frame) | ||||
| GeneratorObject* GeneratorObject::create(GlobalObject& global_object, Value initial_value, ECMAScriptFunctionObject* generating_function, Environment* generating_scope, Bytecode::RegisterWindow frame) | ||||
| { | ||||
|     // 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); | ||||
|  |  | |||
|  | @ -7,8 +7,8 @@ | |||
| #pragma once | ||||
| 
 | ||||
| #include <LibJS/Bytecode/Interpreter.h> | ||||
| #include <LibJS/Runtime/ECMAScriptFunctionObject.h> | ||||
| #include <LibJS/Runtime/Object.h> | ||||
| #include <LibJS/Runtime/OrdinaryFunctionObject.h> | ||||
| 
 | ||||
| namespace JS { | ||||
| 
 | ||||
|  | @ -16,7 +16,7 @@ class GeneratorObject final : public Object { | |||
|     JS_OBJECT(GeneratorObject, Object); | ||||
| 
 | ||||
| public: | ||||
|     static GeneratorObject* create(GlobalObject&, Value, OrdinaryFunctionObject*, Environment*, Bytecode::RegisterWindow); | ||||
|     static GeneratorObject* create(GlobalObject&, Value, ECMAScriptFunctionObject*, Environment*, Bytecode::RegisterWindow); | ||||
|     GeneratorObject(GlobalObject&, Object& prototype); | ||||
|     virtual void initialize(GlobalObject&) override; | ||||
|     virtual ~GeneratorObject() override; | ||||
|  | @ -27,7 +27,7 @@ public: | |||
| 
 | ||||
| private: | ||||
|     Environment* m_environment { nullptr }; | ||||
|     OrdinaryFunctionObject* m_generating_function { nullptr }; | ||||
|     ECMAScriptFunctionObject* m_generating_function { nullptr }; | ||||
|     Value m_previous_value; | ||||
|     Bytecode::RegisterWindow m_frame; | ||||
|     bool m_done { false }; | ||||
|  |  | |||
|  | @ -136,7 +136,7 @@ public: | |||
|     virtual bool is_global_object() const { return false; } | ||||
|     virtual bool is_proxy_object() const { return false; } | ||||
|     virtual bool is_native_function() const { return false; } | ||||
|     virtual bool is_ordinary_function_object() const { return false; } | ||||
|     virtual bool is_ecmascript_function_object() const { return false; } | ||||
| 
 | ||||
|     // B.3.7 The [[IsHTMLDDA]] Internal Slot, https://tc39.es/ecma262/#sec-IsHTMLDDA-internal-slot
 | ||||
|     virtual bool is_htmldda() const { return false; } | ||||
|  |  | |||
|  | @ -12,6 +12,7 @@ | |||
| #include <LibJS/Runtime/AbstractOperations.h> | ||||
| #include <LibJS/Runtime/Array.h> | ||||
| #include <LibJS/Runtime/BoundFunction.h> | ||||
| #include <LibJS/Runtime/ECMAScriptFunctionObject.h> | ||||
| #include <LibJS/Runtime/Error.h> | ||||
| #include <LibJS/Runtime/FinalizationRegistry.h> | ||||
| #include <LibJS/Runtime/FunctionEnvironment.h> | ||||
|  | @ -19,7 +20,6 @@ | |||
| #include <LibJS/Runtime/GlobalObject.h> | ||||
| #include <LibJS/Runtime/IteratorOperations.h> | ||||
| #include <LibJS/Runtime/NativeFunction.h> | ||||
| #include <LibJS/Runtime/OrdinaryFunctionObject.h> | ||||
| #include <LibJS/Runtime/PromiseReaction.h> | ||||
| #include <LibJS/Runtime/Reference.h> | ||||
| #include <LibJS/Runtime/Symbol.h> | ||||
|  | @ -377,7 +377,7 @@ Value VM::get_variable(const FlyString& name, GlobalObject& global_object) | |||
|                 if (context.function->is_strict_mode() || !context.function->has_simple_parameter_list()) { | ||||
|                     context.arguments_object = create_unmapped_arguments_object(global_object, context.arguments.span()); | ||||
|                 } else { | ||||
|                     context.arguments_object = create_mapped_arguments_object(global_object, *context.function, verify_cast<OrdinaryFunctionObject>(context.function)->parameters(), context.arguments.span(), *lexical_environment()); | ||||
|                     context.arguments_object = create_mapped_arguments_object(global_object, *context.function, verify_cast<ECMAScriptFunctionObject>(context.function)->parameters(), context.arguments.span(), *lexical_environment()); | ||||
|                 } | ||||
|             } | ||||
|             return context.arguments_object; | ||||
|  | @ -479,7 +479,7 @@ Value VM::construct(FunctionObject& function, FunctionObject& new_target, Option | |||
|         this_argument = TRY_OR_DISCARD(ordinary_create_from_constructor<Object>(global_object, new_target, &GlobalObject::object_prototype)); | ||||
| 
 | ||||
|     // FIXME: prepare_for_ordinary_call() is not supposed to receive a BoundFunction, ProxyObject, etc. - ever.
 | ||||
|     //        This needs to be moved to NativeFunction/OrdinaryFunctionObject's construct() (10.2.2 [[Construct]])
 | ||||
|     //        This needs to be moved to NativeFunction/ECMAScriptFunctionObject's construct() (10.2.2 [[Construct]])
 | ||||
|     ExecutionContext callee_context(heap()); | ||||
|     prepare_for_ordinary_call(function, callee_context, &new_target); | ||||
|     if (exception()) | ||||
|  | @ -677,7 +677,7 @@ ThrowCompletionOr<Value> VM::call_internal(FunctionObject& function, Value this_ | |||
|     } | ||||
| 
 | ||||
|     // FIXME: prepare_for_ordinary_call() is not supposed to receive a BoundFunction, ProxyObject, etc. - ever.
 | ||||
|     //        This needs to be moved to NativeFunction/OrdinaryFunctionObject's construct() (10.2.2 [[Construct]])
 | ||||
|     //        This needs to be moved to NativeFunction/ECMAScriptFunctionObject's construct() (10.2.2 [[Construct]])
 | ||||
|     ExecutionContext callee_context(heap()); | ||||
|     prepare_for_ordinary_call(function, callee_context, nullptr); | ||||
|     if (auto* exception = this->exception()) | ||||
|  |  | |||
|  | @ -237,7 +237,7 @@ bool Value::is_constructor() const | |||
|         return static_cast<const NativeFunction&>(as_object()).has_constructor(); | ||||
|     if (is<BoundFunction>(as_object())) | ||||
|         return Value(&static_cast<const BoundFunction&>(as_object()).target_function()).is_constructor(); | ||||
|     // OrdinaryFunctionObject
 | ||||
|     // ECMAScriptFunctionObject
 | ||||
|     return true; | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -15,7 +15,7 @@ test("bad argument values", () => { | |||
|         [{}, "[object Object]"], | ||||
|         [true, "true"], | ||||
|         ["foobar", "foobar"], | ||||
|         [function () {}, "[object OrdinaryFunctionObject]"], // FIXME: Better function stringification
 | ||||
|         [function () {}, "[object ECMAScriptFunctionObject]"], // FIXME: Better function stringification
 | ||||
|     ].forEach(testCase => { | ||||
|         expect(() => { | ||||
|             Symbol.keyFor(testCase[0]); | ||||
|  |  | |||
|  | @ -7,7 +7,7 @@ | |||
| #include <AK/StringBuilder.h> | ||||
| #include <LibJS/Interpreter.h> | ||||
| #include <LibJS/Parser.h> | ||||
| #include <LibJS/Runtime/OrdinaryFunctionObject.h> | ||||
| #include <LibJS/Runtime/ECMAScriptFunctionObject.h> | ||||
| #include <LibWeb/Bindings/ScriptExecutionContext.h> | ||||
| #include <LibWeb/DOM/Document.h> | ||||
| #include <LibWeb/DOM/Event.h> | ||||
|  | @ -133,7 +133,7 @@ void EventTarget::set_event_handler_attribute(FlyString const& name, HTML::Event | |||
|             dbgln("Failed to parse script in event handler attribute '{}'", name); | ||||
|             return; | ||||
|         } | ||||
|         auto* function = JS::OrdinaryFunctionObject::create(target->script_execution_context()->realm().global_object(), name, program->body(), program->parameters(), program->function_length(), nullptr, JS::FunctionKind::Regular, false, false); | ||||
|         auto* function = JS::ECMAScriptFunctionObject::create(target->script_execution_context()->realm().global_object(), name, program->body(), program->parameters(), program->function_length(), nullptr, JS::FunctionKind::Regular, false, false); | ||||
|         VERIFY(function); | ||||
|         listener = adopt_ref(*new DOM::EventListener(JS::make_handle(static_cast<JS::FunctionObject*>(function)))); | ||||
|     } | ||||
|  |  | |||
|  | @ -6,7 +6,6 @@ | |||
| 
 | ||||
| #include <LibJS/Interpreter.h> | ||||
| #include <LibJS/Parser.h> | ||||
| #include <LibJS/Runtime/OrdinaryFunctionObject.h> | ||||
| #include <LibWeb/DOM/Document.h> | ||||
| #include <LibWeb/DOM/EventListener.h> | ||||
| #include <LibWeb/HTML/EventHandler.h> | ||||
|  |  | |||
|  | @ -7,7 +7,6 @@ | |||
| #include <LibJS/Interpreter.h> | ||||
| #include <LibJS/Parser.h> | ||||
| #include <LibJS/Runtime/FunctionObject.h> | ||||
| #include <LibJS/Runtime/OrdinaryFunctionObject.h> | ||||
| #include <LibProtocol/WebSocket.h> | ||||
| #include <LibProtocol/WebSocketClient.h> | ||||
| #include <LibWeb/Bindings/EventWrapper.h> | ||||
|  |  | |||
|  | @ -26,6 +26,7 @@ | |||
| #include <LibJS/Runtime/BooleanObject.h> | ||||
| #include <LibJS/Runtime/DataView.h> | ||||
| #include <LibJS/Runtime/Date.h> | ||||
| #include <LibJS/Runtime/ECMAScriptFunctionObject.h> | ||||
| #include <LibJS/Runtime/Error.h> | ||||
| #include <LibJS/Runtime/FunctionObject.h> | ||||
| #include <LibJS/Runtime/GlobalObject.h> | ||||
|  | @ -38,7 +39,6 @@ | |||
| #include <LibJS/Runtime/NativeFunction.h> | ||||
| #include <LibJS/Runtime/NumberObject.h> | ||||
| #include <LibJS/Runtime/Object.h> | ||||
| #include <LibJS/Runtime/OrdinaryFunctionObject.h> | ||||
| #include <LibJS/Runtime/PrimitiveString.h> | ||||
| #include <LibJS/Runtime/Promise.h> | ||||
| #include <LibJS/Runtime/ProxyObject.h> | ||||
|  | @ -255,8 +255,8 @@ static void print_object(JS::Object& object, HashTable<JS::Object*>& seen_object | |||
| static void print_function(JS::Object const& object, HashTable<JS::Object*>&) | ||||
| { | ||||
|     print_type(object.class_name()); | ||||
|     if (is<JS::OrdinaryFunctionObject>(object)) | ||||
|         out(" {}", static_cast<JS::OrdinaryFunctionObject const&>(object).name()); | ||||
|     if (is<JS::ECMAScriptFunctionObject>(object)) | ||||
|         out(" {}", static_cast<JS::ECMAScriptFunctionObject const&>(object).name()); | ||||
|     else if (is<JS::NativeFunction>(object)) | ||||
|         out(" {}", static_cast<JS::NativeFunction const&>(object).name()); | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Linus Groh
						Linus Groh