for-let.js revision 1142:c4c3be2ab854
1239332Sjkim/*
2239332Sjkim * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
3239332Sjkim * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4239332Sjkim *
5239332Sjkim * This code is free software; you can redistribute it and/or modify it
6239332Sjkim * under the terms of the GNU General Public License version 2 only, as
7239332Sjkim * published by the Free Software Foundation.
8239332Sjkim *
9239332Sjkim * This code is distributed in the hope that it will be useful, but WITHOUT
10239332Sjkim * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11239332Sjkim * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12239332Sjkim * version 2 for more details (a copy is included in the LICENSE file that
13239332Sjkim * accompanied this code).
14239332Sjkim *
15239332Sjkim * You should have received a copy of the GNU General Public License version
16239332Sjkim * 2 along with this work; if not, write to the Free Software Foundation,
17239332Sjkim * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18239332Sjkim *
19239332Sjkim * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20239332Sjkim * or visit www.oracle.com if you need additional information or have any
21239332Sjkim * questions.
22239332Sjkim */
23239332Sjkim
24239332Sjkim/**
25239332Sjkim * JDK-8051889: Implement block scoping in symbol assignment and scope computation
26239332Sjkim *
27239332Sjkim * @test
28239332Sjkim * @run
29239332Sjkim * @option --language=es6
30239332Sjkim */
31239332Sjkim
32239332Sjkim"use strict";
33239332Sjkim
34239332Sjkimfor (let i = 0; i < 10; i++) {
35239332Sjkim    print(i);
36239332Sjkim}
37239332Sjkim
38239332Sjkimtry {
39239332Sjkim    print(i);
40239332Sjkim} catch (e) {
41239332Sjkim    print(e);
42239332Sjkim}
43239332Sjkim
44239332Sjkimlet a = [];
45239332Sjkim
46239332Sjkimfor (let i = 0; i < 10; i++) {
47239332Sjkim    a.push(function() { print(i); });
48239332Sjkim}
49239332Sjkim
50239332Sjkima.forEach(function(f) { f(); });
51239332Sjkim
52239332Sjkima = [];
53239332Sjkim
54239332Sjkimfor (let i = 0; i < 10; i++) {
55239332Sjkim    if (i == 5) {
56239332Sjkim        i = "foo";
57239332Sjkim    }
58239332Sjkim    a.push(function() { print(i); });
59239332Sjkim}
60239332Sjkim
61239332Sjkima.forEach(function(f) { f(); });
62239332Sjkim
63239332Sjkimtry {
64239332Sjkim    print(i);
65239332Sjkim} catch (e) {
66239332Sjkim    print(e);
67239332Sjkim}
68239332Sjkim
69239332Sjkima = [];
70239332Sjkim
71239332Sjkimfor (let i = 0; i < 20; i++) {
72239332Sjkim    if (i % 2 == 1) {
73239332Sjkim        i += 2;
74239332Sjkim        continue;
75239332Sjkim    }
76239332Sjkim    a.push(function() { print(i); });
77239332Sjkim}
78239332Sjkim
79239332Sjkima.forEach(function(f) { f(); });
80239332Sjkim