Skip to content

Commit 1b01171

Browse files
authored
Update forcing of lexical environment creation for functions. (jerryscript-project#3683)
JerryScript-DCO-1.0-Signed-off-by: Zoltan Herczeg [email protected]
1 parent 4be9ffd commit 1b01171

File tree

4 files changed

+45
-3
lines changed

4 files changed

+45
-3
lines changed

jerry-core/parser/js/js-parser-expr.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ parser_emit_unary_lvalue_opcode (parser_context_t *context_p, /**< context */
192192
parser_raise_error (context_p, PARSER_ERR_DELETE_IDENT_NOT_ALLOWED);
193193
}
194194

195-
context_p->status_flags |= PARSER_LEXICAL_ENV_NEEDED;
196195
unary_opcode = CBC_DELETE_IDENT_PUSH_RESULT;
197196
}
198197
else
@@ -2006,6 +2005,8 @@ parser_process_unary_expression (parser_context_t *context_p, /**< context */
20062005

20072006
if (is_eval)
20082007
{
2008+
context_p->status_flags |= PARSER_LEXICAL_ENV_NEEDED;
2009+
20092010
#if ENABLED (JERRY_ES2015)
20102011
if (context_p->status_flags & (PARSER_ALLOW_SUPER_CALL | PARSER_ALLOW_SUPER | PARSER_ALLOW_NEW_TARGET))
20112012
{

jerry-core/parser/js/js-parser-statm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ parser_parse_with_statement_start (parser_context_t *context_p) /**< context */
859859

860860
uint8_t inside_with = (context_p->status_flags & PARSER_INSIDE_WITH) != 0;
861861

862-
context_p->status_flags |= PARSER_INSIDE_WITH | PARSER_LEXICAL_ENV_NEEDED;
862+
context_p->status_flags |= PARSER_INSIDE_WITH;
863863
parser_emit_cbc_ext_forward_branch (context_p,
864864
CBC_EXT_WITH_CREATE_CONTEXT,
865865
&with_statement.branch);

jerry-core/parser/js/js-parser.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1272,7 +1272,7 @@ parser_post_processing (parser_context_t *context_p) /**< context */
12721272
}
12731273

12741274
/* Arguments is stored in the lexical environment. */
1275-
context_p->status_flags |= PARSER_LEXICAL_ENV_NEEDED;
1275+
JERRY_ASSERT (context_p->status_flags & PARSER_LEXICAL_ENV_NEEDED);
12761276
}
12771277

12781278
if (!(context_p->status_flags & PARSER_LEXICAL_ENV_NEEDED))

tests/jerry/es2015/arrow-eval.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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+
16+
let a = 4
17+
18+
var f = () => {
19+
eval("var a = 5")
20+
assert(a === 5)
21+
}
22+
f()
23+
24+
assert(a === 4)
25+
26+
function g() {
27+
eval("var b = 6")
28+
29+
assert(b === 6)
30+
31+
var h = () => delete b
32+
h()
33+
34+
try {
35+
b
36+
assert(false)
37+
} catch (e) {
38+
assert(e instanceof ReferenceError)
39+
}
40+
}
41+
g()

0 commit comments

Comments
 (0)