Skip to content

Commit 049a0c4

Browse files
authored
Fix ReferenceError for let/const variables in of/in for loop (#3885)
ReferenceError should be thrown when variable is used before assignment JerryScript-DCO-1.0-Signed-off-by: Rafal Walczyna r.walczyna@samsung.com
1 parent 1bf52f5 commit 049a0c4

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2108,7 +2108,7 @@ scanner_scan_statement_end (parser_context_t *context_p, /**< context */
21082108
while ((literal_p = (lexer_lit_location_t *) parser_list_iterator_next (&literal_iterator)) != NULL)
21092109
{
21102110
if ((literal_p->type & (SCANNER_LITERAL_IS_LET | SCANNER_LITERAL_IS_CONST))
2111-
&& literal_p->type & SCANNER_LITERAL_NO_REG)
2111+
&& (literal_p->type & SCANNER_LITERAL_IS_USED))
21122112
{
21132113
literal_p->type |= SCANNER_LITERAL_EARLY_CREATE;
21142114
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 check_reference_error (code)
17+
{
18+
try {
19+
eval (code)
20+
assert (false)
21+
} catch (e) {
22+
assert (e instanceof ReferenceError)
23+
}
24+
}
25+
26+
check_reference_error("for (let x of [x]) {}")
27+
check_reference_error("for (const x of [x]) {}")
28+
29+
check_reference_error("for (let x in {x}) {}")
30+
check_reference_error("for (const x in {x}) {}")

tests/test262-es6-excludelist.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,12 +422,8 @@
422422
<test id="language/statements/continue/labeled-continue.js"><reason></reason></test>
423423
<test id="language/statements/continue/nested-let-bound-for-loops-labeled-continue.js"><reason></reason></test>
424424
<test id="language/statements/continue/simple-and-labeled.js"><reason></reason></test>
425-
<test id="language/statements/for-in/const-bound-names-fordecl-tdz-for-in.js"><reason></reason></test>
426-
<test id="language/statements/for-in/let-bound-names-fordecl-tdz-for-in.js"><reason></reason></test>
427425
<test id="language/statements/for-of/body-dstr-assign-error.js"><reason></reason></test>
428426
<test id="language/statements/for-of/body-dstr-assign.js"><reason></reason></test>
429-
<test id="language/statements/for-of/const-bound-names-fordecl-tdz-for-of.js"><reason></reason></test>
430-
<test id="language/statements/for-of/let-bound-names-fordecl-tdz-for-of.js"><reason></reason></test>
431427
<test id="language/statements/for/S12.6.3_A9.1.js"><reason></reason></test>
432428
<test id="language/statements/for/S12.6.3_A9.js"><reason></reason></test>
433429
<test id="language/statements/function/13.2-30-s.js"><reason></reason></test>

0 commit comments

Comments
 (0)