Skip to content

Commit c6f9ea6

Browse files
authored
Declaration in the head of a for-of loop can't have an initializer (#4804)
JerryScript-DCO-1.0-Signed-off-by: Robert Sipka [email protected] Co-authored-by: Robert Sipka <[email protected]>
1 parent 499cdea commit c6f9ea6

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1414,7 +1414,7 @@ parser_parse_for_statement_start (parser_context_t *context_p) /**< context */
14141414
if (context_p->token.type == LEXER_ASSIGN)
14151415
{
14161416
#if JERRY_ESNEXT
1417-
if (context_p->status_flags & PARSER_IS_STRICT)
1417+
if ((context_p->status_flags & PARSER_IS_STRICT) || !is_for_in)
14181418
{
14191419
parser_raise_error (context_p, PARSER_ERR_FOR_IN_OF_DECLARATION);
14201420
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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+
function parse(txt) {
17+
try {
18+
eval(txt)
19+
assert(false)
20+
} catch (e) {
21+
assert(e instanceof SyntaxError)
22+
}
23+
}
24+
25+
parse("for (var x = 1 of []) { }")

tests/test262-esnext-excludelist.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,8 @@
343343
<test id="language/statements/for-of/cptn-expr-abrupt-empty.js"><reason></reason></test>
344344
<test id="language/statements/for-of/cptn-expr-itr.js"><reason></reason></test>
345345
<test id="language/statements/for-of/cptn-expr-no-itr.js"><reason></reason></test>
346-
<test id="language/statements/for-of/head-const-init.js"><reason></reason></test>
347346
<test id="language/statements/for-of/head-decl-no-expr.js"><reason></reason></test>
348347
<test id="language/statements/for-of/head-expr-no-expr.js"><reason></reason></test>
349-
<test id="language/statements/for-of/head-let-init.js"><reason></reason></test>
350-
<test id="language/statements/for-of/head-var-init.js"><reason></reason></test>
351348
<test id="language/statements/for-of/head-var-no-expr.js"><reason></reason></test>
352349
<test id="language/statements/for-of/let-block-with-newline.js"><reason></reason></test>
353350
<test id="language/statements/for-of/let-identifier-with-newline.js"><reason></reason></test>
@@ -7702,9 +7699,6 @@
77027699
<test id="language/statements/for-await-of/async-gen-dstr-var-obj-ptrn-prop-id-get-value-err.js"><reason></reason></test>
77037700
<test id="language/statements/for-await-of/async-gen-dstr-var-obj-ptrn-prop-id-init-throws.js"><reason></reason></test>
77047701
<test id="language/statements/for-await-of/async-gen-dstr-var-obj-ptrn-prop-id-init-unresolvable.js"><reason></reason></test>
7705-
<test id="language/statements/for-await-of/head-const-init.js"><reason></reason></test>
7706-
<test id="language/statements/for-await-of/head-let-init.js"><reason></reason></test>
7707-
<test id="language/statements/for-await-of/head-var-init.js"><reason></reason></test>
77087702
<test id="language/statements/for-await-of/let-block-with-newline.js"><reason></reason></test>
77097703
<test id="language/statements/for-await-of/let-identifier-with-newline.js"><reason></reason></test>
77107704
<test id="language/statements/for-await-of/ticks-with-sync-iter-resolved-promise-and-constructor-lookup.js"><reason></reason></test>

0 commit comments

Comments
 (0)