mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-27 11:48:32 +00:00
LibJS: Move native objects towards two-pass construction
To make sure that everything is set up correctly in objects before we start adding properties to them, we split cell allocation into 3 steps: 1. Allocate a cell of appropriate size from the Heap 2. Call the C++ constructor on the cell 3. Call initialize() on the constructed object The job of initialize() is to define all the initial properties. Doing it in a second pass guarantees that the Object has a valid Shape and can find its own GlobalObject.
This commit is contained in:
@@ -36,10 +36,20 @@
|
||||
|
||||
namespace JS {
|
||||
|
||||
ArrayConstructor::ArrayConstructor()
|
||||
: NativeFunction("Array", *interpreter().global_object().function_prototype())
|
||||
ArrayConstructor::ArrayConstructor(GlobalObject& global_object)
|
||||
: NativeFunction("Array", *global_object.function_prototype())
|
||||
{
|
||||
define_property("prototype", interpreter().global_object().array_prototype(), 0);
|
||||
}
|
||||
|
||||
ArrayConstructor::~ArrayConstructor()
|
||||
{
|
||||
}
|
||||
|
||||
void ArrayConstructor::initialize(Interpreter& interpreter, GlobalObject& global_object)
|
||||
{
|
||||
NativeFunction::initialize(interpreter, global_object);
|
||||
|
||||
define_property("prototype", global_object.array_prototype(), 0);
|
||||
define_property("length", Value(1), Attribute::Configurable);
|
||||
|
||||
u8 attr = Attribute::Writable | Attribute::Configurable;
|
||||
@@ -47,10 +57,6 @@ ArrayConstructor::ArrayConstructor()
|
||||
define_native_function("of", of, 0, attr);
|
||||
}
|
||||
|
||||
ArrayConstructor::~ArrayConstructor()
|
||||
{
|
||||
}
|
||||
|
||||
Value ArrayConstructor::call(Interpreter& interpreter)
|
||||
{
|
||||
if (interpreter.argument_count() <= 0)
|
||||
|
||||
Reference in New Issue
Block a user