Skip to content

Commit 38111c0

Browse files
authored
Fix redeclaration of existing var variables in functions with argument context. (#3891)
Fixes #3888 JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg zherczeg.u-szeged@partner.samsung.com
1 parent 01e9670 commit 38111c0

File tree

3 files changed

+54
-7
lines changed

3 files changed

+54
-7
lines changed

jerry-core/vm/vm.c

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,17 +1421,31 @@ vm_loop (vm_frame_ctx_t *frame_ctx_p) /**< frame context */
14211421
JERRY_ASSERT (ecma_get_lex_env_type (lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE);
14221422
JERRY_ASSERT (prev_lex_env_p != NULL
14231423
&& ecma_get_lex_env_type (prev_lex_env_p) == ECMA_LEXICAL_ENVIRONMENT_DECLARATIVE);
1424-
JERRY_ASSERT (ecma_find_named_property (prev_lex_env_p, name_p) == NULL);
14251424

1425+
ecma_property_t *property_p = ecma_find_named_property (prev_lex_env_p, name_p);
14261426
ecma_property_value_t *property_value_p;
1427-
property_value_p = ecma_create_named_data_property (prev_lex_env_p,
1428-
name_p,
1429-
ECMA_PROPERTY_CONFIGURABLE_WRITABLE,
1430-
NULL);
14311427

1432-
if (lit_value == ECMA_VALUE_UNDEFINED)
1428+
if (property_p == NULL)
14331429
{
1434-
continue;
1430+
property_value_p = ecma_create_named_data_property (prev_lex_env_p,
1431+
name_p,
1432+
ECMA_PROPERTY_CONFIGURABLE_WRITABLE,
1433+
NULL);
1434+
1435+
if (lit_value == ECMA_VALUE_UNDEFINED)
1436+
{
1437+
continue;
1438+
}
1439+
}
1440+
else
1441+
{
1442+
if (lit_value == ECMA_VALUE_UNDEFINED)
1443+
{
1444+
continue;
1445+
}
1446+
1447+
property_value_p = ECMA_PROPERTY_VALUE_PTR (property_p);
1448+
ecma_free_value_if_not_object (property_value_p->value);
14351449
}
14361450

14371451
property_value_p->value = lit_value;

tests/jerry/es2015/function-scope2.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,17 @@ function i([a], get = () => a, set = (v) => a = v) {
9595
assert(get() === 3);
9696
}
9797
i([1]);
98+
99+
function j(a = eval()) {
100+
var a = 3.14;
101+
102+
try {
103+
eval("throw 1; function a() { return 8; }")
104+
assert(false)
105+
} catch (e) {
106+
assert(e === 1)
107+
}
108+
109+
assert(a() === 8)
110+
}
111+
j()
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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(id_0, b = (eval("var x"))) {
16+
function x() {}
17+
eval(!eval("var x = {}; x instanceof assert;"))
18+
}
19+
i()

0 commit comments

Comments
 (0)