From 1cfda262bddfb2b541ddd7638a7b41b707499ed1 Mon Sep 17 00:00:00 2001 From: Zoltan Herczeg Date: Tue, 17 Mar 2020 13:06:59 +0100 Subject: [PATCH] Catch paramter must not be scanned as function in ES5.1 (#3618) Fixes #3554 JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com --- jerry-core/parser/js/js-scanner-util.c | 19 ++++++++++---- tests/jerry/es5.1/try-catch.js | 26 +++++++++++++++++++ .../jerry/fail/regression-test-issue-3554.js | 15 +++++++++++ 3 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 tests/jerry/es5.1/try-catch.js create mode 100644 tests/jerry/fail/regression-test-issue-3554.js diff --git a/jerry-core/parser/js/js-scanner-util.c b/jerry-core/parser/js/js-scanner-util.c index 73a8ff814..58a0d5cc2 100644 --- a/jerry-core/parser/js/js-scanner-util.c +++ b/jerry-core/parser/js/js-scanner-util.c @@ -553,17 +553,26 @@ scanner_pop_literal_pool (parser_context_t *context_p, /**< context */ no_declarations++; - if (type & SCANNER_LITERAL_IS_FUNC) - { - no_declarations++; - } - if (no_reg || (type & no_reg_types)) { type |= SCANNER_LITERAL_NO_REG; literal_p->type = type; } + if (type & SCANNER_LITERAL_IS_FUNC) + { + no_declarations++; + +#if !ENABLED (JERRY_ES2015) + if (type & SCANNER_LITERAL_IS_LOCAL) + { + /* Catch parameters cannot be functions. */ + literal_p->type = (uint8_t) (type & ~SCANNER_LITERAL_IS_FUNC); + no_declarations--; + } +#endif /* !ENABLED (JERRY_ES2015) */ + } + intptr_t diff = (intptr_t) (literal_p->char_p - prev_source_p); if (diff >= 1 && diff <= UINT8_MAX) diff --git a/tests/jerry/es5.1/try-catch.js b/tests/jerry/es5.1/try-catch.js new file mode 100644 index 000000000..bfd310814 --- /dev/null +++ b/tests/jerry/es5.1/try-catch.js @@ -0,0 +1,26 @@ +// 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. + +function f() { + try { + assert(e() == 6) + throw 8; + assert(false); + } catch (e) { + function e() { return 6 } + assert(e == 8); + } +} + +f(); diff --git a/tests/jerry/fail/regression-test-issue-3554.js b/tests/jerry/fail/regression-test-issue-3554.js new file mode 100644 index 000000000..4f01e94a2 --- /dev/null +++ b/tests/jerry/fail/regression-test-issue-3554.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. + +(function(){try{}catch(e){function e