From d248eef21c9b3a914de4bef096dee5c8ce228402 Mon Sep 17 00:00:00 2001 From: Zoltan Herczeg Date: Fri, 20 Sep 2019 05:26:07 -0700 Subject: [PATCH] Free scanner info even if for statement parsing is failed. Fixes #3140. JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com --- jerry-core/parser/js/js-parser-statm.c | 7 +++++++ tests/jerry/fail/regression-test-issue-3140.js | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 tests/jerry/fail/regression-test-issue-3140.js diff --git a/jerry-core/parser/js/js-parser-statm.c b/jerry-core/parser/js/js-parser-statm.c index e39a525236..b86efffadc 100644 --- a/jerry-core/parser/js/js-parser-statm.c +++ b/jerry-core/parser/js/js-parser-statm.c @@ -1064,6 +1064,13 @@ parser_parse_for_statement_start (parser_context_t *context_p) /**< context */ if (context_p->next_scanner_info_p->source_p != context_p->source_p || ((scanner_for_info_t *) context_p->next_scanner_info_p)->end_location.source_p == NULL) { + if (context_p->next_scanner_info_p->source_p == context_p->source_p) + { + /* Even though the scanning is failed, there might be valid statements + * inside the for statement which depend on scanner info blocks. */ + scanner_release_next (context_p, sizeof (parser_for_statement_t)); + } + /* The prescanner couldn't find the second semicolon or the closing paranthesis. */ lexer_next_token (context_p); parser_parse_expression (context_p, PARSE_EXPR); diff --git a/tests/jerry/fail/regression-test-issue-3140.js b/tests/jerry/fail/regression-test-issue-3140.js new file mode 100644 index 0000000000..b9094262b5 --- /dev/null +++ b/tests/jerry/fail/regression-test-issue-3140.js @@ -0,0 +1,18 @@ +// 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. + +for (; []; [//]) +function f14(v33, v34) { +switch (!0x13) {} + }