nashorn/test/script/basic/NASHORN-19.js
author martin
Wed, 10 Dec 2014 09:23:00 -0800
changeset 28057 1a47ceecdba5
parent 24778 2ff5d7041566
permissions -rw-r--r--
8065804: JEP 171: Clarifications/corrections for fence intrinsics Reviewed-by: dholmes, shade, dl, psandoz
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     1
/*
16151
97c1e756ae1e 8005663: Update copyright year to 2013
jlaskey
parents: 16147
diff changeset
     2
 * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
     4
 *
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     7
 * published by the Free Software Foundation.
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
     8
 *
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    13
 * accompanied this code).
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
    14
 *
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
    18
 *
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    21
 * questions.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    22
 */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    23
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    24
/**
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    25
 * NASHORN-19:  with blocks in various scopes and breaking from them if they are inloops
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    26
 * (also continues)
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    27
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    28
 * @test
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    29
 * @run
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    30
 */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    31
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    32
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    33
var myvalue = "hello";
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    34
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    35
var myscope = {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    36
    myvalue: 11
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    37
};
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    38
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    39
do {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    40
    with(myscope) {
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
    41
    myvalue = 12;
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
    42
    break;
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    43
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    44
} while (false);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    45
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    46
if (myvalue != 'hello') {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    47
    throw "expecting to be hello";
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    48
} else {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    49
    print("value is 'hello' as expected");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    50
}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    51
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    52
print("\n");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    53
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    54
function ten() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    55
    return 0xa;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    56
}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    57
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    58
//make sure the scope works outside functions too
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    59
print("starting 0");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    60
var value = "hello";
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    61
var scope = {value:10};
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    62
var scope2 = {value:20};
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    63
while (true) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    64
    with (scope) {
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
    65
    print(value);
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
    66
    value = 11;
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
    67
    print(value);
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
    68
    with (scope2) {
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
    69
        print(value);
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
    70
        value = 21;
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
    71
        print(value);
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
    72
        break;
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
    73
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    74
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    75
}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    76
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    77
print(value);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    78
print("\n");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    79
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    80
//two level scope
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    81
function test1() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    82
    var value = "hello";
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    83
    var scope = {value:10};
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    84
    var scope2 = {value:20};
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    85
    while (true) {
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
    86
    with (scope) {
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
    87
        print(value);
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
    88
        value = 11;
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
    89
        print(value);
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
    90
        with (scope2) {
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
    91
        print(value);
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
    92
        value = 21;
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
    93
        print(value);
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
    94
        break;
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
    95
        }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    96
    }
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
    97
    }
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
    98
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    99
    print(value);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   100
}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   101
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   102
//one level scope
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   103
function test2() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   104
    var value = "hello";
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   105
    var scope = {value:10};
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   106
    while (true) {
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   107
    with (scope) {
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   108
        print(value);
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   109
        value = 11;
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   110
        print(value);
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   111
        if (value > ten()) {
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   112
        break;
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   113
        }
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   114
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   115
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   116
    print(value);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   117
}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   118
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   119
//continue two levels
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   120
function test3() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   121
    var value = "hello";
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   122
    var scope = {value:10};
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   123
    var scope2 = {value:20};
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   124
    var outer = 0;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   125
    while (outer < 5) {
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   126
    var i=0;
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   127
    while (i < 10) {
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   128
        with(scope) {
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   129
        print("loop header "+i);
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   130
        with (scope2) {
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   131
            value = 11;
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   132
            i++;
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   133
            if ((i & 1) != 0) {
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   134
            print("continue");
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   135
            continue;
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   136
            }
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   137
        }
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   138
        }
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   139
        print(value);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   140
    }
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   141
    outer++;
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   142
    }
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   143
}
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   144
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   145
//continue one level
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   146
function test4() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   147
    var value = "hello";
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   148
    var scope = {value:10};
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   149
    var i=0;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   150
    while (i < 10) {
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   151
    print("loop header "+i);
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   152
    with (scope) {
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   153
        value = 11;
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   154
        i++;
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   155
        if ((i & 1) != 0) {
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   156
        print("continue");
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   157
        continue;
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   158
        }
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   159
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   160
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   161
    print(value);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   162
}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   163
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   164
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   165
//labelled continue;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   166
function test5() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   167
    var value = "hello";
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   168
    var scope = {value:10};
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   169
    var scope2 = {value:20};
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   170
    var outer = 0;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   171
    outer_label:
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   172
    while (outer < 5) {
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   173
    var i=0;
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   174
    while (i < 10) {
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   175
        with(scope) {
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   176
        print("loop header "+i);
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   177
        with (scope2) {
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   178
            value = 11;
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   179
            i++;
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   180
            if ((i & 1) != 0) {
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   181
            print("continue");
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   182
            outer++;
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   183
            continue outer_label;
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   184
            }
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   185
        }
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   186
        }
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   187
        print(value);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   188
    }
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   189
    }
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   190
}
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   191
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   192
//labelled break
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   193
function test6() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   194
    var value = "hello";
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   195
    var scope = {value:10};
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   196
    var scope2 = {value:20};
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   197
    outer:
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   198
    {
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   199
    var i=0;
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   200
    while (i < 10) {
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   201
        with(scope) {
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   202
        print("loop header "+i);
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   203
        with (scope2) {
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   204
            value = 11;
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   205
            i++;
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   206
            if ((i & 1) != 0) {
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   207
            print("break");
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   208
            break outer;
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   209
            }
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   210
        }
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   211
        }
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   212
        print(value);
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   213
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   214
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   215
}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   216
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   217
//exceptions in one scope and then the other
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   218
function test7() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   219
    var value = "hello";
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   220
    var scope = {value:10};
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   221
    var scope2 = {value:20};
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   222
    var global = false;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   223
    try {
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   224
    with(scope) {
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   225
        try {
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   226
        print(value);
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   227
        value = 4711;
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   228
        print(value);
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   229
        with(scope2) {
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   230
            print(value);
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   231
            value = 17;
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   232
            print(value);
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   233
            global = true;
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   234
            throw "inner";
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   235
        }
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   236
        } catch (ei) {
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   237
        print(ei);
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   238
        print(value);
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   239
        if (global) {
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   240
            throw "outer";
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   241
        }
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   242
        }
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   243
    }
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   244
    } catch (eo) {
24778
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   245
    print(eo);
2ff5d7041566 8044638: Tidy up Nashorn codebase for code standards
attila
parents: 16151
diff changeset
   246
    print(value);
16147
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   247
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   248
    print(value);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   249
}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   250
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   251
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   252
print("starting 1");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   253
test1();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   254
print("\n");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   255
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   256
print("starting 2");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   257
test2();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   258
print("\n");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   259
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   260
print("starting 3");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   261
test3();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   262
print("\n");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   263
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   264
print("starting 4");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   265
test4();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   266
print("\n");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   267
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   268
print("starting 5");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   269
test5();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   270
print("\n");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   271
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   272
print("starting 6");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   273
test6();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   274
print("\n");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   275
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   276
print("starting 7");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   277
test7();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   278
print("\n");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   279