Skip to content

Commit b496e68

Browse files
sand1kruben-ayrapetyan
authored andcommitted
Fix missing var_decl.
JerryScript-DCO-1.0-Signed-off-by: Andrey Shitov a.shitov@samsung.com
1 parent 9b9e537 commit b496e68

File tree

2 files changed

+81
-40
lines changed

2 files changed

+81
-40
lines changed

jerry-core/parser/js/parser.cpp

Lines changed: 62 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ static void parse_statement (void);
6565
static operand parse_assignment_expression (bool);
6666
static void parse_source_element_list (bool);
6767
static operand parse_argument_list (varg_list_type, operand, uint8_t *, operand *);
68+
static void process_keyword_names (void);
6869
static void skip_braces (void);
6970
static void skip_parens (void);
7071

@@ -2463,62 +2464,70 @@ skip_optional_name_and_parens (void)
24632464
}
24642465
}
24652466

2466-
static void
2467-
skip_braces (void)
2467+
static void process_keyword_names ()
24682468
{
2469-
current_token_must_be (TOK_OPEN_BRACE);
2470-
2471-
uint8_t nesting_level = 1;
2472-
while (nesting_level > 0)
2469+
if (token_is (TOK_KEYWORD))
24732470
{
2471+
keyword kw = (keyword) token_data ();
24742472
skip_newlines ();
2475-
if (token_is (TOK_OPEN_BRACE))
2473+
if (token_is (TOK_COLON))
24762474
{
2477-
nesting_level++;
2475+
lexer_add_keyword_or_numeric_literal_if_not_present (
2476+
create_literal_from_str_compute_len (lexer_keyword_to_string (kw)));
24782477
}
2479-
else if (token_is (TOK_CLOSE_BRACE))
2478+
else
24802479
{
2481-
nesting_level--;
2480+
lexer_save_token (tok);
24822481
}
2483-
else if (token_is (TOK_KEYWORD))
2482+
}
2483+
else if (token_is (TOK_NAME))
2484+
{
2485+
if (literal_equal_type_s (lexer_get_literal_by_id (token_data ()), "get")
2486+
|| literal_equal_type_s (lexer_get_literal_by_id (token_data ()), "set"))
24842487
{
2485-
keyword kw = (keyword) token_data ();
24862488
skip_newlines ();
2487-
if (token_is (TOK_COLON))
2488-
{
2489-
lexer_add_keyword_or_numeric_literal_if_not_present (
2490-
create_literal_from_str_compute_len (lexer_keyword_to_string (kw)));
2491-
}
2492-
else
2493-
{
2494-
lexer_save_token (tok);
2495-
}
2496-
}
2497-
else if (token_is (TOK_NAME))
2498-
{
2499-
if (literal_equal_type_s (lexer_get_literal_by_id (token_data ()), "get")
2500-
|| literal_equal_type_s (lexer_get_literal_by_id (token_data ()), "set"))
2489+
if (token_is (TOK_KEYWORD))
25012490
{
2491+
keyword kw = (keyword) token_data ();
25022492
skip_newlines ();
2503-
if (token_is (TOK_KEYWORD))
2493+
if (token_is (TOK_OPEN_PAREN))
25042494
{
2505-
keyword kw = (keyword) token_data ();
2506-
skip_newlines ();
2507-
if (token_is (TOK_OPEN_PAREN))
2508-
{
2509-
lexer_add_keyword_or_numeric_literal_if_not_present (
2510-
create_literal_from_str_compute_len (lexer_keyword_to_string (kw)));
2511-
}
2512-
else
2513-
{
2514-
lexer_save_token (tok);
2515-
}
2495+
lexer_add_keyword_or_numeric_literal_if_not_present (
2496+
create_literal_from_str_compute_len (lexer_keyword_to_string (kw)));
25162497
}
25172498
else
25182499
{
25192500
lexer_save_token (tok);
25202501
}
25212502
}
2503+
else
2504+
{
2505+
lexer_save_token (tok);
2506+
}
2507+
}
2508+
}
2509+
}
2510+
2511+
static void
2512+
skip_braces (void)
2513+
{
2514+
current_token_must_be (TOK_OPEN_BRACE);
2515+
2516+
uint8_t nesting_level = 1;
2517+
while (nesting_level > 0)
2518+
{
2519+
skip_newlines ();
2520+
if (token_is (TOK_OPEN_BRACE))
2521+
{
2522+
nesting_level++;
2523+
}
2524+
else if (token_is (TOK_CLOSE_BRACE))
2525+
{
2526+
nesting_level--;
2527+
}
2528+
else
2529+
{
2530+
process_keyword_names ();
25222531
}
25232532
}
25242533
}
@@ -2649,9 +2658,18 @@ preparse_scope (bool is_global)
26492658

26502659
dump_reg_var_decl_for_rewrite ();
26512660

2652-
while (!token_is (end_tt))
2661+
size_t nesting_level = 0;
2662+
while (nesting_level > 0 || !token_is (end_tt))
26532663
{
2654-
if (is_keyword (KW_VAR))
2664+
if (token_is (TOK_OPEN_BRACE))
2665+
{
2666+
nesting_level++;
2667+
}
2668+
else if (token_is (TOK_CLOSE_BRACE))
2669+
{
2670+
nesting_level--;
2671+
}
2672+
else if (is_keyword (KW_VAR))
26552673
{
26562674
preparse_var_decls ();
26572675
}
@@ -2663,6 +2681,10 @@ preparse_scope (bool is_global)
26632681
{
26642682
skip_braces ();
26652683
}
2684+
else
2685+
{
2686+
process_keyword_names ();
2687+
}
26662688
skip_newlines ();
26672689
}
26682690

tests/jerry/var_decl.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2015 Samsung Electronics Co., Ltd.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
{
16+
var y;
17+
}
18+
var x = y;
19+
assert (x === undefined);

0 commit comments

Comments
 (0)