Initial implementation of class fields (#4191)

Missing features:
 - this binding in static fields are not supported
 - static field evaluation order is wrong
 - function names are not supported

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2020-09-17 15:22:55 +02:00
committed by GitHub
parent 7345c83af7
commit d9653823ca
30 changed files with 1666 additions and 581 deletions
+78 -2
View File
@@ -790,6 +790,78 @@ parser_set_continues_to_current_position (parser_context_t *context_p, /**< cont
}
} /* parser_set_continues_to_current_position */
#if ENABLED (JERRY_ESNEXT)
/**
* Reverse the field list of a class
*/
void
parser_reverse_class_fields (parser_context_t *context_p, /**< context */
size_t fields_size) /**< size of consumed memory */
{
uint8_t *data_p = (uint8_t *) parser_malloc (context_p, fields_size);
uint8_t *data_end_p = data_p + fields_size;
uint8_t *current_p = data_p;
parser_stack_iterator_t iterator;
parser_stack_iterator_init (context_p, &iterator);
do
{
uint8_t class_field_type = parser_stack_iterator_read_uint8 (&iterator);
parser_stack_iterator_skip (&iterator, 1);
if (class_field_type & PARSER_CLASS_FIELD_INITIALIZED)
{
parser_stack_iterator_read (&iterator, current_p, sizeof (scanner_range_t));
parser_stack_iterator_skip (&iterator, sizeof (scanner_range_t));
current_p += sizeof (scanner_range_t);
}
else if (class_field_type & PARSER_CLASS_FIELD_NORMAL)
{
parser_stack_iterator_read (&iterator, current_p, sizeof (scanner_location_t));
parser_stack_iterator_skip (&iterator, sizeof (scanner_location_t));
current_p += sizeof (scanner_location_t);
}
*current_p++ = class_field_type;
}
while (current_p < data_end_p);
parser_stack_iterator_init (context_p, &iterator);
current_p = data_end_p;
context_p->stack_top_uint8 = current_p[-1];
do
{
uint8_t class_field_type = current_p[-1];
if (class_field_type & PARSER_CLASS_FIELD_INITIALIZED)
{
current_p -= sizeof (scanner_range_t) + 1;
parser_stack_iterator_write (&iterator, current_p, sizeof (scanner_range_t) + 1);
parser_stack_iterator_skip (&iterator, sizeof (scanner_range_t) + 1);
}
else if (class_field_type & PARSER_CLASS_FIELD_NORMAL)
{
current_p -= sizeof (scanner_location_t) + 1;
parser_stack_iterator_write (&iterator, current_p, sizeof (scanner_location_t) + 1);
parser_stack_iterator_skip (&iterator, sizeof (scanner_location_t) + 1);
}
else
{
current_p--;
parser_stack_iterator_write (&iterator, current_p, 1);
parser_stack_iterator_skip (&iterator, 1);
}
}
while (current_p > data_p);
parser_free (data_p, fields_size);
} /* parser_reverse_class_fields */
#endif /* ENABLED (JERRY_ESNEXT) */
#if ENABLED (JERRY_ERROR_MESSAGES)
/**
* Returns with the string representation of the error
@@ -1170,9 +1242,9 @@ parser_error_to_string (parser_error_t error) /**< error code */
{
return "Class constructor may not be an accessor.";
}
case PARSER_ERR_CLASS_CONSTRUCTOR_AS_GENERATOR:
case PARSER_ERR_INVALID_CLASS_CONSTRUCTOR:
{
return "Class constructor may not be a generator.";
return "Class constructor may not be a generator or async function.";
}
case PARSER_ERR_CLASS_STATIC_PROTOTYPE:
{
@@ -1182,6 +1254,10 @@ parser_error_to_string (parser_error_t error) /**< error code */
{
return "Super is not allowed to be used here.";
}
case PARSER_ERR_ARGUMENTS_IN_CLASS_FIELD:
{
return "In class field declarations 'arguments' is not allowed.";
}
case PARSER_ERR_RIGHT_BRACE_EXPECTED:
{
return "Expected '}' token.";