Skip to content

Commit 197ab51

Browse files
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
1 parent 5020015 commit 197ab51

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

jerry-core/ecma/builtin-objects/ecma-builtin-global.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ ecma_builtin_global_object_eval (ecma_value_t x) /**< routine's first argument *
8888
if (JERRY_UNLIKELY (!ecma_is_value_string (x)))
8989
{
9090
/* step 1 */
91+
ECMA_CLEAR_LOCAL_PARSE_OPTS ();
9192
return ecma_copy_value (x);
9293
}
9394

jerry-core/ecma/operations/ecma-eval.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ ecma_op_eval (ecma_value_t source_code, /**< source code */
5050

5151
if (ecma_is_value_magic_string (source_code, LIT_MAGIC_STRING__EMPTY))
5252
{
53+
ECMA_CLEAR_LOCAL_PARSE_OPTS ();
5354
return ECMA_VALUE_UNDEFINED;
5455
}
5556

tests/jerry/eval-lexical-env.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright JS Foundation and other contributors, http://js.foundation
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
function i(a, b = eval()){eval()};
16+
i(i("a"), eval("var a"));

0 commit comments

Comments
 (0)