Skip to content

Commit 906558b

Browse files
committed
Fix: switch statement jumps to incorrect case body
JerryScript-DCO-1.0-Signed-off-by: Hanjoung Lee [email protected]
1 parent 3e31931 commit 906558b

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

jerry-core/parser/js/parser.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2462,10 +2462,7 @@ parse_switch_statement (void)
24622462
}
24632463
current_token_must_be (TOK_CLOSE_BRACE);
24642464

2465-
if (was_default)
2466-
{
2467-
dump_default_clause_check_for_rewrite ();
2468-
}
2465+
dump_default_clause_check_for_rewrite ();
24692466

24702467
lexer_seek (start_loc);
24712468
next_token_must_be (TOK_OPEN_BRACE);
@@ -2501,6 +2498,12 @@ parse_switch_statement (void)
25012498
parse_statement_list ();
25022499
skip_newlines ();
25032500
}
2501+
2502+
if (!was_default)
2503+
{
2504+
rewrite_default_clause ();
2505+
}
2506+
25042507
current_token_must_be (TOK_CLOSE_BRACE);
25052508
skip_token ();
25062509

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

0 commit comments

Comments
 (0)