mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 19:32:45 +00:00 
			
		
		
		
	LibJS: Remove usage of define_native_property in OrdinaryFunctionObject
The length & name properties are supposed to be normal data properties.
This commit is contained in:
		
							parent
							
								
									b2e6088bff
								
							
						
					
					
						commit
						557424a141
					
				
					 2 changed files with 9 additions and 31 deletions
				
			
		|  | @ -24,18 +24,6 @@ | ||||||
| 
 | 
 | ||||||
| namespace JS { | namespace JS { | ||||||
| 
 | 
 | ||||||
| static OrdinaryFunctionObject* typed_this(VM& vm, GlobalObject& global_object) |  | ||||||
| { |  | ||||||
|     auto* this_object = vm.this_value(global_object).to_object(global_object); |  | ||||||
|     if (!this_object) |  | ||||||
|         return nullptr; |  | ||||||
|     if (!this_object->is_function()) { |  | ||||||
|         vm.throw_exception<TypeError>(global_object, ErrorType::NotAFunctionNoParam); |  | ||||||
|         return nullptr; |  | ||||||
|     } |  | ||||||
|     return static_cast<OrdinaryFunctionObject*>(this_object); |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| 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) | 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) | ||||||
| { | { | ||||||
|     Object* prototype = nullptr; |     Object* prototype = nullptr; | ||||||
|  | @ -99,8 +87,8 @@ void OrdinaryFunctionObject::initialize(GlobalObject& global_object) | ||||||
|         } |         } | ||||||
|         define_property(vm.names.prototype, prototype, Attribute::Writable); |         define_property(vm.names.prototype, prototype, Attribute::Writable); | ||||||
|     } |     } | ||||||
|     define_native_property(vm.names.length, length_getter, {}, Attribute::Configurable); |     define_property_or_throw(vm.names.length, { .value = Value(m_function_length), .writable = false, .enumerable = false, .configurable = true }); | ||||||
|     define_native_property(vm.names.name, name_getter, {}, Attribute::Configurable); |     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() | OrdinaryFunctionObject::~OrdinaryFunctionObject() | ||||||
|  | @ -246,20 +234,13 @@ Value OrdinaryFunctionObject::construct(FunctionObject&) | ||||||
|     return execute_function_body(); |     return execute_function_body(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| JS_DEFINE_NATIVE_GETTER(OrdinaryFunctionObject::length_getter) | void OrdinaryFunctionObject::set_name(const FlyString& name) | ||||||
| { | { | ||||||
|     auto* function = typed_this(vm, global_object); |     VERIFY(!name.is_null()); | ||||||
|     if (!function) |     auto& vm = this->vm(); | ||||||
|         return {}; |     m_name = name; | ||||||
|     return Value(static_cast<i32>(function->m_function_length)); |     auto success = define_property_or_throw(vm.names.name, { .value = js_string(vm, m_name), .writable = false, .enumerable = false, .configurable = true }); | ||||||
| } |     VERIFY(success); | ||||||
| 
 |  | ||||||
| JS_DEFINE_NATIVE_GETTER(OrdinaryFunctionObject::name_getter) |  | ||||||
| { |  | ||||||
|     auto* function = typed_this(vm, global_object); |  | ||||||
|     if (!function) |  | ||||||
|         return {}; |  | ||||||
|     return js_string(vm, function->name().is_null() ? "" : function->name()); |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -29,7 +29,7 @@ public: | ||||||
|     virtual Value construct(FunctionObject& new_target) override; |     virtual Value construct(FunctionObject& new_target) override; | ||||||
| 
 | 
 | ||||||
|     virtual const FlyString& name() const override { return m_name; }; |     virtual const FlyString& name() const override { return m_name; }; | ||||||
|     void set_name(const FlyString& name) { m_name = name; }; |     void set_name(const FlyString& name); | ||||||
| 
 | 
 | ||||||
|     void set_is_class_constructor() { m_is_class_constructor = true; }; |     void set_is_class_constructor() { m_is_class_constructor = true; }; | ||||||
| 
 | 
 | ||||||
|  | @ -49,9 +49,6 @@ private: | ||||||
| 
 | 
 | ||||||
|     Value execute_function_body(); |     Value execute_function_body(); | ||||||
| 
 | 
 | ||||||
|     JS_DECLARE_NATIVE_GETTER(length_getter); |  | ||||||
|     JS_DECLARE_NATIVE_GETTER(name_getter); |  | ||||||
| 
 |  | ||||||
|     FlyString m_name; |     FlyString m_name; | ||||||
|     NonnullRefPtr<Statement> m_body; |     NonnullRefPtr<Statement> m_body; | ||||||
|     const Vector<FunctionNode::Parameter> m_parameters; |     const Vector<FunctionNode::Parameter> m_parameters; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Idan Horowitz
						Idan Horowitz