for-let-object-fields.js revision 1142:c4c3be2ab854
1111888Sjlemon/*
2193219Srwatson * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
3103781Sjake * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4103781Sjake *
5103781Sjake * This code is free software; you can redistribute it and/or modify it
6103781Sjake * under the terms of the GNU General Public License version 2 only, as
7103781Sjake * published by the Free Software Foundation.
8103781Sjake *
9111888Sjlemon * This code is distributed in the hope that it will be useful, but WITHOUT
10103781Sjake * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11103781Sjake * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12103781Sjake * version 2 for more details (a copy is included in the LICENSE file that
13103781Sjake * accompanied this code).
14111888Sjlemon *
15111888Sjlemon * You should have received a copy of the GNU General Public License version
16111888Sjlemon * 2 along with this work; if not, write to the Free Software Foundation,
17111888Sjlemon * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18111888Sjlemon *
19111888Sjlemon * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20111888Sjlemon * or visit www.oracle.com if you need additional information or have any
21111888Sjlemon * questions.
22111888Sjlemon */
23111888Sjlemon
24111888Sjlemon/**
25193219Srwatson * JDK-8067219: NPE in ScriptObject.clone() when running with object fields
26193219Srwatson *
27193219Srwatson * @test
28193219Srwatson * @run
29193219Srwatson * @fork
30193219Srwatson * @option -Dnashorn.fields.objects=true
31193219Srwatson * @option --language=es6
32193219Srwatson */
33193219Srwatson
34193219Srwatson"use strict";
35200898Srwatson
36200898Srwatsonfor (let i = 0; i < 10; i++) {
37200898Srwatson    print(i);
38103781Sjake}
39200898Srwatson
40193219Srwatsontry {
41200898Srwatson    print(i);
42193219Srwatson} catch (e) {
43193219Srwatson    print(e);
44193219Srwatson}
45193219Srwatson
46193219Srwatsonlet a = [];
47193219Srwatson
48193219Srwatsonfor (let i = 0; i < 10; i++) {
49193219Srwatson    a.push(function() { print(i); });
50193219Srwatson}
51193219Srwatson
52193219Srwatsona.forEach(function(f) { f(); });
53193219Srwatson
54193219Srwatsona = [];
55193219Srwatson
56193219Srwatsonfor (let i = 0; i < 10; i++) {
57200898Srwatson    if (i == 5) {
58193219Srwatson        i = "foo";
59200898Srwatson    }
60103781Sjake    a.push(function() { print(i); });
61103781Sjake}
62193219Srwatson
63150968Sglebiusa.forEach(function(f) { f(); });
64134443Srwatson
65103781Sjaketry {
66111888Sjlemon    print(i);
67103781Sjake} catch (e) {
68111888Sjlemon    print(e);
69193219Srwatson}
70111888Sjlemon
71193219Srwatsona = [];
72193219Srwatson
73195019Srwatsonfor (let i = 0; i < 20; i++) {
74111888Sjlemon    if (i % 2 == 1) {
75193219Srwatson        i += 2;
76193219Srwatson        continue;
77193219Srwatson    }
78193219Srwatson    a.push(function() { print(i); });
79111888Sjlemon}
80193219Srwatson
81103781Sjakea.forEach(function(f) { f(); });
82193219Srwatson