From b3fa7d97651265dacc173330d93ffcf6964c916a Mon Sep 17 00:00:00 2001 From: Andrey Shitov Date: Fri, 10 Jul 2015 14:41:08 +0300 Subject: [PATCH] Fix function skipping in preparse_scope: properly detect usage of 'function' keyword as property name. JerryScript-DCO-1.0-Signed-off-by: Andrey Shitov a.shitov@samsung.com --- jerry-core/parser/js/parser.cpp | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/jerry-core/parser/js/parser.cpp b/jerry-core/parser/js/parser.cpp index 752443169..08a6d1b38 100644 --- a/jerry-core/parser/js/parser.cpp +++ b/jerry-core/parser/js/parser.cpp @@ -2855,31 +2855,47 @@ parse_source_element (void) } } -static void +/** + * Skip function's optional name and parentheses + * + * @return: true, if skipped successfully + * false, if open parentheses wasn't found (this means that keyword 'function' is used as + * a property name) + */ +static bool skip_optional_name_and_parens (void) { if (token_is (TOK_NAME)) { token_after_newlines_must_be (TOK_OPEN_PAREN); } + + if (token_is (TOK_OPEN_PAREN)) + { + skip_newlines (); + } else { - current_token_must_be (TOK_OPEN_PAREN); + return false; } while (!token_is (TOK_CLOSE_PAREN)) { skip_newlines (); } -} + + return true; +} /* skip_optional_name_and_parens */ static void skip_function (void) { skip_newlines (); - skip_optional_name_and_parens (); - skip_newlines (); - jsp_skip_braces (TOK_OPEN_BRACE); + if (skip_optional_name_and_parens ()) + { + skip_newlines (); + jsp_skip_braces (TOK_OPEN_BRACE); + } } static bool