Skip to content

Commit 7734f87

Browse files
authored
For in-of declaration should only throw error after initialization. (#3541)
This patch fixes the error introduced in #3513. JerryScript-DCO-1.0-Signed-off-by: Robert Fancsik [email protected]
1 parent 2fe06f8 commit 7734f87

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,11 +1168,6 @@ parser_parse_for_statement_start (parser_context_t *context_p) /**< context */
11681168
|| context_p->token.type == LEXER_KEYW_LET
11691169
|| context_p->token.type == LEXER_KEYW_CONST)
11701170
{
1171-
if (context_p->status_flags & PARSER_IS_STRICT)
1172-
{
1173-
parser_raise_error (context_p, PARSER_ERR_FOR_IN_OF_DECLARATION);
1174-
}
1175-
11761171
token_type = context_p->token.type;
11771172
has_context = (context_p->token.type != LEXER_KEYW_VAR);
11781173
scanner_get_location (&start_location, context_p);
@@ -1311,6 +1306,12 @@ parser_parse_for_statement_start (parser_context_t *context_p) /**< context */
13111306

13121307
if (context_p->token.type == LEXER_ASSIGN)
13131308
{
1309+
#if ENABLED (JERRY_ES2015)
1310+
if (context_p->status_flags & PARSER_IS_STRICT)
1311+
{
1312+
parser_raise_error (context_p, PARSER_ERR_FOR_IN_OF_DECLARATION);
1313+
}
1314+
#endif /* ENABLED (JERRY_ES2015) */
13141315
parser_branch_t branch;
13151316

13161317
/* Initialiser is never executed. */

tests/jerry/es2015/forin-header-strict.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,35 @@ try {
2727
} catch (e) {
2828
assert(e instanceof SyntaxError);
2929
}
30+
31+
var reached = false;
32+
33+
for (var i in {}) {
34+
reached = true;
35+
}
36+
assert(!reached);
37+
38+
for (var i of []) {
39+
reached = true;
40+
}
41+
assert(!reached);
42+
43+
for (let i in {}) {
44+
reached = true;
45+
}
46+
assert(!reached);
47+
48+
for (let i of []) {
49+
reached = true;
50+
}
51+
assert(!reached);
52+
53+
for (const i in {}) {
54+
reached = true;
55+
}
56+
assert(!reached);
57+
58+
for (const i of []) {
59+
reached = true;
60+
}
61+
assert(!reached);

0 commit comments

Comments
 (0)