@@ -67,8 +67,6 @@ static void parse_statement (jsp_label_t *outermost_stmt_label_p);
6767static operand parse_assignment_expression (bool );
6868static void parse_source_element_list (bool );
6969static operand parse_argument_list (varg_list_type, operand, uint8_t *, operand *);
70- static void skip_braces (void );
71- static void skip_parens (void );
7270
7371static bool
7472token_is (token_type tt)
@@ -173,6 +171,55 @@ is_strict_mode (void)
173171 return scopes_tree_strict_mode (STACK_TOP (scopes));
174172}
175173
174+ /* *
175+ * Skip block, defined with braces of specified type
176+ *
177+ * Note:
178+ * Missing corresponding brace is considered a syntax error
179+ *
180+ * Note:
181+ * Opening brace of the block to skip should be set as current
182+ * token when the routine is called
183+ */
184+ static void
185+ jsp_skip_braces (token_type brace_type) /* *< type of the opening brace */
186+ {
187+ current_token_must_be (brace_type);
188+
189+ token_type closing_bracket_type;
190+
191+ if (brace_type == TOK_OPEN_PAREN)
192+ {
193+ closing_bracket_type = TOK_CLOSE_PAREN;
194+ }
195+ else if (brace_type == TOK_OPEN_BRACE)
196+ {
197+ closing_bracket_type = TOK_CLOSE_BRACE;
198+ }
199+ else
200+ {
201+ JERRY_ASSERT (brace_type == TOK_OPEN_SQUARE);
202+ closing_bracket_type = TOK_CLOSE_SQUARE;
203+ }
204+
205+ skip_newlines ();
206+
207+ while (!token_is (closing_bracket_type)
208+ && !token_is (TOK_EOF))
209+ {
210+ if (token_is (TOK_OPEN_PAREN)
211+ || token_is (TOK_OPEN_BRACE)
212+ || token_is (TOK_OPEN_SQUARE))
213+ {
214+ jsp_skip_braces (tok.type );
215+ }
216+
217+ skip_newlines ();
218+ }
219+
220+ current_token_must_be (closing_bracket_type);
221+ } /* jsp_skip_braces */
222+
176223/* property_name
177224 : Identifier
178225 | Keyword
@@ -1964,7 +2011,7 @@ parse_while_statement (jsp_label_t *outermost_stmt_label_p) /**< outermost (firs
19642011
19652012 token_after_newlines_must_be (TOK_OPEN_PAREN);
19662013 const locus cond_loc = tok.loc ;
1967- skip_parens ( );
2014+ jsp_skip_braces (TOK_OPEN_PAREN );
19682015
19692016 dump_jump_to_end_for_rewrite ();
19702017
@@ -2020,7 +2067,7 @@ skip_case_clause_body (void)
20202067 {
20212068 if (token_is (TOK_OPEN_BRACE))
20222069 {
2023- skip_braces ( );
2070+ jsp_skip_braces (TOK_OPEN_BRACE );
20242071 }
20252072 skip_newlines ();
20262073 }
@@ -2565,73 +2612,13 @@ skip_optional_name_and_parens (void)
25652612 }
25662613}
25672614
2568- static void
2569- skip_braces (void )
2570- {
2571- current_token_must_be (TOK_OPEN_BRACE);
2572-
2573- uint8_t nesting_level = 1 ;
2574- while (nesting_level > 0 )
2575- {
2576- skip_newlines ();
2577- if (token_is (TOK_OPEN_BRACE))
2578- {
2579- nesting_level++;
2580- }
2581- else if (token_is (TOK_CLOSE_BRACE))
2582- {
2583- nesting_level--;
2584- }
2585- }
2586- }
2587-
25882615static void
25892616skip_function (void )
25902617{
25912618 skip_newlines ();
25922619 skip_optional_name_and_parens ();
25932620 skip_newlines ();
2594- skip_braces ();
2595- }
2596-
2597- static void
2598- skip_squares (void )
2599- {
2600- current_token_must_be (TOK_OPEN_SQUARE);
2601-
2602- uint8_t nesting_level = 1 ;
2603- while (nesting_level > 0 )
2604- {
2605- skip_newlines ();
2606- if (token_is (TOK_OPEN_SQUARE))
2607- {
2608- nesting_level++;
2609- }
2610- else if (token_is (TOK_CLOSE_SQUARE))
2611- {
2612- nesting_level--;
2613- }
2614- }
2615- }
2616-
2617- static void
2618- skip_parens (void )
2619- {
2620- current_token_must_be (TOK_OPEN_PAREN);
2621-
2622- uint8_t nesting_level = 1 ;
2623- while (nesting_level > 0 )
2624- {
2625- skip_newlines ();
2626- if (token_is (TOK_OPEN_PAREN))
2627- {
2628- nesting_level++;
2629- }
2630- else if (token_is (TOK_CLOSE_PAREN))
2631- {
2632- nesting_level--;
2633- }
2634- }
2621+ jsp_skip_braces (TOK_OPEN_BRACE);
26352622}
26362623
26372624static bool
@@ -2670,15 +2657,15 @@ preparse_var_decls (void)
26702657 }
26712658 else if (token_is (TOK_OPEN_BRACE))
26722659 {
2673- skip_braces ( );
2660+ jsp_skip_braces (TOK_OPEN_BRACE );
26742661 }
26752662 else if (token_is (TOK_OPEN_SQUARE))
26762663 {
2677- skip_squares ( );
2664+ jsp_skip_braces (TOK_OPEN_SQUARE );
26782665 }
26792666 else if (token_is (TOK_OPEN_PAREN))
26802667 {
2681- skip_parens ( );
2668+ jsp_skip_braces (TOK_OPEN_PAREN );
26822669 }
26832670 skip_token ();
26842671 }
@@ -2739,7 +2726,7 @@ preparse_scope (bool is_global)
27392726 }
27402727 else if (token_is (TOK_OPEN_BRACE))
27412728 {
2742- skip_braces ( );
2729+ jsp_skip_braces (TOK_OPEN_BRACE );
27432730 }
27442731 else
27452732 {
0 commit comments