mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 03:08:13 +00:00
LibJS: Add support for public fields in classes
This commit is contained in:
parent
3b6a8d1d53
commit
def8b44c40
9 changed files with 265 additions and 11 deletions
|
@ -457,6 +457,16 @@ static void append_bound_and_passed_arguments(MarkedValueList& arguments, Vector
|
|||
}
|
||||
}
|
||||
|
||||
// 7.3.32 InitializeInstanceElements ( O, constructor ), https://tc39.es/ecma262/#sec-initializeinstanceelements
|
||||
void VM::initialize_instance_elements(Object& object, FunctionObject& constructor)
|
||||
{
|
||||
for (auto& field : constructor.fields()) {
|
||||
field.define_field(*this, object);
|
||||
if (exception())
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
Value VM::construct(FunctionObject& function, FunctionObject& new_target, Optional<MarkedValueList> arguments)
|
||||
{
|
||||
auto& global_object = function.global_object();
|
||||
|
@ -494,6 +504,14 @@ Value VM::construct(FunctionObject& function, FunctionObject& new_target, Option
|
|||
|
||||
// If we are a Derived constructor, |this| has not been constructed before super is called.
|
||||
callee_context.this_value = this_argument;
|
||||
|
||||
if (function.constructor_kind() == FunctionObject::ConstructorKind::Base) {
|
||||
VERIFY(this_argument.is_object());
|
||||
initialize_instance_elements(this_argument.as_object(), function);
|
||||
if (exception())
|
||||
return {};
|
||||
}
|
||||
|
||||
auto result = function.construct(new_target);
|
||||
|
||||
pop_execution_context();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue