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
This commit is contained in:
Andrey Shitov
2015-07-10 14:41:08 +03:00
parent 7f1a7981b9
commit b3fa7d9765
+22 -6
View File
@@ -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) skip_optional_name_and_parens (void)
{ {
if (token_is (TOK_NAME)) if (token_is (TOK_NAME))
{ {
token_after_newlines_must_be (TOK_OPEN_PAREN); token_after_newlines_must_be (TOK_OPEN_PAREN);
} }
if (token_is (TOK_OPEN_PAREN))
{
skip_newlines ();
}
else else
{ {
current_token_must_be (TOK_OPEN_PAREN); return false;
} }
while (!token_is (TOK_CLOSE_PAREN)) while (!token_is (TOK_CLOSE_PAREN))
{ {
skip_newlines (); skip_newlines ();
} }
}
return true;
} /* skip_optional_name_and_parens */
static void static void
skip_function (void) skip_function (void)
{ {
skip_newlines (); skip_newlines ();
skip_optional_name_and_parens (); if (skip_optional_name_and_parens ())
skip_newlines (); {
jsp_skip_braces (TOK_OPEN_BRACE); skip_newlines ();
jsp_skip_braces (TOK_OPEN_BRACE);
}
} }
static bool static bool