Skip to content

Commit 0121b2b

Browse files
zherczegdbatyai
authored andcommitted
Fix object initializers for get and set properties. (#3164)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg [email protected]
1 parent 4eae760 commit 0121b2b

File tree

3 files changed

+51
-5
lines changed

3 files changed

+51
-5
lines changed

jerry-core/parser/js/js-lexer.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,8 @@ lexer_skip_empty_statements (parser_context_t *context_p) /**< context */
292292
context_p->source_p++;
293293
lexer_skip_spaces (context_p);
294294
}
295+
296+
context_p->token.flags = (uint8_t) (context_p->token.flags | LEXER_NO_SKIP_SPACES);
295297
} /* lexer_skip_empty_statements */
296298
#endif /* ENABLED (JERRY_ES2015_CLASS) */
297299

@@ -2305,8 +2307,13 @@ lexer_expect_object_literal_id (parser_context_t *context_p, /**< context */
23052307
&& context_p->token.lit_location.length == 3)
23062308
{
23072309
lexer_skip_spaces (context_p);
2310+
context_p->token.flags = (uint8_t) (context_p->token.flags | LEXER_NO_SKIP_SPACES);
23082311

23092312
if (context_p->source_p < context_p->source_end_p
2313+
#if ENABLED (JERRY_ES2015_OBJECT_INITIALIZER)
2314+
&& context_p->source_p[0] != LIT_CHAR_COMMA
2315+
&& context_p->source_p[0] != LIT_CHAR_RIGHT_BRACE
2316+
#endif /* ENABLED (JERRY_ES2015_OBJECT_INITIALIZER) */
23102317
&& context_p->source_p[0] != LIT_CHAR_COLON)
23112318
{
23122319
if (lexer_compare_literal_to_string (context_p, "get", 3))
@@ -2421,8 +2428,13 @@ lexer_scan_identifier (parser_context_t *context_p, /**< context */
24212428
&& context_p->token.lit_location.length == 3)
24222429
{
24232430
lexer_skip_spaces (context_p);
2431+
context_p->token.flags = (uint8_t) (context_p->token.flags | LEXER_NO_SKIP_SPACES);
24242432

24252433
if (context_p->source_p < context_p->source_end_p
2434+
#if ENABLED (JERRY_ES2015_OBJECT_INITIALIZER)
2435+
&& context_p->source_p[0] != LIT_CHAR_COMMA
2436+
&& context_p->source_p[0] != LIT_CHAR_RIGHT_BRACE
2437+
#endif /* ENABLED (JERRY_ES2015_OBJECT_INITIALIZER) */
24262438
&& context_p->source_p[0] != LIT_CHAR_COLON)
24272439
{
24282440
if (lexer_compare_literal_to_string (context_p, "get", 3))

jerry-core/parser/js/js-scanner.c

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1955,6 +1955,14 @@ scanner_scan_all (parser_context_t *context_p, /**< context */
19551955
break;
19561956
}
19571957

1958+
JERRY_ASSERT (context_p->token.type == LEXER_LITERAL);
1959+
1960+
#if ENABLED (JERRY_ES2015_OBJECT_INITIALIZER)
1961+
parser_line_counter_t start_line = context_p->token.line;
1962+
parser_line_counter_t start_column = context_p->token.column;
1963+
bool is_ident = (context_p->token.lit_location.type == LEXER_IDENT_LITERAL);
1964+
#endif /* ENABLED (JERRY_ES2015_OBJECT_INITIALIZER) */
1965+
19581966
lexer_next_token (context_p);
19591967

19601968
#if ENABLED (JERRY_ES2015_OBJECT_INITIALIZER)
@@ -1965,13 +1973,32 @@ scanner_scan_all (parser_context_t *context_p, /**< context */
19651973
continue;
19661974
}
19671975

1968-
if (context_p->token.type == LEXER_COMMA)
1976+
if (is_ident
1977+
&& (context_p->token.type == LEXER_COMMA || context_p->token.type == LEXER_RIGHT_BRACE))
19691978
{
1970-
continue;
1971-
}
1979+
context_p->source_p = context_p->token.lit_location.char_p;
1980+
context_p->line = start_line;
1981+
context_p->column = start_column;
1982+
1983+
lexer_next_token (context_p);
1984+
1985+
JERRY_ASSERT (context_p->token.type != LEXER_LITERAL
1986+
|| context_p->token.lit_location.type == LEXER_IDENT_LITERAL);
1987+
1988+
if (context_p->token.type != LEXER_LITERAL)
1989+
{
1990+
scanner_raise_error (context_p);
1991+
}
1992+
1993+
lexer_next_token (context_p);
1994+
1995+
if (context_p->token.type == LEXER_COMMA)
1996+
{
1997+
continue;
1998+
}
1999+
2000+
JERRY_ASSERT (context_p->token.type == LEXER_RIGHT_BRACE);
19722001

1973-
if (context_p->token.type == LEXER_RIGHT_BRACE)
1974-
{
19752002
parser_stack_pop_uint8 (context_p);
19762003
scanner_context.mode = SCAN_MODE_POST_PRIMARY_EXPRESSION;
19772004
break;

tests/jerry/es2015/object-initializer.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,11 @@ default:
6262
({ true: true });
6363
({ 13: 13 });
6464
({ "x": "x" });
65+
66+
var get = 8;
67+
var set = 12;
68+
var o = ({ get, set });
69+
70+
assert(o.get == 8);
71+
assert(o.set == 12);
6572
}

0 commit comments

Comments
 (0)