From 197ab510e5294d48959e784349a47628364d6bfb Mon Sep 17 00:00:00 2001 From: tangbin <2387440390@qq.com> Date: Thu, 24 Jul 2025 19:23:14 +0800 Subject: [PATCH] When the eval is either a non-string or empty, clear the local state to prevent contamination of the next parsing unit JerryScript-DCO-1.0-Signed-off-by: tangbin 2387440390@qq.com --- .../ecma/builtin-objects/ecma-builtin-global.c | 1 + jerry-core/ecma/operations/ecma-eval.c | 1 + tests/jerry/eval-lexical-env.js | 16 ++++++++++++++++ 3 files changed, 18 insertions(+) create mode 100644 tests/jerry/eval-lexical-env.js diff --git a/jerry-core/ecma/builtin-objects/ecma-builtin-global.c b/jerry-core/ecma/builtin-objects/ecma-builtin-global.c index d9ccc8ff68..8018bbcbbb 100644 --- a/jerry-core/ecma/builtin-objects/ecma-builtin-global.c +++ b/jerry-core/ecma/builtin-objects/ecma-builtin-global.c @@ -88,6 +88,7 @@ ecma_builtin_global_object_eval (ecma_value_t x) /**< routine's first argument * if (JERRY_UNLIKELY (!ecma_is_value_string (x))) { /* step 1 */ + ECMA_CLEAR_LOCAL_PARSE_OPTS (); return ecma_copy_value (x); } diff --git a/jerry-core/ecma/operations/ecma-eval.c b/jerry-core/ecma/operations/ecma-eval.c index ac8e2c40f3..da61b3631c 100644 --- a/jerry-core/ecma/operations/ecma-eval.c +++ b/jerry-core/ecma/operations/ecma-eval.c @@ -50,6 +50,7 @@ ecma_op_eval (ecma_value_t source_code, /**< source code */ if (ecma_is_value_magic_string (source_code, LIT_MAGIC_STRING__EMPTY)) { + ECMA_CLEAR_LOCAL_PARSE_OPTS (); return ECMA_VALUE_UNDEFINED; } diff --git a/tests/jerry/eval-lexical-env.js b/tests/jerry/eval-lexical-env.js new file mode 100644 index 0000000000..439b627063 --- /dev/null +++ b/tests/jerry/eval-lexical-env.js @@ -0,0 +1,16 @@ +// 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 i(a, b = eval()){eval()}; +i(i("a"), eval("var a"));