1
0
Fork 0
mirror of https://github.com/LadybirdBrowser/ladybird.git synced 2025-06-11 18:20:43 +09:00

LibJS: Consistently make prototype the last argument in Object ctors

This is so that we can reliably allocate them in a template function,
e.g. in ordinary_create_from_constructor():

    global_object.heap().allocate<T>(
        global_object, forward<Args>(args)..., *prototype);

The majority of objects already take the prototype as the last argument,
so I updated the ones that didn't.
This commit is contained in:
Linus Groh 2021-06-19 23:21:08 +01:00 committed by Andreas Kling
parent df095afbcc
commit e5753443ae
Notes: sideshowbarker 2024-07-18 11:59:27 +09:00
18 changed files with 26 additions and 26 deletions

View file

@ -11,10 +11,10 @@ namespace JS {
ArrayIterator* ArrayIterator::create(GlobalObject& global_object, Value array, Object::PropertyKind iteration_kind)
{
return global_object.heap().allocate<ArrayIterator>(global_object, *global_object.array_iterator_prototype(), array, iteration_kind);
return global_object.heap().allocate<ArrayIterator>(global_object, array, iteration_kind, *global_object.array_iterator_prototype());
}
ArrayIterator::ArrayIterator(Object& prototype, Value array, Object::PropertyKind iteration_kind)
ArrayIterator::ArrayIterator(Value array, Object::PropertyKind iteration_kind, Object& prototype)
: Object(prototype)
, m_array(array)
, m_iteration_kind(iteration_kind)

View file

@ -16,7 +16,7 @@ class ArrayIterator final : public Object {
public:
static ArrayIterator* create(GlobalObject&, Value array, Object::PropertyKind iteration_kind);
explicit ArrayIterator(Object& prototype, Value array, Object::PropertyKind iteration_kind);
explicit ArrayIterator(Value array, Object::PropertyKind iteration_kind, Object& prototype);
virtual ~ArrayIterator() override;
Value array() const { return m_array; }

View file

@ -10,7 +10,7 @@
namespace JS {
BoundFunction::BoundFunction(GlobalObject& global_object, Function& target_function, Value bound_this, Vector<Value> arguments, i32 length, Object* constructor_prototype)
: Function::Function(*global_object.function_prototype(), bound_this, move(arguments))
: Function::Function(bound_this, move(arguments), *global_object.function_prototype())
, m_target_function(&target_function)
, m_constructor_prototype(constructor_prototype)
, m_name(String::formatted("bound {}", target_function.name()))

View file

@ -10,10 +10,10 @@ namespace JS {
DataView* DataView::create(GlobalObject& global_object, ArrayBuffer* viewed_buffer, size_t byte_length, size_t byte_offset)
{
return global_object.heap().allocate<DataView>(global_object, *global_object.data_view_prototype(), viewed_buffer, byte_length, byte_offset);
return global_object.heap().allocate<DataView>(global_object, viewed_buffer, byte_length, byte_offset, *global_object.data_view_prototype());
}
DataView::DataView(Object& prototype, ArrayBuffer* viewed_buffer, size_t byte_length, size_t byte_offset)
DataView::DataView(ArrayBuffer* viewed_buffer, size_t byte_length, size_t byte_offset, Object& prototype)
: Object(prototype)
, m_viewed_array_buffer(viewed_buffer)
, m_byte_length(byte_length)

View file

@ -18,7 +18,7 @@ class DataView : public Object {
public:
static DataView* create(GlobalObject&, ArrayBuffer*, size_t byte_length, size_t byte_offset);
explicit DataView(Object& prototype, ArrayBuffer*, size_t byte_length, size_t byte_offset);
explicit DataView(ArrayBuffer*, size_t byte_length, size_t byte_offset, Object& prototype);
virtual ~DataView() override;
ArrayBuffer* viewed_array_buffer() const { return m_viewed_array_buffer; }

View file

@ -10,10 +10,10 @@ namespace JS {
FinalizationRegistry* FinalizationRegistry::create(GlobalObject& global_object, Function& cleanup_callback)
{
return global_object.heap().allocate<FinalizationRegistry>(global_object, *global_object.finalization_registry_prototype(), cleanup_callback);
return global_object.heap().allocate<FinalizationRegistry>(global_object, cleanup_callback, *global_object.finalization_registry_prototype());
}
FinalizationRegistry::FinalizationRegistry(Object& prototype, Function& cleanup_callback)
FinalizationRegistry::FinalizationRegistry(Function& cleanup_callback, Object& prototype)
: Object(prototype)
, WeakContainer(heap())
, m_cleanup_callback(&cleanup_callback)

View file

@ -23,7 +23,7 @@ class FinalizationRegistry final
public:
static FinalizationRegistry* create(GlobalObject&, Function&);
explicit FinalizationRegistry(Object& prototype, Function&);
explicit FinalizationRegistry(Function&, Object& prototype);
virtual ~FinalizationRegistry() override;
void add_finalization_record(Cell& target, Value held_value, Object* unregister_token);

View file

@ -12,11 +12,11 @@
namespace JS {
Function::Function(Object& prototype)
: Function(prototype, {}, {})
: Function({}, {}, prototype)
{
}
Function::Function(Object& prototype, Value bound_this, Vector<Value> bound_arguments)
Function::Function(Value bound_this, Vector<Value> bound_arguments, Object& prototype)
: Object(prototype)
, m_bound_this(bound_this)
, m_bound_arguments(move(bound_arguments))

View file

@ -46,7 +46,7 @@ protected:
virtual void visit_edges(Visitor&) override;
explicit Function(Object& prototype);
Function(Object& prototype, Value bound_this, Vector<Value> bound_arguments);
Function(Value bound_this, Vector<Value> bound_arguments, Object& prototype);
private:
virtual bool is_function() const override { return true; }

View file

@ -11,10 +11,10 @@ namespace JS {
MapIterator* MapIterator::create(GlobalObject& global_object, Map& map, Object::PropertyKind iteration_kind)
{
return global_object.heap().allocate<MapIterator>(global_object, *global_object.map_iterator_prototype(), map, iteration_kind);
return global_object.heap().allocate<MapIterator>(global_object, map, iteration_kind, *global_object.map_iterator_prototype());
}
MapIterator::MapIterator(Object& prototype, Map& map, Object::PropertyKind iteration_kind)
MapIterator::MapIterator(Map& map, Object::PropertyKind iteration_kind, Object& prototype)
: Object(prototype)
, m_map(map)
, m_iteration_kind(iteration_kind)

View file

@ -18,7 +18,7 @@ class MapIterator final : public Object {
public:
static MapIterator* create(GlobalObject&, Map& map, Object::PropertyKind iteration_kind);
explicit MapIterator(Object& prototype, Map& map, Object::PropertyKind iteration_kind);
explicit MapIterator(Map& map, Object::PropertyKind iteration_kind, Object& prototype);
virtual ~MapIterator() override;
Map& map() const { return m_map; }

View file

@ -50,7 +50,7 @@ ScriptFunction* ScriptFunction::create(GlobalObject& global_object, const FlyStr
}
ScriptFunction::ScriptFunction(GlobalObject& global_object, const FlyString& name, const Statement& body, Vector<FunctionNode::Parameter> parameters, i32 m_function_length, ScopeObject* parent_scope, Object& prototype, FunctionKind kind, bool is_strict, bool is_arrow_function)
: Function(prototype, is_arrow_function ? vm().this_value(global_object) : Value(), {})
: Function(is_arrow_function ? vm().this_value(global_object) : Value(), {}, prototype)
, m_name(name)
, m_body(body)
, m_parameters(move(parameters))

View file

@ -11,10 +11,10 @@ namespace JS {
SetIterator* SetIterator::create(GlobalObject& global_object, Set& set, Object::PropertyKind iteration_kind)
{
return global_object.heap().allocate<SetIterator>(global_object, *global_object.set_iterator_prototype(), set, iteration_kind);
return global_object.heap().allocate<SetIterator>(global_object, set, iteration_kind, *global_object.set_iterator_prototype());
}
SetIterator::SetIterator(Object& prototype, Set& set, Object::PropertyKind iteration_kind)
SetIterator::SetIterator(Set& set, Object::PropertyKind iteration_kind, Object& prototype)
: Object(prototype)
, m_set(set)
, m_iteration_kind(iteration_kind)

View file

@ -18,7 +18,7 @@ class SetIterator final : public Object {
public:
static SetIterator* create(GlobalObject&, Set& set, Object::PropertyKind iteration_kind);
explicit SetIterator(Object& prototype, Set& set, Object::PropertyKind iteration_kind);
explicit SetIterator(Set& set, Object::PropertyKind iteration_kind, Object& prototype);
virtual ~SetIterator() override;
Set& set() const { return m_set; }

View file

@ -12,10 +12,10 @@ namespace JS {
StringIterator* StringIterator::create(GlobalObject& global_object, String string)
{
return global_object.heap().allocate<StringIterator>(global_object, *global_object.string_iterator_prototype(), move(string));
return global_object.heap().allocate<StringIterator>(global_object, move(string), *global_object.string_iterator_prototype());
}
StringIterator::StringIterator(Object& prototype, String string)
StringIterator::StringIterator(String string, Object& prototype)
: Object(prototype)
, m_string(move(string))
, m_iterator(Utf8View(m_string).begin())

View file

@ -17,7 +17,7 @@ class StringIterator final : public Object {
public:
static StringIterator* create(GlobalObject&, String string);
explicit StringIterator(Object& prototype, String string);
explicit StringIterator(String string, Object& prototype);
virtual ~StringIterator() override;
Utf8CodePointIterator& iterator() { return m_iterator; }

View file

@ -10,10 +10,10 @@ namespace JS {
WeakRef* WeakRef::create(GlobalObject& global_object, Object* object)
{
return global_object.heap().allocate<WeakRef>(global_object, *global_object.weak_ref_prototype(), object);
return global_object.heap().allocate<WeakRef>(global_object, object, *global_object.weak_ref_prototype());
}
WeakRef::WeakRef(Object& prototype, Object* object)
WeakRef::WeakRef(Object* object, Object& prototype)
: Object(prototype)
, WeakContainer(heap())
, m_value(object)

View file

@ -20,7 +20,7 @@ class WeakRef final
public:
static WeakRef* create(GlobalObject&, Object*);
explicit WeakRef(Object& prototype, Object*);
explicit WeakRef(Object*, Object& prototype);
virtual ~WeakRef() override;
Object* value() const { return m_value; };