Properly implement static class fields. (#4221)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
@@ -792,6 +792,27 @@ parser_set_continues_to_current_position (parser_context_t *context_p, /**< cont
|
||||
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
|
||||
/**
|
||||
* Return the size of internal record corresponding to a class field
|
||||
*
|
||||
* @return internal record size
|
||||
*/
|
||||
static size_t
|
||||
parser_get_class_field_info_size (uint8_t class_field_type) /**< class field type */
|
||||
{
|
||||
if (class_field_type & PARSER_CLASS_FIELD_INITIALIZED)
|
||||
{
|
||||
return sizeof (scanner_range_t) + 1;
|
||||
}
|
||||
|
||||
if (class_field_type & PARSER_CLASS_FIELD_NORMAL)
|
||||
{
|
||||
return sizeof (scanner_location_t) + 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
} /* parser_get_class_field_info_size */
|
||||
|
||||
/**
|
||||
* Reverse the field list of a class
|
||||
*/
|
||||
@@ -802,60 +823,87 @@ parser_reverse_class_fields (parser_context_t *context_p, /**< context */
|
||||
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;
|
||||
bool has_fields = false;
|
||||
parser_stack_iterator_t iterator;
|
||||
|
||||
JERRY_ASSERT (!(context_p->stack_top_uint8 & PARSER_CLASS_FIELD_END));
|
||||
|
||||
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);
|
||||
size_t info_size = parser_get_class_field_info_size (class_field_type);
|
||||
|
||||
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);
|
||||
}
|
||||
parser_stack_iterator_read (&iterator, current_p, info_size);
|
||||
parser_stack_iterator_skip (&iterator, info_size);
|
||||
current_p += info_size;
|
||||
|
||||
*current_p++ = class_field_type;
|
||||
if (!(class_field_type & PARSER_CLASS_FIELD_STATIC))
|
||||
{
|
||||
has_fields = true;
|
||||
context_p->stack_top_uint8 = 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
|
||||
bool has_static_fields = false;
|
||||
|
||||
if (has_fields)
|
||||
{
|
||||
uint8_t class_field_type = 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);
|
||||
size_t info_size = parser_get_class_field_info_size (class_field_type);
|
||||
|
||||
if (!(class_field_type & PARSER_CLASS_FIELD_STATIC))
|
||||
{
|
||||
current_p -= info_size;
|
||||
parser_stack_iterator_write (&iterator, current_p, info_size);
|
||||
parser_stack_iterator_skip (&iterator, info_size);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!has_static_fields)
|
||||
{
|
||||
has_static_fields = true;
|
||||
current_p[-1] |= PARSER_CLASS_FIELD_END;
|
||||
}
|
||||
current_p -= info_size;
|
||||
}
|
||||
while (current_p > data_p);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* All class fields are static. */
|
||||
has_static_fields = true;
|
||||
JERRY_ASSERT (data_end_p[-1] & PARSER_CLASS_FIELD_STATIC);
|
||||
context_p->stack_top_uint8 = data_end_p[-1];
|
||||
}
|
||||
|
||||
if (has_static_fields)
|
||||
{
|
||||
current_p = data_end_p;
|
||||
|
||||
do
|
||||
{
|
||||
uint8_t class_field_type = current_p[-1];
|
||||
|
||||
size_t info_size = parser_get_class_field_info_size (class_field_type);
|
||||
current_p -= info_size;
|
||||
|
||||
if (class_field_type & PARSER_CLASS_FIELD_STATIC)
|
||||
{
|
||||
parser_stack_iterator_write (&iterator, current_p, info_size);
|
||||
parser_stack_iterator_skip (&iterator, info_size);
|
||||
}
|
||||
}
|
||||
while (current_p > data_p);
|
||||
}
|
||||
while (current_p > data_p);
|
||||
|
||||
parser_free (data_p, fields_size);
|
||||
} /* parser_reverse_class_fields */
|
||||
@@ -1260,6 +1308,10 @@ parser_error_to_string (parser_error_t error) /**< error code */
|
||||
{
|
||||
return "Super is not allowed to be used here.";
|
||||
}
|
||||
case PARSER_ERR_TOO_MANY_CLASS_FIELDS:
|
||||
{
|
||||
return "Too many computed class fields are declared.";
|
||||
}
|
||||
case PARSER_ERR_ARGUMENTS_IN_CLASS_FIELD:
|
||||
{
|
||||
return "In class field declarations 'arguments' is not allowed.";
|
||||
|
||||
Reference in New Issue
Block a user