1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 07:17:35 +00:00

LibJS: Move initialize_instance_elements() from VM to Object

This makes more sense as an Object method rather than living within the
VM class for no good reason. Most of the other 7.3.xx AOs already work
the same way.
Also add spec comments while we're here.
This commit is contained in:
Linus Groh 2022-12-07 00:22:23 +00:00
parent cdeaced54e
commit daec065fde
7 changed files with 25 additions and 16 deletions

View file

@ -606,6 +606,27 @@ ThrowCompletionOr<void> Object::define_field(ClassFieldDefinition const& field)
return {};
}
// 7.3.33 InitializeInstanceElements ( O, constructor ), https://tc39.es/ecma262/#sec-initializeinstanceelements
ThrowCompletionOr<void> Object::initialize_instance_elements(ECMAScriptFunctionObject& constructor)
{
// 1. Let methods be the value of constructor.[[PrivateMethods]].
// 2. For each PrivateElement method of methods, do
for (auto const& method : constructor.private_methods()) {
// a. Perform ? PrivateMethodOrAccessorAdd(O, method).
TRY(private_method_or_accessor_add(method));
}
// 3. Let fields be the value of constructor.[[Fields]].
// 4. For each element fieldRecord of fields, do
for (auto const& field : constructor.fields()) {
// a. Perform ? DefineField(O, fieldRecord).
TRY(define_field(field));
}
// 5. Return unused.
return {};
}
// 10.1 Ordinary Object Internal Methods and Internal Slots, https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots
// 10.1.1 [[GetPrototypeOf]] ( ), https://tc39.es/ecma262/#sec-ordinary-object-internal-methods-and-internal-slots-getprototypeof