JDK-8010710.js revision 877:cf4d2252d444
1177633Sdfr/*
2177633Sdfr * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
3177633Sdfr * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4177633Sdfr *
5177633Sdfr * This code is free software; you can redistribute it and/or modify it
6177633Sdfr * under the terms of the GNU General Public License version 2 only, as
7177633Sdfr * published by the Free Software Foundation.
8177633Sdfr *
9177633Sdfr * This code is distributed in the hope that it will be useful, but WITHOUT
10177633Sdfr * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11177633Sdfr * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12177633Sdfr * version 2 for more details (a copy is included in the LICENSE file that
13177633Sdfr * accompanied this code).
14177633Sdfr *
15177633Sdfr * You should have received a copy of the GNU General Public License version
16177633Sdfr * 2 along with this work; if not, write to the Free Software Foundation,
17177633Sdfr * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18177633Sdfr *
19177633Sdfr * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20177633Sdfr * or visit www.oracle.com if you need additional information or have any
21177633Sdfr * questions.
22177633Sdfr */
23177633Sdfr
24177633Sdfr/**
25177633Sdfr * JDK-8010710 - slot/scope problem with temporary expressions
26177633Sdfr * as array index in self modifying assigns
27177633Sdfr *
28177633Sdfr * @test
29177633Sdfr * @run
30177633Sdfr */
31177633Sdfrfunction zero() {
32177633Sdfr    return 0;
33177633Sdfr}
34177633Sdfr
35177633Sdfr//try complex self modifying assignment and force slots to temporary value index operators
36177633Sdfrvar a = [1, 2, 3, 4, 5];
37177633Sdfrvar b = [a, a];
38177633Sdfrprint(b[zero() + 1][2 + a[0]] += 10);
39177633Sdfr
40177633Sdfr//repro for NASHORN-258 that never made it
41177633Sdfrfunction AddRoundKey() {
42177633Sdfr    var r=0;
43177633Sdfr    state[r][1] &= 17;
44177633Sdfr}
45177633Sdfr
46177633Sdfrvar srcFiles = [];
47177633Sdfrfor(i=0;i<100;i++) {
48177633Sdfr    srcFiles.push('dummy');
49177633Sdfr}
50177633Sdfrvar added = '';
51177633Sdfr
52177633Sdfr//this broke the javafx build system. verify it works
53177633Sdfrfunction bouncingBall() {
54177633Sdfr    for (j=0; j<100; j++) {
55177633Sdfr    added += srcFiles[j];
56177633Sdfr    }
57177633Sdfr}
58177633SdfrbouncingBall();
59177633Sdfrprint(added);
60177633Sdfr
61177633Sdfr//this is how they should have done it for speed, that works always, verify this too
62177633Sdfrfunction bouncingBall2() {
63177633Sdfr    for (var k=0; k<100; k++) {
64177633Sdfr    added += srcFiles[k];
65177633Sdfr    }
66177633Sdfr}
67177633SdfrbouncingBall2();
68177633Sdfrprint(added);
69177633Sdfr