Support super property reference in object methods/accessors (#3940)
JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik frobert@inf.u-szeged.hu
This commit is contained in:
@@ -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 == 128,
|
||||
JERRY_STATIC_ASSERT (CBC_EXT_END == 132,
|
||||
number_of_cbc_ext_opcodes_changed);
|
||||
|
||||
#if ENABLED (JERRY_PARSER)
|
||||
|
||||
@@ -676,6 +676,14 @@
|
||||
VM_OC_SUPER_REFERENCE | VM_OC_GET_STACK) \
|
||||
CBC_OPCODE (CBC_EXT_SUPER_PROP_LITERAL_ASSIGNMENT_REFERENCE, CBC_HAS_LITERAL_ARG, 2, \
|
||||
VM_OC_SUPER_REFERENCE | VM_OC_GET_LITERAL) \
|
||||
CBC_OPCODE (CBC_EXT_OBJECT_LITERAL_SET_HOME_OBJECT, CBC_NO_FLAG, 0, \
|
||||
VM_OC_SET_HOME_OBJECT) \
|
||||
CBC_OPCODE (CBC_EXT_OBJECT_LITERAL_SET_HOME_OBJECT_COMPUTED, CBC_NO_FLAG, 0, \
|
||||
VM_OC_SET_HOME_OBJECT) \
|
||||
CBC_OPCODE (CBC_EXT_PUSH_OBJECT_SUPER_ENVIRONMENT, CBC_NO_FLAG, 1, \
|
||||
VM_OC_OBJECT_LITERAL_HOME_ENV) \
|
||||
CBC_OPCODE (CBC_EXT_POP_OBJECT_SUPER_ENVIRONMENT, CBC_NO_FLAG, -1, \
|
||||
VM_OC_OBJECT_LITERAL_HOME_ENV) \
|
||||
CBC_OPCODE (CBC_EXT_RESOLVE_LEXICAL_THIS, CBC_NO_FLAG, 1, \
|
||||
VM_OC_RESOLVE_LEXICAL_THIS | VM_OC_PUT_STACK) \
|
||||
CBC_OPCODE (CBC_EXT_LOCAL_EVAL, CBC_HAS_BYTE_ARG, 0, \
|
||||
|
||||
@@ -869,7 +869,8 @@ parser_parse_object_method (parser_context_t *context_p) /**< context */
|
||||
{
|
||||
context_p->source_p--;
|
||||
context_p->column--;
|
||||
uint16_t function_literal_index = lexer_construct_function_object (context_p, PARSER_FUNCTION_CLOSURE);
|
||||
uint16_t function_literal_index = lexer_construct_function_object (context_p, (PARSER_FUNCTION_CLOSURE
|
||||
| PARSER_ALLOW_SUPER));
|
||||
|
||||
parser_emit_cbc_literal (context_p,
|
||||
CBC_PUSH_LITERAL,
|
||||
@@ -932,6 +933,15 @@ parser_parse_object_literal (parser_context_t *context_p) /**< context */
|
||||
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
bool proto_seen = false;
|
||||
bool has_super_env = false;
|
||||
|
||||
if (context_p->next_scanner_info_p->source_p == context_p->source_p)
|
||||
{
|
||||
JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_OBJECT_LITERAL_WITH_SUPER);
|
||||
scanner_release_next (context_p, sizeof (scanner_info_t));
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_PUSH_OBJECT_SUPER_ENVIRONMENT);
|
||||
has_super_env = true;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
while (true)
|
||||
@@ -971,6 +981,10 @@ parser_parse_object_literal (parser_context_t *context_p) /**< context */
|
||||
#endif /* !ENABLED (JERRY_ESNEXT) */
|
||||
}
|
||||
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
status_flags |= PARSER_ALLOW_SUPER;
|
||||
#endif /* !ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
lexer_expect_object_literal_id (context_p, LEXER_OBJ_IDENT_ONLY_IDENTIFIERS);
|
||||
|
||||
/* This assignment is a nop for computed getters/setters. */
|
||||
@@ -1008,16 +1022,32 @@ parser_parse_object_literal (parser_context_t *context_p) /**< context */
|
||||
{
|
||||
parser_emit_cbc_ext (context_p, is_getter ? CBC_EXT_SET_COMPUTED_GETTER_NAME
|
||||
: CBC_EXT_SET_COMPUTED_SETTER_NAME);
|
||||
|
||||
if (has_super_env)
|
||||
{
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_OBJECT_LITERAL_SET_HOME_OBJECT_COMPUTED);
|
||||
}
|
||||
parser_emit_cbc_ext (context_p, opcode);
|
||||
lexer_next_token (context_p);
|
||||
break;
|
||||
}
|
||||
|
||||
parser_set_function_name (context_p, function_literal_index, literal_index, status_flags);
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (opcode);
|
||||
context_p->last_cbc.value = function_literal_index;
|
||||
if (has_super_env)
|
||||
{
|
||||
context_p->last_cbc_opcode = CBC_PUSH_TWO_LITERALS;
|
||||
context_p->last_cbc.value = function_literal_index;
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_OBJECT_LITERAL_SET_HOME_OBJECT_COMPUTED);
|
||||
parser_emit_cbc_ext (context_p, is_getter ? CBC_EXT_SET_COMPUTED_GETTER
|
||||
: CBC_EXT_SET_COMPUTED_SETTER);
|
||||
}
|
||||
else
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
{
|
||||
context_p->last_cbc_opcode = PARSER_TO_EXT_OPCODE (opcode);
|
||||
context_p->last_cbc.value = function_literal_index;
|
||||
}
|
||||
|
||||
lexer_next_token (context_p);
|
||||
break;
|
||||
@@ -1035,6 +1065,10 @@ parser_parse_object_literal (parser_context_t *context_p) /**< context */
|
||||
if (parser_check_anonymous_function_declaration (context_p) < PARSER_NAMED_FUNCTION)
|
||||
{
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_SET_COMPUTED_FUNCTION_NAME);
|
||||
if (has_super_env)
|
||||
{
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_OBJECT_LITERAL_SET_HOME_OBJECT_COMPUTED);
|
||||
}
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_SET_COMPUTED_PROPERTY);
|
||||
}
|
||||
else
|
||||
@@ -1091,6 +1125,11 @@ parser_parse_object_literal (parser_context_t *context_p) /**< context */
|
||||
status_flags |= PARSER_IS_GENERATOR_FUNCTION | PARSER_DISALLOW_AWAIT_YIELD;
|
||||
}
|
||||
|
||||
if (has_super_env)
|
||||
{
|
||||
status_flags |= PARSER_ALLOW_SUPER;
|
||||
}
|
||||
|
||||
lexer_expect_object_literal_id (context_p, LEXER_OBJ_IDENT_ONLY_IDENTIFIERS);
|
||||
|
||||
uint16_t opcode = CBC_SET_LITERAL_PROPERTY;
|
||||
@@ -1114,6 +1153,10 @@ parser_parse_object_literal (parser_context_t *context_p) /**< context */
|
||||
if (is_computed)
|
||||
{
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_SET_COMPUTED_FUNCTION_NAME);
|
||||
if (has_super_env)
|
||||
{
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_OBJECT_LITERAL_SET_HOME_OBJECT_COMPUTED);
|
||||
}
|
||||
parser_emit_cbc_ext (context_p, opcode);
|
||||
lexer_next_token (context_p);
|
||||
break;
|
||||
@@ -1121,8 +1164,16 @@ parser_parse_object_literal (parser_context_t *context_p) /**< context */
|
||||
|
||||
parser_set_function_name (context_p, function_literal_index, literal_index, status_flags);
|
||||
|
||||
context_p->last_cbc_opcode = opcode;
|
||||
context_p->last_cbc.value = literal_index;
|
||||
if (has_super_env)
|
||||
{
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_OBJECT_LITERAL_SET_HOME_OBJECT);
|
||||
parser_emit_cbc_literal (context_p, CBC_SET_PROPERTY, literal_index);
|
||||
}
|
||||
else
|
||||
{
|
||||
context_p->last_cbc_opcode = opcode;
|
||||
context_p->last_cbc.value = literal_index;
|
||||
}
|
||||
|
||||
lexer_next_token (context_p);
|
||||
break;
|
||||
@@ -1167,6 +1218,14 @@ parser_parse_object_literal (parser_context_t *context_p) /**< context */
|
||||
|
||||
JERRY_ASSERT (context_p->last_cbc_opcode == CBC_PUSH_LITERAL);
|
||||
parser_set_function_name (context_p, context_p->last_cbc.literal_index, literal_index, 0);
|
||||
|
||||
if (has_super_env)
|
||||
{
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_OBJECT_LITERAL_SET_HOME_OBJECT);
|
||||
parser_emit_cbc_literal (context_p, CBC_SET_PROPERTY, literal_index);
|
||||
break;
|
||||
}
|
||||
|
||||
context_p->last_cbc_opcode = CBC_SET_LITERAL_PROPERTY;
|
||||
context_p->last_cbc.value = literal_index;
|
||||
break;
|
||||
@@ -1246,6 +1305,11 @@ parser_parse_object_literal (parser_context_t *context_p) /**< context */
|
||||
}
|
||||
|
||||
parser_stack_pop_uint8 (context_p);
|
||||
#else /* ENABLED (JERRY_ESNEXT) */
|
||||
if (has_super_env)
|
||||
{
|
||||
parser_emit_cbc_ext (context_p, CBC_EXT_POP_OBJECT_SUPER_ENVIRONMENT);
|
||||
}
|
||||
#endif /* !ENABLED (JERRY_ESNEXT) */
|
||||
} /* parser_parse_object_literal */
|
||||
|
||||
@@ -1828,10 +1892,9 @@ parser_parse_unary_expression (parser_context_t *context_p, /**< context */
|
||||
case LEXER_LEFT_BRACE:
|
||||
{
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
if (context_p->next_scanner_info_p->source_p == context_p->source_p)
|
||||
if (context_p->next_scanner_info_p->source_p == context_p->source_p
|
||||
&& context_p->next_scanner_info_p->type == SCANNER_TYPE_INITIALIZER)
|
||||
{
|
||||
JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_INITIALIZER);
|
||||
|
||||
if (parser_is_assignment_expr (context_p))
|
||||
{
|
||||
parser_parse_object_initializer (context_p, PARSER_PATTERN_NO_OPTS);
|
||||
|
||||
@@ -641,6 +641,7 @@ void parser_stack_init (parser_context_t *context_p);
|
||||
void parser_stack_free (parser_context_t *context_p);
|
||||
void parser_stack_push_uint8 (parser_context_t *context_p, uint8_t uint8_value);
|
||||
void parser_stack_pop_uint8 (parser_context_t *context_p);
|
||||
void parser_stack_change_last_uint8 (parser_context_t *context_p, uint8_t new_value);
|
||||
void parser_stack_push_uint16 (parser_context_t *context_p, uint16_t uint16_value);
|
||||
uint16_t parser_stack_pop_uint16 (parser_context_t *context_p);
|
||||
void parser_stack_push (parser_context_t *context_p, const void *data_p, uint32_t length);
|
||||
|
||||
@@ -436,6 +436,22 @@ parser_stack_pop_uint8 (parser_context_t *context_p) /**< context */
|
||||
context_p->stack_top_uint8 = page_p->bytes[context_p->stack.last_position - 1];
|
||||
} /* parser_stack_pop_uint8 */
|
||||
|
||||
/**
|
||||
* Change last byte of the stack.
|
||||
*/
|
||||
void
|
||||
parser_stack_change_last_uint8 (parser_context_t *context_p, /**< context */
|
||||
uint8_t new_value) /**< new value */
|
||||
{
|
||||
parser_mem_page_t *page_p = context_p->stack.first_p;
|
||||
|
||||
JERRY_ASSERT (page_p != NULL
|
||||
&& context_p->stack_top_uint8 == page_p->bytes[context_p->stack.last_position - 1]);
|
||||
|
||||
page_p->bytes[context_p->stack.last_position - 1] = new_value;
|
||||
context_p->stack_top_uint8 = new_value;
|
||||
} /* parser_stack_change_last_uint8 */
|
||||
|
||||
/**
|
||||
* Pushes an uint16_t value onto the stack.
|
||||
*/
|
||||
|
||||
@@ -331,22 +331,6 @@ parser_stack_iterator_read_uint8 (parser_stack_iterator_t *iterator) /**< iterat
|
||||
return iterator->current_p->bytes[iterator->current_position - 1];
|
||||
} /* parser_stack_iterator_read_uint8 */
|
||||
|
||||
/**
|
||||
* Change last byte of the stack.
|
||||
*/
|
||||
static inline void
|
||||
parser_stack_change_last_uint8 (parser_context_t *context_p, /**< context */
|
||||
uint8_t new_value) /**< new value */
|
||||
{
|
||||
parser_mem_page_t *page_p = context_p->stack.first_p;
|
||||
|
||||
JERRY_ASSERT (page_p != NULL
|
||||
&& context_p->stack_top_uint8 == page_p->bytes[context_p->stack.last_position - 1]);
|
||||
|
||||
page_p->bytes[context_p->stack.last_position - 1] = new_value;
|
||||
context_p->stack_top_uint8 = new_value;
|
||||
} /* parser_stack_change_last_uint8 */
|
||||
|
||||
/**
|
||||
* Parse expression enclosed in parens.
|
||||
*/
|
||||
|
||||
@@ -115,6 +115,7 @@ typedef enum
|
||||
SCAN_STACK_CLASS_EXTENDS, /**< class extends expression */
|
||||
SCAN_STACK_FUNCTION_PARAMETERS, /**< function parameter initializer */
|
||||
SCAN_STACK_USE_ASYNC, /**< an "async" identifier is used */
|
||||
SCAN_STACK_OBJECT_LITERAL_WITH_SUPER, /**< object literal with inner super reference */
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
} scan_stack_modes_t;
|
||||
|
||||
@@ -287,6 +288,7 @@ typedef enum
|
||||
SCANNER_LITERAL_POOL_ARROW = (1 << 9), /**< arrow function */
|
||||
SCANNER_LITERAL_POOL_GENERATOR = (1 << 10), /**< generator function */
|
||||
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) */
|
||||
} scanner_literal_pool_flags_t;
|
||||
|
||||
|
||||
@@ -66,6 +66,8 @@ scanner_check_arrow_body (parser_context_t *context_p, /**< context */
|
||||
{
|
||||
lexer_next_token (context_p);
|
||||
|
||||
scanner_context_p->active_literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_ARROW;
|
||||
|
||||
if (context_p->token.type != LEXER_LEFT_BRACE)
|
||||
{
|
||||
scanner_context_p->mode = SCAN_MODE_PRIMARY_EXPRESSION;
|
||||
@@ -431,9 +433,12 @@ scanner_scan_bracket (parser_context_t *context_p, /**< context */
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
/* A function call cannot be an eval function. */
|
||||
arrow_source_p = NULL;
|
||||
const uint16_t flags = (uint16_t) (SCANNER_LITERAL_POOL_CAN_EVAL | SCANNER_LITERAL_POOL_HAS_SUPER_REFERENCE);
|
||||
#else /* !ENABLED (JERRY_ESNEXT) */
|
||||
const uint16_t flags = SCANNER_LITERAL_POOL_CAN_EVAL;
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
scanner_context_p->active_literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_CAN_EVAL;
|
||||
scanner_context_p->active_literal_pool_p->status_flags |= flags;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -475,6 +475,14 @@ scanner_pop_literal_pool (parser_context_t *context_p, /**< context */
|
||||
scanner_literal_pool_t *literal_pool_p = scanner_context_p->active_literal_pool_p;
|
||||
scanner_literal_pool_t *prev_literal_pool_p = literal_pool_p->prev_p;
|
||||
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
const uint32_t arrow_super_flags = (SCANNER_LITERAL_POOL_ARROW | SCANNER_LITERAL_POOL_HAS_SUPER_REFERENCE);
|
||||
if ((literal_pool_p->status_flags & arrow_super_flags) == arrow_super_flags)
|
||||
{
|
||||
prev_literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_HAS_SUPER_REFERENCE;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
if (literal_pool_p->source_p == NULL)
|
||||
{
|
||||
JERRY_ASSERT (literal_pool_p->status_flags & SCANNER_LITERAL_POOL_FUNCTION);
|
||||
@@ -1287,7 +1295,13 @@ scanner_detect_eval_call (parser_context_t *context_p, /**< context */
|
||||
if (context_p->token.keyword_type == LEXER_KEYW_EVAL
|
||||
&& lexer_check_next_character (context_p, LIT_CHAR_LEFT_PAREN))
|
||||
{
|
||||
scanner_context_p->active_literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_CAN_EVAL;
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
const uint16_t flags = (uint16_t) (SCANNER_LITERAL_POOL_CAN_EVAL | SCANNER_LITERAL_POOL_HAS_SUPER_REFERENCE);
|
||||
#else /* !ENABLED (JERRY_ESNEXT) */
|
||||
const uint16_t flags = SCANNER_LITERAL_POOL_CAN_EVAL;
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
scanner_context_p->active_literal_pool_p->status_flags |= flags;
|
||||
}
|
||||
} /* scanner_detect_eval_call */
|
||||
|
||||
@@ -1654,6 +1668,7 @@ scanner_cleanup (parser_context_t *context_p) /**< context */
|
||||
JERRY_ASSERT (scanner_info_p->type == SCANNER_TYPE_END_ARGUMENTS
|
||||
|| scanner_info_p->type == SCANNER_TYPE_LET_EXPRESSION
|
||||
|| scanner_info_p->type == SCANNER_TYPE_CLASS_CONSTRUCTOR
|
||||
|| scanner_info_p->type == SCANNER_TYPE_OBJECT_LITERAL_WITH_SUPER
|
||||
|| scanner_info_p->type == SCANNER_TYPE_ERR_REDECLARED
|
||||
|| scanner_info_p->type == SCANNER_TYPE_ERR_ASYNC_FUNCTION);
|
||||
#else /* !ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
@@ -193,7 +193,6 @@ scanner_scan_primary_expression (parser_context_t *context_p, /**< context */
|
||||
/* FALLTHRU */
|
||||
}
|
||||
case LEXER_KEYW_THIS:
|
||||
case LEXER_KEYW_SUPER:
|
||||
case LEXER_LIT_TRUE:
|
||||
case LEXER_LIT_FALSE:
|
||||
case LEXER_LIT_NULL:
|
||||
@@ -202,6 +201,12 @@ scanner_scan_primary_expression (parser_context_t *context_p, /**< context */
|
||||
break;
|
||||
}
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
case LEXER_KEYW_SUPER:
|
||||
{
|
||||
scanner_context_p->active_literal_pool_p->status_flags |= SCANNER_LITERAL_POOL_HAS_SUPER_REFERENCE;
|
||||
scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION;
|
||||
break;
|
||||
}
|
||||
case LEXER_KEYW_CLASS:
|
||||
{
|
||||
scanner_push_class_declaration (context_p, scanner_context_p, SCAN_STACK_CLASS_EXPRESSION);
|
||||
@@ -442,6 +447,7 @@ scanner_scan_primary_expression_end (parser_context_t *context_p, /**< context *
|
||||
|
||||
return SCAN_NEXT_TOKEN;
|
||||
}
|
||||
case SCAN_STACK_OBJECT_LITERAL_WITH_SUPER:
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
case SCAN_STACK_OBJECT_LITERAL:
|
||||
{
|
||||
@@ -555,6 +561,7 @@ scanner_scan_primary_expression_end (parser_context_t *context_p, /**< context *
|
||||
|
||||
JERRY_ASSERT (context_p->stack_top_uint8 == SCAN_STACK_ARRAY_LITERAL
|
||||
|| context_p->stack_top_uint8 == SCAN_STACK_OBJECT_LITERAL
|
||||
|| context_p->stack_top_uint8 == SCAN_STACK_OBJECT_LITERAL_WITH_SUPER
|
||||
|| context_p->stack_top_uint8 == SCAN_STACK_LET
|
||||
|| context_p->stack_top_uint8 == SCAN_STACK_CONST
|
||||
|| context_p->stack_top_uint8 == SCAN_STACK_FOR_LET_START
|
||||
@@ -586,6 +593,7 @@ scanner_scan_primary_expression_end (parser_context_t *context_p, /**< context *
|
||||
|
||||
JERRY_ASSERT (context_p->stack_top_uint8 == SCAN_STACK_ARRAY_LITERAL
|
||||
|| context_p->stack_top_uint8 == SCAN_STACK_OBJECT_LITERAL
|
||||
|| context_p->stack_top_uint8 == SCAN_STACK_OBJECT_LITERAL_WITH_SUPER
|
||||
|| context_p->stack_top_uint8 == SCAN_STACK_LET
|
||||
|| context_p->stack_top_uint8 == SCAN_STACK_CONST
|
||||
|| context_p->stack_top_uint8 == SCAN_STACK_FOR_LET_START
|
||||
@@ -593,8 +601,10 @@ scanner_scan_primary_expression_end (parser_context_t *context_p, /**< context *
|
||||
|| context_p->stack_top_uint8 == SCAN_STACK_FUNCTION_PARAMETERS
|
||||
|| context_p->stack_top_uint8 == SCAN_STACK_ARROW_ARGUMENTS);
|
||||
|
||||
JERRY_ASSERT ((stack_top != SCAN_STACK_ARRAY_LITERAL && stack_top != SCAN_STACK_OBJECT_LITERAL)
|
||||
|| SCANNER_NEEDS_BINDING_LIST (scanner_context_p->binding_type));
|
||||
JERRY_ASSERT (SCANNER_NEEDS_BINDING_LIST (scanner_context_p->binding_type)
|
||||
|| (stack_top != SCAN_STACK_ARRAY_LITERAL
|
||||
&& stack_top != SCAN_STACK_OBJECT_LITERAL
|
||||
&& stack_top != SCAN_STACK_OBJECT_LITERAL_WITH_SUPER));
|
||||
|
||||
if (binding_literal.literal_p->type & SCANNER_LITERAL_IS_USED)
|
||||
{
|
||||
@@ -823,9 +833,12 @@ scanner_scan_primary_expression_end (parser_context_t *context_p, /**< context *
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
case SCAN_STACK_ARRAY_LITERAL:
|
||||
case SCAN_STACK_OBJECT_LITERAL:
|
||||
case SCAN_STACK_OBJECT_LITERAL_WITH_SUPER:
|
||||
{
|
||||
if (((stack_top == SCAN_STACK_ARRAY_LITERAL) && (type != LEXER_RIGHT_SQUARE))
|
||||
|| ((stack_top == SCAN_STACK_OBJECT_LITERAL) && (type != LEXER_RIGHT_BRACE)))
|
||||
bool is_array = stack_top == SCAN_STACK_ARRAY_LITERAL;
|
||||
|
||||
if ((is_array && (type != LEXER_RIGHT_SQUARE))
|
||||
|| (!is_array && (type != LEXER_RIGHT_BRACE)))
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -867,6 +880,13 @@ scanner_scan_primary_expression_end (parser_context_t *context_p, /**< context *
|
||||
scanner_pop_binding_list (scanner_context_p);
|
||||
}
|
||||
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
if (stack_top == SCAN_STACK_OBJECT_LITERAL_WITH_SUPER)
|
||||
{
|
||||
scanner_info_t *info_p = scanner_insert_info (context_p, source_start.source_p, sizeof (scanner_info_t));
|
||||
info_p->type = SCANNER_TYPE_OBJECT_LITERAL_WITH_SUPER;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
scanner_context_p->mode = SCAN_MODE_POST_PRIMARY_EXPRESSION;
|
||||
return SCAN_KEEP_TOKEN;
|
||||
}
|
||||
@@ -941,7 +961,8 @@ scanner_scan_primary_expression_end (parser_context_t *context_p, /**< context *
|
||||
return SCAN_KEEP_TOKEN;
|
||||
}
|
||||
|
||||
JERRY_ASSERT (stack_top == SCAN_STACK_OBJECT_LITERAL);
|
||||
JERRY_ASSERT (stack_top == SCAN_STACK_OBJECT_LITERAL
|
||||
|| stack_top == SCAN_STACK_OBJECT_LITERAL_WITH_SUPER);
|
||||
|
||||
if (context_p->token.type == LEXER_LEFT_PAREN)
|
||||
{
|
||||
@@ -978,6 +999,7 @@ scanner_scan_primary_expression_end (parser_context_t *context_p, /**< context *
|
||||
parser_stack_pop_uint8 (context_p);
|
||||
|
||||
JERRY_ASSERT (context_p->stack_top_uint8 == SCAN_STACK_OBJECT_LITERAL
|
||||
|| context_p->stack_top_uint8 == SCAN_STACK_OBJECT_LITERAL_WITH_SUPER
|
||||
|| context_p->stack_top_uint8 == SCAN_STACK_FUNCTION_PROPERTY);
|
||||
|
||||
uint16_t status_flags = (uint16_t) (SCANNER_LITERAL_POOL_FUNCTION
|
||||
@@ -1966,6 +1988,10 @@ scanner_scan_statement_end (parser_context_t *context_p, /**< context */
|
||||
break;
|
||||
}
|
||||
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
bool has_super_reference = (scanner_context_p->active_literal_pool_p->status_flags
|
||||
& SCANNER_LITERAL_POOL_HAS_SUPER_REFERENCE) != 0;
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
scanner_pop_literal_pool (context_p, scanner_context_p);
|
||||
parser_stack_pop_uint8 (context_p);
|
||||
|
||||
@@ -1976,9 +2002,14 @@ scanner_scan_statement_end (parser_context_t *context_p, /**< context */
|
||||
scanner_context_p->mode = SCAN_MODE_CLASS_METHOD;
|
||||
return SCAN_KEEP_TOKEN;
|
||||
}
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
if (has_super_reference && context_p->stack_top_uint8 == SCAN_STACK_OBJECT_LITERAL)
|
||||
{
|
||||
parser_stack_change_last_uint8 (context_p, SCAN_STACK_OBJECT_LITERAL_WITH_SUPER);
|
||||
}
|
||||
#else /* ENABLED (JERRY_ESNEXT) */
|
||||
JERRY_ASSERT (context_p->stack_top_uint8 == SCAN_STACK_OBJECT_LITERAL);
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
lexer_next_token (context_p);
|
||||
|
||||
@@ -2869,7 +2900,12 @@ scanner_scan_all (parser_context_t *context_p, /**< context */
|
||||
}
|
||||
case SCAN_MODE_PROPERTY_NAME:
|
||||
{
|
||||
#if ENABLED (JERRY_ESNEXT)
|
||||
JERRY_ASSERT (stack_top == SCAN_STACK_OBJECT_LITERAL
|
||||
|| stack_top == SCAN_STACK_OBJECT_LITERAL_WITH_SUPER);
|
||||
#else /* !ENABLED (JERRY_ESNEXT) */
|
||||
JERRY_ASSERT (stack_top == SCAN_STACK_OBJECT_LITERAL);
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
|
||||
if (lexer_scan_identifier (context_p))
|
||||
{
|
||||
@@ -3471,6 +3507,13 @@ scan_completed:
|
||||
print_location = true;
|
||||
break;
|
||||
}
|
||||
case SCANNER_TYPE_OBJECT_LITERAL_WITH_SUPER:
|
||||
{
|
||||
JERRY_DEBUG_MSG (" OBJECT-LITERAL-WITH-SUPER: source:%d\n",
|
||||
(int) (info_p->source_p - source_start_p));
|
||||
print_location = false;
|
||||
break;
|
||||
}
|
||||
case SCANNER_TYPE_CLASS_CONSTRUCTOR:
|
||||
{
|
||||
JERRY_DEBUG_MSG (" CLASS-CONSTRUCTOR: source:%d\n",
|
||||
|
||||
@@ -50,6 +50,7 @@ typedef enum
|
||||
SCANNER_TYPE_LET_EXPRESSION, /**< let expression */
|
||||
SCANNER_TYPE_ERR_REDECLARED, /**< syntax error: a variable is redeclared */
|
||||
SCANNER_TYPE_ERR_ASYNC_FUNCTION, /**< an invalid async function follows */
|
||||
SCANNER_TYPE_OBJECT_LITERAL_WITH_SUPER, /**< object literal with inner super reference */
|
||||
#endif /* ENABLED (JERRY_ESNEXT) */
|
||||
} scanner_info_type_t;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user