Fix object initializers for get and set properties. (#3164)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
This commit is contained in:
committed by
Dániel Bátyai
parent
4eae760180
commit
0121b2bbcf
@@ -292,6 +292,8 @@ lexer_skip_empty_statements (parser_context_t *context_p) /**< context */
|
|||||||
context_p->source_p++;
|
context_p->source_p++;
|
||||||
lexer_skip_spaces (context_p);
|
lexer_skip_spaces (context_p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context_p->token.flags = (uint8_t) (context_p->token.flags | LEXER_NO_SKIP_SPACES);
|
||||||
} /* lexer_skip_empty_statements */
|
} /* lexer_skip_empty_statements */
|
||||||
#endif /* ENABLED (JERRY_ES2015_CLASS) */
|
#endif /* ENABLED (JERRY_ES2015_CLASS) */
|
||||||
|
|
||||||
@@ -2305,8 +2307,13 @@ lexer_expect_object_literal_id (parser_context_t *context_p, /**< context */
|
|||||||
&& context_p->token.lit_location.length == 3)
|
&& context_p->token.lit_location.length == 3)
|
||||||
{
|
{
|
||||||
lexer_skip_spaces (context_p);
|
lexer_skip_spaces (context_p);
|
||||||
|
context_p->token.flags = (uint8_t) (context_p->token.flags | LEXER_NO_SKIP_SPACES);
|
||||||
|
|
||||||
if (context_p->source_p < context_p->source_end_p
|
if (context_p->source_p < context_p->source_end_p
|
||||||
|
#if ENABLED (JERRY_ES2015_OBJECT_INITIALIZER)
|
||||||
|
&& context_p->source_p[0] != LIT_CHAR_COMMA
|
||||||
|
&& context_p->source_p[0] != LIT_CHAR_RIGHT_BRACE
|
||||||
|
#endif /* ENABLED (JERRY_ES2015_OBJECT_INITIALIZER) */
|
||||||
&& context_p->source_p[0] != LIT_CHAR_COLON)
|
&& context_p->source_p[0] != LIT_CHAR_COLON)
|
||||||
{
|
{
|
||||||
if (lexer_compare_literal_to_string (context_p, "get", 3))
|
if (lexer_compare_literal_to_string (context_p, "get", 3))
|
||||||
@@ -2421,8 +2428,13 @@ lexer_scan_identifier (parser_context_t *context_p, /**< context */
|
|||||||
&& context_p->token.lit_location.length == 3)
|
&& context_p->token.lit_location.length == 3)
|
||||||
{
|
{
|
||||||
lexer_skip_spaces (context_p);
|
lexer_skip_spaces (context_p);
|
||||||
|
context_p->token.flags = (uint8_t) (context_p->token.flags | LEXER_NO_SKIP_SPACES);
|
||||||
|
|
||||||
if (context_p->source_p < context_p->source_end_p
|
if (context_p->source_p < context_p->source_end_p
|
||||||
|
#if ENABLED (JERRY_ES2015_OBJECT_INITIALIZER)
|
||||||
|
&& context_p->source_p[0] != LIT_CHAR_COMMA
|
||||||
|
&& context_p->source_p[0] != LIT_CHAR_RIGHT_BRACE
|
||||||
|
#endif /* ENABLED (JERRY_ES2015_OBJECT_INITIALIZER) */
|
||||||
&& context_p->source_p[0] != LIT_CHAR_COLON)
|
&& context_p->source_p[0] != LIT_CHAR_COLON)
|
||||||
{
|
{
|
||||||
if (lexer_compare_literal_to_string (context_p, "get", 3))
|
if (lexer_compare_literal_to_string (context_p, "get", 3))
|
||||||
|
|||||||
@@ -1955,6 +1955,14 @@ scanner_scan_all (parser_context_t *context_p, /**< context */
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JERRY_ASSERT (context_p->token.type == LEXER_LITERAL);
|
||||||
|
|
||||||
|
#if ENABLED (JERRY_ES2015_OBJECT_INITIALIZER)
|
||||||
|
parser_line_counter_t start_line = context_p->token.line;
|
||||||
|
parser_line_counter_t start_column = context_p->token.column;
|
||||||
|
bool is_ident = (context_p->token.lit_location.type == LEXER_IDENT_LITERAL);
|
||||||
|
#endif /* ENABLED (JERRY_ES2015_OBJECT_INITIALIZER) */
|
||||||
|
|
||||||
lexer_next_token (context_p);
|
lexer_next_token (context_p);
|
||||||
|
|
||||||
#if ENABLED (JERRY_ES2015_OBJECT_INITIALIZER)
|
#if ENABLED (JERRY_ES2015_OBJECT_INITIALIZER)
|
||||||
@@ -1965,13 +1973,32 @@ scanner_scan_all (parser_context_t *context_p, /**< context */
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context_p->token.type == LEXER_COMMA)
|
if (is_ident
|
||||||
|
&& (context_p->token.type == LEXER_COMMA || context_p->token.type == LEXER_RIGHT_BRACE))
|
||||||
{
|
{
|
||||||
continue;
|
context_p->source_p = context_p->token.lit_location.char_p;
|
||||||
}
|
context_p->line = start_line;
|
||||||
|
context_p->column = start_column;
|
||||||
|
|
||||||
|
lexer_next_token (context_p);
|
||||||
|
|
||||||
|
JERRY_ASSERT (context_p->token.type != LEXER_LITERAL
|
||||||
|
|| context_p->token.lit_location.type == LEXER_IDENT_LITERAL);
|
||||||
|
|
||||||
|
if (context_p->token.type != LEXER_LITERAL)
|
||||||
|
{
|
||||||
|
scanner_raise_error (context_p);
|
||||||
|
}
|
||||||
|
|
||||||
|
lexer_next_token (context_p);
|
||||||
|
|
||||||
|
if (context_p->token.type == LEXER_COMMA)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
JERRY_ASSERT (context_p->token.type == LEXER_RIGHT_BRACE);
|
||||||
|
|
||||||
if (context_p->token.type == LEXER_RIGHT_BRACE)
|
|
||||||
{
|
|
||||||
parser_stack_pop_uint8 (context_p);
|
parser_stack_pop_uint8 (context_p);
|
||||||
scanner_context.mode = SCAN_MODE_POST_PRIMARY_EXPRESSION;
|
scanner_context.mode = SCAN_MODE_POST_PRIMARY_EXPRESSION;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -62,4 +62,11 @@ default:
|
|||||||
({ true: true });
|
({ true: true });
|
||||||
({ 13: 13 });
|
({ 13: 13 });
|
||||||
({ "x": "x" });
|
({ "x": "x" });
|
||||||
|
|
||||||
|
var get = 8;
|
||||||
|
var set = 12;
|
||||||
|
var o = ({ get, set });
|
||||||
|
|
||||||
|
assert(o.get == 8);
|
||||||
|
assert(o.set == 12);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user