mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 14:28:12 +00:00
LibJS: Initialize {Async,}{Generator,}Function constructors properly
We were previously manually initializing them instead of just calling GlobalObject::initialize_constructor, which aside from duplicating code also meant we didn't set the required name property.
This commit is contained in:
parent
de238ff351
commit
08d1ae58b1
2 changed files with 6 additions and 15 deletions
|
@ -291,22 +291,13 @@ void GlobalObject::initialize_global_object()
|
||||||
#undef __JS_ENUMERATE
|
#undef __JS_ENUMERATE
|
||||||
|
|
||||||
// NOTE: These constructors cannot be initialized with add_constructor as they have no global binding.
|
// NOTE: These constructors cannot be initialized with add_constructor as they have no global binding.
|
||||||
m_generator_function_constructor = heap().allocate<GeneratorFunctionConstructor>(*this, *this);
|
initialize_constructor(vm.names.GeneratorFunction, m_generator_function_constructor, m_generator_function_prototype, Attribute::Configurable);
|
||||||
m_async_generator_function_constructor = heap().allocate<AsyncGeneratorFunctionConstructor>(*this, *this);
|
initialize_constructor(vm.names.AsyncGeneratorFunction, m_async_generator_function_constructor, m_async_generator_function_prototype, Attribute::Configurable);
|
||||||
m_async_function_constructor = heap().allocate<AsyncFunctionConstructor>(*this, *this);
|
initialize_constructor(vm.names.AsyncFunction, m_async_function_constructor, m_async_function_prototype, Attribute::Configurable);
|
||||||
|
|
||||||
// 27.3.3.1 GeneratorFunction.prototype.constructor, https://tc39.es/ecma262/#sec-generatorfunction.prototype.constructor
|
|
||||||
m_generator_function_prototype->define_direct_property(vm.names.constructor, m_generator_function_constructor, Attribute::Configurable);
|
|
||||||
|
|
||||||
// 27.4.3.1 AsyncGeneratorFunction.prototype.constructor, https://tc39.es/ecma262/#sec-asyncgeneratorfunction-prototype-constructor
|
|
||||||
m_async_generator_function_prototype->define_direct_property(vm.names.constructor, m_async_generator_function_constructor, Attribute::Configurable);
|
|
||||||
|
|
||||||
// 27.5.1.1 Generator.prototype.constructor, https://tc39.es/ecma262/#sec-generator.prototype.constructor
|
// 27.5.1.1 Generator.prototype.constructor, https://tc39.es/ecma262/#sec-generator.prototype.constructor
|
||||||
m_generator_prototype->define_direct_property(vm.names.constructor, m_generator_function_prototype, Attribute::Configurable);
|
m_generator_prototype->define_direct_property(vm.names.constructor, m_generator_function_prototype, Attribute::Configurable);
|
||||||
|
|
||||||
// 27.7.3.1 AsyncFunction.prototype.constructor, https://tc39.es/ecma262/#sec-async-function-prototype-properties-constructor
|
|
||||||
m_async_function_prototype->define_direct_property(vm.names.constructor, m_async_function_constructor, Attribute::Configurable);
|
|
||||||
|
|
||||||
m_array_prototype_values_function = &m_array_prototype->get_without_side_effects(vm.names.values).as_function();
|
m_array_prototype_values_function = &m_array_prototype->get_without_side_effects(vm.names.values).as_function();
|
||||||
m_date_constructor_now_function = &m_date_constructor->get_without_side_effects(vm.names.now).as_function();
|
m_date_constructor_now_function = &m_date_constructor->get_without_side_effects(vm.names.now).as_function();
|
||||||
m_eval_function = &get_without_side_effects(vm.names.eval).as_function();
|
m_eval_function = &get_without_side_effects(vm.names.eval).as_function();
|
||||||
|
|
|
@ -74,7 +74,7 @@ protected:
|
||||||
virtual void visit_edges(Visitor&) override;
|
virtual void visit_edges(Visitor&) override;
|
||||||
|
|
||||||
template<typename ConstructorType>
|
template<typename ConstructorType>
|
||||||
void initialize_constructor(PropertyKey const&, ConstructorType*&, Object* prototype);
|
void initialize_constructor(PropertyKey const&, ConstructorType*&, Object* prototype, PropertyAttributes = Attribute::Writable | Attribute::Configurable);
|
||||||
template<typename ConstructorType>
|
template<typename ConstructorType>
|
||||||
void add_constructor(PropertyKey const&, ConstructorType*&, Object* prototype);
|
void add_constructor(PropertyKey const&, ConstructorType*&, Object* prototype);
|
||||||
|
|
||||||
|
@ -143,13 +143,13 @@ private:
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename ConstructorType>
|
template<typename ConstructorType>
|
||||||
inline void GlobalObject::initialize_constructor(PropertyKey const& property_key, ConstructorType*& constructor, Object* prototype)
|
inline void GlobalObject::initialize_constructor(PropertyKey const& property_key, ConstructorType*& constructor, Object* prototype, PropertyAttributes attributes)
|
||||||
{
|
{
|
||||||
auto& vm = this->vm();
|
auto& vm = this->vm();
|
||||||
constructor = heap().allocate<ConstructorType>(*this, *this);
|
constructor = heap().allocate<ConstructorType>(*this, *this);
|
||||||
constructor->define_direct_property(vm.names.name, js_string(heap(), property_key.as_string()), Attribute::Configurable);
|
constructor->define_direct_property(vm.names.name, js_string(heap(), property_key.as_string()), Attribute::Configurable);
|
||||||
if (prototype)
|
if (prototype)
|
||||||
prototype->define_direct_property(vm.names.constructor, constructor, Attribute::Writable | Attribute::Configurable);
|
prototype->define_direct_property(vm.names.constructor, constructor, attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename ConstructorType>
|
template<typename ConstructorType>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue