Skip to content

Commit 1322e08

Browse files
authored
Fix parsing function statements containing invalid tokens (#3838)
Fixes #3821. JerryScript-DCO-1.0-Signed-off-by: Dániel Bátyai [email protected]
1 parent fe09200 commit 1322e08

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -710,9 +710,9 @@ parser_parse_function_statement (parser_context_t *context_p) /**< context */
710710
&& context_p->token.lit_location.type == LEXER_IDENT_LITERAL);
711711

712712
#if ENABLED (JERRY_ES2015)
713-
if (context_p->next_scanner_info_p->source_p == context_p->source_p)
713+
if (context_p->next_scanner_info_p->source_p == context_p->source_p
714+
&& context_p->next_scanner_info_p->type == SCANNER_TYPE_ERR_REDECLARED)
714715
{
715-
JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_ERR_REDECLARED);
716716
parser_raise_error (context_p, PARSER_ERR_VARIABLE_REDECLARED);
717717
}
718718
#endif /* ENABLED (JERRY_ES2015) */
@@ -730,8 +730,6 @@ parser_parse_function_statement (parser_context_t *context_p) /**< context */
730730
status_flags |= PARSER_HAS_NON_STRICT_ARG;
731731
}
732732

733-
JERRY_ASSERT (context_p->next_scanner_info_p->type == SCANNER_TYPE_FUNCTION);
734-
735733
#if ENABLED (JERRY_ES2015)
736734
if (is_generator_function)
737735
{
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright JS Foundation and other contributors, http://js.foundation
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+
function check_syntax_error (script)
16+
{
17+
try
18+
{
19+
eval (script);
20+
assert (false);
21+
}
22+
catch (e)
23+
{
24+
assert (e instanceof SyntaxError);
25+
}
26+
}
27+
28+
check_syntax_error ('function')
29+
check_syntax_error ('function a')
30+
check_syntax_error ('function a"')
31+
check_syntax_error ('function a"b')
32+
check_syntax_error ('function a("b')
33+
check_syntax_error ('function a(b, "c')
34+
check_syntax_error ('function a(b, c"d')
35+
check_syntax_error ('function a(b, c)"d')

0 commit comments

Comments
 (0)