Correctly set flags of identifiers related to classes (#4233)

JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
Zoltan Herczeg
2020-09-30 12:45:53 +02:00
committed by GitHub
parent 0ffe1665bd
commit 4b2dbd5c21
13 changed files with 318 additions and 123 deletions
+1 -1
View File
@@ -27,7 +27,7 @@ JERRY_STATIC_ASSERT ((sizeof (cbc_uint16_arguments_t) % sizeof (jmem_cpointer_t)
*/
JERRY_STATIC_ASSERT (CBC_END == 238,
number_of_cbc_opcodes_changed);
JERRY_STATIC_ASSERT (CBC_EXT_END == 145,
JERRY_STATIC_ASSERT (CBC_EXT_END == 144,
number_of_cbc_ext_opcodes_changed);
#if ENABLED (JERRY_PARSER)
+1 -3
View File
@@ -663,8 +663,6 @@
\
/* Class related opcodes. */ \
CBC_OPCODE (CBC_EXT_PUSH_NAMED_CLASS_ENV, CBC_HAS_LITERAL_ARG, 1, \
VM_OC_PUSH_CLASS_ENVIRONMENT | VM_OC_GET_LITERAL) \
CBC_OPCODE (CBC_EXT_PUSH_ANONYMOUS_CLASS_ENV, CBC_NO_FLAG, 1, \
VM_OC_PUSH_CLASS_ENVIRONMENT) \
CBC_OPCODE (CBC_EXT_PUSH_IMPLICIT_CONSTRUCTOR, CBC_NO_FLAG, 1, \
VM_OC_PUSH_IMPLICIT_CTOR | VM_OC_PUT_STACK) \
@@ -673,7 +671,7 @@
CBC_OPCODE (CBC_EXT_INIT_CLASS, CBC_NO_FLAG, 0, \
VM_OC_INIT_CLASS | VM_OC_PUT_STACK) \
CBC_OPCODE (CBC_EXT_FINALIZE_NAMED_CLASS, CBC_HAS_LITERAL_ARG, -2, \
VM_OC_FINALIZE_CLASS | VM_OC_GET_LITERAL) \
VM_OC_FINALIZE_CLASS) \
CBC_OPCODE (CBC_EXT_FINALIZE_ANONYMOUS_CLASS, CBC_NO_FLAG, -2, \
VM_OC_FINALIZE_CLASS) \
CBC_OPCODE (CBC_EXT_SET_FIELD_INIT, CBC_HAS_LITERAL_ARG, 0, \
+19 -4
View File
@@ -945,7 +945,8 @@ parser_parse_class (parser_context_t *context_p, /**< context */
}
class_ident_index = context_p->lit_object.index;
lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_STRING_LITERAL);
lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_NEW_IDENT_LITERAL);
context_p->lit_object.literal_p->status_flags |= LEXER_FLAG_USED;
class_name_index = context_p->lit_object.index;
#if ENABLED (JERRY_MODULE_SYSTEM)
@@ -962,7 +963,8 @@ parser_parse_class (parser_context_t *context_p, /**< context */
/* Class expression may contain an identifier. */
if (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL)
{
lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_STRING_LITERAL);
lexer_construct_literal_object (context_p, &context_p->token.lit_location, LEXER_NEW_IDENT_LITERAL);
context_p->lit_object.literal_p->status_flags |= LEXER_FLAG_USED;
class_name_index = context_p->lit_object.index;
lexer_next_token (context_p);
}
@@ -970,11 +972,23 @@ parser_parse_class (parser_context_t *context_p, /**< context */
if (class_name_index != PARSER_INVALID_LITERAL_INDEX)
{
if (JERRY_UNLIKELY (context_p->scope_stack_top >= context_p->scope_stack_size))
{
JERRY_ASSERT (context_p->scope_stack_size == PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK);
parser_raise_error (context_p, PARSER_ERR_SCOPE_STACK_LIMIT_REACHED);
}
parser_scope_stack_t *scope_stack_p = context_p->scope_stack_p + context_p->scope_stack_top;
PARSER_PLUS_EQUAL_U16 (context_p->scope_stack_top, 1);
scope_stack_p->map_from = class_name_index;
scope_stack_p->map_to = 0;
parser_emit_cbc_ext_literal (context_p, CBC_EXT_PUSH_NAMED_CLASS_ENV, class_name_index);
}
else
{
parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_ANONYMOUS_CLASS_ENV);
parser_emit_cbc (context_p, CBC_PUSH_UNDEFINED);
}
bool is_strict = (context_p->status_flags & PARSER_IS_STRICT) != 0;
@@ -1005,7 +1019,8 @@ parser_parse_class (parser_context_t *context_p, /**< context */
if (class_name_index != PARSER_INVALID_LITERAL_INDEX)
{
parser_emit_cbc_ext_literal (context_p, CBC_EXT_FINALIZE_NAMED_CLASS, class_name_index);
parser_emit_cbc_ext_literal (context_p, CBC_EXT_SET_FUNCTION_NAME, class_name_index);
parser_emit_cbc_ext_literal (context_p, CBC_EXT_SET_CLASS_NAME, class_name_index);
PARSER_MINUS_EQUAL_U16 (context_p->scope_stack_top, 1);
}
else
{
+36 -11
View File
@@ -275,17 +275,17 @@ typedef struct scanner_binding_list_t
typedef enum
{
SCANNER_LITERAL_POOL_FUNCTION = (1 << 0), /**< literal pool represents a function */
SCANNER_LITERAL_POOL_BLOCK = (1 << 1), /**< literal pool represents a code block */
SCANNER_LITERAL_POOL_IS_STRICT = (1 << 2), /**< literal pool represents a strict mode code block */
SCANNER_LITERAL_POOL_CAN_EVAL = (1 << 3), /**< prepare for executing eval in this block */
SCANNER_LITERAL_POOL_NO_ARGUMENTS = (1 << 4), /**< arguments object must not be constructed */
#if ENABLED (JERRY_ESNEXT)
SCANNER_LITERAL_POOL_HAS_COMPLEX_ARGUMENT = (1 << 5), /**< function has complex (ES2015+) argument definition */
SCANNER_LITERAL_POOL_CLASS_NAME = (1 << 1), /**< literal pool which contains a class name */
SCANNER_LITERAL_POOL_CLASS_FIELD = (1 << 2), /**< literal pool is created for a class field initializer */
#endif /* ENABLED (JERRY_ESNEXT) */
SCANNER_LITERAL_POOL_IN_WITH = (1 << 6), /**< literal pool is in a with statement */
#if ENABLED (JERRY_MODULE_SYSTEM)
SCANNER_LITERAL_POOL_IN_EXPORT = (1 << 7), /**< the declared variables are exported by the module system */
#endif /* ENABLED (JERRY_MODULE_SYSTEM) */
SCANNER_LITERAL_POOL_IS_STRICT = (1 << 3), /**< literal pool represents a strict mode code block */
SCANNER_LITERAL_POOL_CAN_EVAL = (1 << 4), /**< prepare for executing eval in this block */
SCANNER_LITERAL_POOL_NO_ARGUMENTS = (1 << 5), /**< arguments object must not be constructed */
#if ENABLED (JERRY_ESNEXT)
SCANNER_LITERAL_POOL_HAS_COMPLEX_ARGUMENT = (1 << 6), /**< function has complex (ES2015+) argument definition */
#endif /* ENABLED (JERRY_ESNEXT) */
SCANNER_LITERAL_POOL_IN_WITH = (1 << 7), /**< literal pool is in a with statement */
#if ENABLED (JERRY_ESNEXT)
SCANNER_LITERAL_POOL_FUNCTION_STATEMENT = (1 << 8), /**< function statement */
SCANNER_LITERAL_POOL_ARROW = (1 << 9), /**< arrow function */
@@ -293,6 +293,9 @@ typedef enum
SCANNER_LITERAL_POOL_ASYNC = (1 << 11), /**< async function */
SCANNER_LITERAL_POOL_HAS_SUPER_REFERENCE = (1 << 12), /**< function body contains super reference */
#endif /* ENABLED (JERRY_ESNEXT) */
#if ENABLED (JERRY_MODULE_SYSTEM)
SCANNER_LITERAL_POOL_IN_EXPORT = (1 << 13), /**< the declared variables are exported by the module system */
#endif /* ENABLED (JERRY_MODULE_SYSTEM) */
} scanner_literal_pool_flags_t;
/**
@@ -319,6 +322,28 @@ typedef enum
#define SCANNER_FROM_COMPUTED_TO_LITERAL_POOL(mode) \
(((mode) - SCAN_STACK_COMPUTED_PROPERTY) << 10)
#if ENABLED (JERRY_ESNEXT)
/**
* Literal pool which may contains function argument identifiers
*/
#define SCANNER_LITERAL_POOL_MAY_HAVE_ARGUMENTS(status_flags) \
(!((status_flags) & (SCANNER_LITERAL_POOL_CLASS_NAME | SCANNER_LITERAL_POOL_CLASS_FIELD)))
/**
* The class name is the *default* class name
*/
#define SCANNER_LITERAL_POOL_DEFAULT_CLASS_NAME SCANNER_LITERAL_POOL_HAS_SUPER_REFERENCE
#else /* !ENABLED (JERRY_ESNEXT) */
/**
* Literal pool which may contains function argument identifiers
*/
#define SCANNER_LITERAL_POOL_MAY_HAVE_ARGUMENTS(status_flags) true
#endif /* ENABLED (JERRY_ESNEXT) */
/**
* Local literal pool.
*/
@@ -387,8 +412,8 @@ void scanner_detect_invalid_let (parser_context_t *context_p, lexer_lit_location
void scanner_detect_eval_call (parser_context_t *context_p, scanner_context_t *scanner_context_p);
#if ENABLED (JERRY_ESNEXT)
void scanner_push_class_declaration (parser_context_t *context_p, scanner_context_t *scanner_context_p,
uint8_t stack_mode);
lexer_lit_location_t *scanner_push_class_declaration (parser_context_t *context_p,
scanner_context_t *scanner_context_p, uint8_t stack_mode);
void scanner_push_class_field_initializer (parser_context_t *context_p, scanner_context_t *scanner_context_p);
void scanner_push_destructuring_pattern (parser_context_t *context_p, scanner_context_t *scanner_context_p,
uint8_t binding_type, bool is_nested);
+1 -3
View File
@@ -347,9 +347,7 @@ scanner_check_function_after_if (parser_context_t *context_p, /**< context */
if (JERRY_UNLIKELY (context_p->token.type == LEXER_KEYW_FUNCTION))
{
scanner_literal_pool_t *literal_pool_p;
literal_pool_p = scanner_push_literal_pool (context_p,
scanner_context_p,
SCANNER_LITERAL_POOL_BLOCK);
literal_pool_p = scanner_push_literal_pool (context_p, scanner_context_p, 0);
literal_pool_p->source_p = context_p->source_p;
parser_stack_push_uint8 (context_p, SCAN_STACK_PRIVATE_BLOCK);
+105 -45
View File
@@ -483,7 +483,7 @@ scanner_pop_literal_pool (parser_context_t *context_p, /**< context */
}
#endif /* ENABLED (JERRY_ESNEXT) */
if (literal_pool_p->source_p == NULL)
if (JERRY_UNLIKELY (literal_pool_p->source_p == NULL))
{
JERRY_ASSERT (literal_pool_p->status_flags & SCANNER_LITERAL_POOL_FUNCTION);
JERRY_ASSERT (literal_pool_p->literal_pool.data.first_p == NULL
@@ -528,6 +528,19 @@ scanner_pop_literal_pool (parser_context_t *context_p, /**< context */
size_t compressed_size = 1;
uint32_t no_declarations = literal_pool_p->no_declarations;
#if ENABLED (JERRY_ESNEXT)
if (JERRY_UNLIKELY (status_flags & SCANNER_LITERAL_POOL_CLASS_NAME))
{
literal_p = (lexer_lit_location_t *) parser_list_iterator_next (&literal_iterator);
if ((literal_p != NULL || (status_flags & SCANNER_LITERAL_POOL_DEFAULT_CLASS_NAME))
&& no_declarations < PARSER_MAXIMUM_DEPTH_OF_SCOPE_STACK)
{
no_declarations++;
}
}
#endif /* ENABLED (JERRY_ESNEXT) */
while ((literal_p = (lexer_lit_location_t *) parser_list_iterator_next (&literal_iterator)) != NULL)
{
uint8_t type = literal_p->type;
@@ -654,7 +667,13 @@ scanner_pop_literal_pool (parser_context_t *context_p, /**< context */
literal_p);
uint8_t extended_type = literal_location_p->type;
if ((status_flags & SCANNER_LITERAL_POOL_FUNCTION) || (type & SCANNER_LITERAL_NO_REG))
#if ENABLED (JERRY_ESNEXT)
const uint16_t no_reg_flags = (SCANNER_LITERAL_POOL_FUNCTION | SCANNER_LITERAL_POOL_CLASS_FIELD);
#else /* !ENABLED (JERRY_ESNEXT) */
const uint16_t no_reg_flags = SCANNER_LITERAL_POOL_FUNCTION;
#endif /* ENABLED (JERRY_ESNEXT) */
if ((status_flags & no_reg_flags) || (type & SCANNER_LITERAL_NO_REG))
{
extended_type |= SCANNER_LITERAL_NO_REG;
}
@@ -974,6 +993,8 @@ scanner_filter_arguments (parser_context_t *context_p, /**< context */
bool can_eval = (literal_pool_p->status_flags & SCANNER_LITERAL_POOL_CAN_EVAL) != 0;
bool has_arguments = (literal_pool_p->status_flags & SCANNER_LITERAL_POOL_NO_ARGUMENTS) == 0;
JERRY_ASSERT (SCANNER_LITERAL_POOL_MAY_HAVE_ARGUMENTS (literal_pool_p->status_flags));
if (can_eval && prev_literal_pool_p != NULL)
{
prev_literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_CAN_EVAL;
@@ -1126,53 +1147,64 @@ scanner_add_custom_literal (parser_context_t *context_p, /**< context */
scanner_literal_pool_t *literal_pool_p, /**< literal pool */
const lexer_lit_location_t *literal_location_p) /**< literal */
{
parser_list_iterator_t literal_iterator;
parser_list_iterator_init (&literal_pool_p->literal_pool, &literal_iterator);
lexer_lit_location_t *literal_p;
const uint8_t *char_p = literal_location_p->char_p;
prop_length_t length = literal_location_p->length;
if (JERRY_LIKELY (!literal_location_p->has_escape))
while (true)
{
while ((literal_p = (lexer_lit_location_t *) parser_list_iterator_next (&literal_iterator)) != NULL)
parser_list_iterator_t literal_iterator;
parser_list_iterator_init (&literal_pool_p->literal_pool, &literal_iterator);
lexer_lit_location_t *literal_p;
const uint8_t *char_p = literal_location_p->char_p;
prop_length_t length = literal_location_p->length;
if (JERRY_LIKELY (!literal_location_p->has_escape))
{
if (literal_p->length == length)
while ((literal_p = (lexer_lit_location_t *) parser_list_iterator_next (&literal_iterator)) != NULL)
{
if (JERRY_LIKELY (!literal_p->has_escape))
if (literal_p->length == length)
{
if (memcmp (literal_p->char_p, char_p, length) == 0)
if (JERRY_LIKELY (!literal_p->has_escape))
{
if (memcmp (literal_p->char_p, char_p, length) == 0)
{
return literal_p;
}
}
else if (lexer_compare_identifier_to_string (literal_p, char_p, length))
{
/* The non-escaped version is preferred. */
literal_p->char_p = char_p;
literal_p->has_escape = 0;
return literal_p;
}
}
else if (lexer_compare_identifier_to_string (literal_p, char_p, length))
}
}
else
{
while ((literal_p = (lexer_lit_location_t *) parser_list_iterator_next (&literal_iterator)) != NULL)
{
if (lexer_compare_identifiers (context_p, literal_p, literal_location_p))
{
/* The non-escaped version is preferred. */
literal_p->char_p = char_p;
literal_p->has_escape = 0;
return literal_p;
}
}
}
}
else
{
while ((literal_p = (lexer_lit_location_t *) parser_list_iterator_next (&literal_iterator)) != NULL)
#if ENABLED (JERRY_ESNEXT)
if (JERRY_UNLIKELY (literal_pool_p->status_flags & SCANNER_LITERAL_POOL_CLASS_NAME))
{
if (lexer_compare_identifiers (context_p, literal_p, literal_location_p))
{
return literal_p;
}
literal_pool_p = literal_pool_p->prev_p;
continue;
}
#endif /* ENABLED (JERRY_ESNEXT) */
literal_p = (lexer_lit_location_t *) parser_list_append (context_p, &literal_pool_p->literal_pool);
*literal_p = *literal_location_p;
literal_p->type = 0;
return literal_p;
}
literal_p = (lexer_lit_location_t *) parser_list_append (context_p, &literal_pool_p->literal_pool);
*literal_p = *literal_location_p;
literal_p->type = 0;
return literal_p;
} /* scanner_add_custom_literal */
/**
@@ -1232,6 +1264,8 @@ scanner_append_argument (parser_context_t *context_p, /**< context */
const uint8_t *char_p = literal_location_p->char_p;
prop_length_t length = literal_location_p->length;
JERRY_ASSERT (SCANNER_LITERAL_POOL_MAY_HAVE_ARGUMENTS (literal_pool_p->status_flags));
if (JERRY_LIKELY (!context_p->token.lit_location.has_escape))
{
while ((literal_p = (lexer_lit_location_t *) parser_list_iterator_next (&literal_iterator)) != NULL)
@@ -1383,9 +1417,9 @@ scanner_detect_invalid_var (parser_context_t *context_p, /**< context */
scanner_literal_pool_t *literal_pool_p = scanner_context_p->active_literal_pool_p;
if (literal_pool_p->status_flags & SCANNER_LITERAL_POOL_BLOCK
if (!(literal_pool_p->status_flags & SCANNER_LITERAL_POOL_FUNCTION)
&& (var_literal_p->type & (SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_FUNC_DECLARATION))
== (SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_FUNC_DECLARATION))
== (SCANNER_LITERAL_IS_FUNC | SCANNER_LITERAL_IS_FUNC_DECLARATION))
{
scanner_raise_redeclaration_error (context_p);
}
@@ -1405,10 +1439,10 @@ scanner_detect_invalid_var (parser_context_t *context_p, /**< context */
{
while ((literal_p = (lexer_lit_location_t *) parser_list_iterator_next (&literal_iterator)) != NULL)
{
if (literal_p->type & SCANNER_LITERAL_IS_LOCAL
if ((literal_p->type & SCANNER_LITERAL_IS_LOCAL)
&& !(literal_p->type & SCANNER_LITERAL_IS_ARG)
&& !((literal_p->type & SCANNER_LITERAL_IS_FUNC)
&& (literal_pool_p->status_flags & SCANNER_LITERAL_POOL_BLOCK) == 0)
&& (literal_pool_p->status_flags & SCANNER_LITERAL_POOL_FUNCTION))
&& (literal_p->type & SCANNER_LITERAL_IS_LOCAL) != SCANNER_LITERAL_IS_LOCAL
&& literal_p->length == length)
{
@@ -1432,10 +1466,10 @@ scanner_detect_invalid_var (parser_context_t *context_p, /**< context */
{
while ((literal_p = (lexer_lit_location_t *) parser_list_iterator_next (&literal_iterator)) != NULL)
{
if (literal_p->type & SCANNER_LITERAL_IS_LOCAL
if ((literal_p->type & SCANNER_LITERAL_IS_LOCAL)
&& !(literal_p->type & SCANNER_LITERAL_IS_ARG)
&& !((literal_p->type & SCANNER_LITERAL_IS_FUNC)
&& (literal_pool_p->status_flags & SCANNER_LITERAL_POOL_BLOCK) == 0)
&& (literal_pool_p->status_flags & SCANNER_LITERAL_POOL_FUNCTION))
&& (literal_p->type & SCANNER_LITERAL_IS_LOCAL) != SCANNER_LITERAL_IS_LOCAL
&& lexer_compare_identifiers (context_p, literal_p, var_literal_p))
{
@@ -1475,23 +1509,44 @@ scanner_detect_invalid_let (parser_context_t *context_p, /**< context */
/**
* Push the values required for class declaration parsing.
*
* @return literal reference created for class statements, NULL otherwise
*/
void
lexer_lit_location_t *
scanner_push_class_declaration (parser_context_t *context_p, /**< context */
scanner_context_t *scanner_context_p, /* scanner context */
uint8_t stack_mode) /**< stack mode */
{
JERRY_ASSERT (context_p->token.type == LEXER_KEYW_CLASS);
parser_stack_push_uint8 (context_p, stack_mode);
scanner_source_start_t source_start;
source_start.source_p = context_p->source_p;
const uint8_t *source_p = context_p->source_p;
lexer_lit_location_t *literal_p = NULL;
parser_stack_push_uint8 (context_p, stack_mode);
lexer_next_token (context_p);
bool class_has_name = (context_p->token.type == LEXER_LITERAL
&& context_p->token.lit_location.type == LEXER_IDENT_LITERAL);
if (stack_mode == SCAN_STACK_CLASS_STATEMENT && class_has_name)
{
literal_p = scanner_add_literal (context_p, scanner_context_p);
}
scanner_literal_pool_t *literal_pool_p = scanner_push_literal_pool (context_p, scanner_context_p, 0);
if (class_has_name)
{
scanner_add_literal (context_p, scanner_context_p);
}
literal_pool_p->source_p = source_p;
literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_CLASS_NAME;
parser_stack_push (context_p, &source_start, sizeof (scanner_source_start_t));
parser_stack_push_uint8 (context_p, SCAN_STACK_IMPLICIT_CLASS_CONSTRUCTOR);
scanner_context_p->mode = SCAN_MODE_CLASS_DECLARATION;
lexer_next_token (context_p);
return literal_p;
} /* scanner_push_class_declaration */
/**
@@ -1506,6 +1561,11 @@ scanner_push_class_field_initializer (parser_context_t *context_p, /**< context
parser_stack_push (context_p, &source_start, sizeof (scanner_source_start_t));
parser_stack_push_uint8 (context_p, SCAN_STACK_CLASS_FIELD_INITIALIZER);
scanner_literal_pool_t *literal_pool_p;
literal_pool_p = scanner_push_literal_pool (context_p, scanner_context_p, SCANNER_LITERAL_POOL_CLASS_FIELD);
literal_pool_p->source_p = context_p->source_p;
scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION;
} /* scanner_push_class_field_initializer */
+36 -38
View File
@@ -771,7 +771,7 @@ scanner_scan_primary_expression_end (parser_context_t *context_p, /**< context *
#if ENABLED (JERRY_ESNEXT)
scanner_literal_pool_t *literal_pool_p;
literal_pool_p = scanner_push_literal_pool (context_p, scanner_context_p, SCANNER_LITERAL_POOL_BLOCK);
literal_pool_p = scanner_push_literal_pool (context_p, scanner_context_p, 0);
literal_pool_p->source_p = context_p->source_p - 1;
#endif /* ENABLED (JERRY_ESNEXT) */
@@ -982,6 +982,8 @@ scanner_scan_primary_expression_end (parser_context_t *context_p, /**< context *
if (stack_top == SCAN_STACK_EXPLICIT_CLASS_CONSTRUCTOR
|| stack_top == SCAN_STACK_IMPLICIT_CLASS_CONSTRUCTOR)
{
JERRY_ASSERT (scanner_context_p->active_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_CLASS_NAME);
if (context_p->token.type == LEXER_LEFT_PAREN)
{
scanner_push_literal_pool (context_p, scanner_context_p, SCANNER_LITERAL_POOL_FUNCTION);
@@ -1108,12 +1110,11 @@ scanner_scan_primary_expression_end (parser_context_t *context_p, /**< context *
case SCAN_STACK_CLASS_FIELD_INITIALIZER:
{
scanner_source_start_t source_start;
const uint8_t *source_p = NULL;
parser_stack_pop_uint8 (context_p);
parser_stack_pop (context_p, &source_start, sizeof (scanner_source_start_t));
const uint8_t *source_p = NULL;
scanner_pop_literal_pool (context_p, scanner_context_p);
scanner_context_p->mode = SCAN_MODE_CLASS_BODY_NO_SCAN;
switch (type)
@@ -1228,9 +1229,7 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */
{
#if ENABLED (JERRY_ESNEXT)
scanner_literal_pool_t *literal_pool_p;
literal_pool_p = scanner_push_literal_pool (context_p,
scanner_context_p,
SCANNER_LITERAL_POOL_BLOCK);
literal_pool_p = scanner_push_literal_pool (context_p, scanner_context_p, 0);
literal_pool_p->source_p = context_p->source_p;
#endif /* ENABLED (JERRY_ESNEXT) */
@@ -1255,9 +1254,7 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */
#if ENABLED (JERRY_ESNEXT)
scanner_literal_pool_t *literal_pool_p;
literal_pool_p = scanner_push_literal_pool (context_p,
scanner_context_p,
SCANNER_LITERAL_POOL_BLOCK);
literal_pool_p = scanner_push_literal_pool (context_p, scanner_context_p, 0);
literal_pool_p->source_p = context_p->source_p;
#endif /* ENABLED (JERRY_ESNEXT) */
@@ -1407,7 +1404,7 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */
case LEXER_KEYW_CONST:
{
scanner_literal_pool_t *literal_pool_p;
literal_pool_p = scanner_push_literal_pool (context_p, scanner_context_p, SCANNER_LITERAL_POOL_BLOCK);
literal_pool_p = scanner_push_literal_pool (context_p, scanner_context_p, 0);
literal_pool_p->source_p = source_p;
if (scanner_context_p->mode == SCAN_MODE_PRIMARY_EXPRESSION)
@@ -1563,7 +1560,7 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */
scanner_literal_pool_t *literal_pool_p = scanner_context_p->active_literal_pool_p;
if (literal_pool_p->status_flags & SCANNER_LITERAL_POOL_BLOCK
if (!(literal_pool_p->status_flags & SCANNER_LITERAL_POOL_FUNCTION)
&& (literal_p->type & (SCANNER_LITERAL_IS_VAR)))
{
scanner_raise_redeclaration_error (context_p);
@@ -1587,18 +1584,22 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */
#if ENABLED (JERRY_ESNEXT)
case LEXER_KEYW_CLASS:
{
scanner_push_class_declaration (context_p, scanner_context_p, SCAN_STACK_CLASS_STATEMENT);
lexer_lit_location_t *literal_p;
literal_p = scanner_push_class_declaration (context_p, scanner_context_p, SCAN_STACK_CLASS_STATEMENT);
if (context_p->token.type != LEXER_LITERAL || context_p->token.lit_location.type != LEXER_IDENT_LITERAL)
if (literal_p == NULL)
{
scanner_raise_error (context_p);
}
lexer_lit_location_t *literal_p = scanner_add_literal (context_p, scanner_context_p);
scanner_detect_invalid_let (context_p, literal_p);
literal_p->type |= SCANNER_LITERAL_IS_LET;
if (literal_p->type & SCANNER_LITERAL_IS_USED)
{
literal_p->type |= SCANNER_LITERAL_EARLY_CREATE;
}
#if ENABLED (JERRY_MODULE_SYSTEM)
if (scanner_context_p->active_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_IN_EXPORT)
{
@@ -1810,25 +1811,31 @@ scanner_scan_statement (parser_context_t *context_p, /**< context */
scanner_context_p->mode = SCAN_MODE_FUNCTION_ARGUMENTS;
return SCAN_KEEP_TOKEN;
}
if (context_p->token.type == LEXER_KEYW_CLASS)
{
scanner_push_class_declaration (context_p, scanner_context_p, SCAN_STACK_CLASS_STATEMENT);
lexer_lit_location_t *literal_p;
literal_p = scanner_push_class_declaration (context_p, scanner_context_p, SCAN_STACK_CLASS_STATEMENT);
if (context_p->token.type == LEXER_LITERAL && context_p->token.lit_location.type == LEXER_IDENT_LITERAL)
if (literal_p != NULL)
{
lexer_lit_location_t *literal_p = scanner_add_literal (context_p, scanner_context_p);
scanner_detect_invalid_let (context_p, literal_p);
if (literal_p->type & SCANNER_LITERAL_IS_USED)
{
literal_p->type |= SCANNER_LITERAL_EARLY_CREATE;
}
literal_p->type |= SCANNER_LITERAL_IS_LET | SCANNER_LITERAL_NO_REG;
return SCAN_NEXT_TOKEN;
}
lexer_lit_location_t *literal_p;
literal_p = scanner_add_custom_literal (context_p,
scanner_context_p->active_literal_pool_p,
&lexer_default_literal);
literal_p->type |= SCANNER_LITERAL_IS_LET | SCANNER_LITERAL_NO_REG;
scanner_context_p->active_literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_DEFAULT_CLASS_NAME;
return SCAN_KEEP_TOKEN;
}
@@ -2299,9 +2306,7 @@ scanner_scan_statement_end (parser_context_t *context_p, /**< context */
#if ENABLED (JERRY_ESNEXT)
scanner_literal_pool_t *literal_pool_p;
literal_pool_p = scanner_push_literal_pool (context_p,
scanner_context_p,
SCANNER_LITERAL_POOL_BLOCK);
literal_pool_p = scanner_push_literal_pool (context_p, scanner_context_p, 0);
literal_pool_p->source_p = context_p->source_p;
#endif /* ENABLED (JERRY_ESNEXT) */
@@ -2325,7 +2330,7 @@ scanner_scan_statement_end (parser_context_t *context_p, /**< context */
lexer_next_token (context_p);
scanner_literal_pool_t *literal_pool_p;
literal_pool_p = scanner_push_literal_pool (context_p, scanner_context_p, SCANNER_LITERAL_POOL_BLOCK);
literal_pool_p = scanner_push_literal_pool (context_p, scanner_context_p, 0);
literal_pool_p->source_p = context_p->source_p;
parser_stack_push_uint8 (context_p, SCAN_STACK_CATCH_STATEMENT);
@@ -2556,20 +2561,15 @@ scanner_scan_all (parser_context_t *context_p, /**< context */
{
JERRY_ASSERT (stack_top == SCAN_STACK_IMPLICIT_CLASS_CONSTRUCTOR
|| stack_top == SCAN_STACK_EXPLICIT_CLASS_CONSTRUCTOR);
JERRY_ASSERT (scanner_context.active_literal_pool_p->status_flags & SCANNER_LITERAL_POOL_CLASS_NAME);
if (context_p->token.type == LEXER_RIGHT_BRACE)
{
scanner_source_start_t source_start;
parser_stack_pop_uint8 (context_p);
if (stack_top == SCAN_STACK_IMPLICIT_CLASS_CONSTRUCTOR)
{
parser_stack_pop (context_p, &source_start, sizeof (scanner_source_start_t));
}
stack_top = context_p->stack_top_uint8;
scanner_pop_literal_pool (context_p, &scanner_context);
JERRY_ASSERT (stack_top == SCAN_STACK_CLASS_STATEMENT || stack_top == SCAN_STACK_CLASS_EXPRESSION);
if (stack_top == SCAN_STACK_CLASS_STATEMENT)
@@ -2592,13 +2592,11 @@ scanner_scan_all (parser_context_t *context_p, /**< context */
{
if (stack_top == SCAN_STACK_IMPLICIT_CLASS_CONSTRUCTOR)
{
scanner_source_start_t source_start;
parser_stack_pop_uint8 (context_p);
parser_stack_pop (context_p, &source_start, sizeof (scanner_source_start_t));
const uint8_t *class_source_p = scanner_context.active_literal_pool_p->source_p;
scanner_info_t *info_p = scanner_insert_info (context_p, class_source_p, sizeof (scanner_info_t));
scanner_info_t *info_p = scanner_insert_info (context_p, source_start.source_p, sizeof (scanner_info_t));
info_p->type = SCANNER_TYPE_CLASS_CONSTRUCTOR;
parser_stack_push_uint8 (context_p, SCAN_STACK_EXPLICIT_CLASS_CONSTRUCTOR);
parser_stack_change_last_uint8 (context_p, SCAN_STACK_EXPLICIT_CLASS_CONSTRUCTOR);
}
}
else if (lexer_token_is_identifier (context_p, "static", 6))