From a7c654617d37fce1ea172405fbeb68949739338b Mon Sep 17 00:00:00 2001 From: Zoltan Herczeg Date: Fri, 20 Sep 2019 11:27:05 +0200 Subject: [PATCH] There is no need to update the scanner info chain after a for/while statement. (#3138) Fixes #3131. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com --- jerry-core/parser/js/js-parser-statm.c | 6 ++++-- tests/jerry/fail/regression-test-issue-3131.js | 15 +++++++++++++++ tests/jerry/switch-case.js | 3 +++ 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 tests/jerry/fail/regression-test-issue-3131.js diff --git a/jerry-core/parser/js/js-parser-statm.c b/jerry-core/parser/js/js-parser-statm.c index d1efcfa96..2b1da5791 100644 --- a/jerry-core/parser/js/js-parser-statm.c +++ b/jerry-core/parser/js/js-parser-statm.c @@ -842,8 +842,9 @@ parser_parse_while_statement_end (parser_context_t *context_p) /**< context */ parser_emit_cbc_backward_branch (context_p, (uint16_t) opcode, while_statement.start_offset); parser_set_breaks_to_current_position (context_p, loop.branch_list_p); + /* Calling scanner_seek is unnecessary because all + * info blocks inside the while statement should be processed. */ scanner_set_location (context_p, &location); - scanner_seek (context_p); context_p->token = current_token; } /* parser_parse_while_statement_end */ @@ -1186,8 +1187,9 @@ parser_parse_for_statement_end (parser_context_t *context_p) /**< context */ parser_emit_cbc_backward_branch (context_p, (uint16_t) opcode, for_statement.start_offset); parser_set_breaks_to_current_position (context_p, loop.branch_list_p); + /* Calling scanner_seek is unnecessary because all + * info blocks inside the for statement should be processed. */ scanner_set_location (context_p, &location); - scanner_seek (context_p); context_p->token = current_token; } /* parser_parse_for_statement_end */ diff --git a/tests/jerry/fail/regression-test-issue-3131.js b/tests/jerry/fail/regression-test-issue-3131.js new file mode 100644 index 000000000..7acd11123 --- /dev/null +++ b/tests/jerry/fail/regression-test-issue-3131.js @@ -0,0 +1,15 @@ +// Copyright JS Foundation and other contributors, http://js.foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +switch ( $) { case $: for ( ; ; ) ; case $ :} diff --git a/tests/jerry/switch-case.js b/tests/jerry/switch-case.js index 64dd47956..192f8fdbd 100644 --- a/tests/jerry/switch-case.js +++ b/tests/jerry/switch-case.js @@ -103,3 +103,6 @@ switch ("var") { } assert (flow === '123a4'); + +switch (0) { case 0: for (;false;); case 1: } +switch (0) { case 0: while (false); case 1: }