nashorn/test/script/basic/NASHORN-207_2.js
author psandoz
Tue, 13 Aug 2013 11:16:37 +0200
changeset 19424 c4524285927f
parent 16151 97c1e756ae1e
child 24778 2ff5d7041566
permissions -rw-r--r--
8022797: Clarify spliterator characteristics for collections containing no elements Reviewed-by: alanb, mduigou
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.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     4
 * 
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.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
     8
 * 
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).
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    14
 * 
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.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    18
 * 
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-207 : Implement strict mode.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    26
 *
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    27
 * @test
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    28
 * @run
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    29
 */
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    30
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    31
// make sure that 'use strict' as first directive inside eval
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    32
// also works the same way (as eval called from strict mode caller).
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    33
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    34
try {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    35
    eval("'use strict'; foo = 4;");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    36
    fail("#1 should have thrown ReferenceError");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    37
} catch (e) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    38
    if (! (e instanceof ReferenceError)) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    39
        fail("#2 expected ReferenceError but got " + e);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    40
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    41
}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    42
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    43
if (typeof foo !== 'undefined') {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    44
    fail("#3 strict mode eval defined var in global scope!");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    45
}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    46
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    47
try {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    48
    eval("'use strict'; var let = 23;");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    49
    fail("#4 should have thrown SyntaxError");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    50
} catch (e) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    51
    if (! (e instanceof SyntaxError)) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    52
        fail("#5 SyntaxError expected but got " + e);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    53
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    54
}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    55
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    56
// non-strict mode, some of the future reserved words can be used
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    57
// as identifiers. These include "let", "implements", "yield" etc.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    58
var let = 30;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    59
var implements = "hello";
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    60
function yield() {}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    61
function public() {}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    62
var private = false;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    63
var protected = "hello";
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    64
var interface = "interface";
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    65
function f(package) {}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    66
function static() {}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    67
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    68
// in strict mode, arguments does not alias named access
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    69
function func(x, y) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    70
    'use strict';
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    71
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    72
    if (x !== arguments[0]) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    73
        fail("#6 arguments[0] !== x");
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
    if (y !== arguments[1]) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    77
        fail("#7 arguments[1] !== y");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    78
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    79
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    80
    arguments[0] = 1;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    81
    arguments[1] = 2;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    82
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    83
    if (x === arguments[0]) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    84
        fail("#8 arguments[0] === x after assignment to it");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    85
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    86
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    87
    if (y === arguments[1]) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    88
        fail("#9 arguments[1] === y after assignment to it ");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    89
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    90
}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    91
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    92
func();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    93
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    94
// functions can not be declared everywhere!!
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    95
try {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    96
    eval("'use strict'; if (true) { function func() {} }");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    97
    fail("#10 should have thrown SyntaxError");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    98
} catch (e) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
    99
    if (! (e instanceof SyntaxError)) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   100
        fail("#11 SyntaxError expected got " + e);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   101
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   102
}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   103
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   104
// arguments.caller and arguments.callee can't read or written in strict mode
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   105
function func2() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   106
    'use strict';
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   107
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   108
    try {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   109
        print(arguments.callee);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   110
        fail("#12 arguments.callee should have thrown TypeError");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   111
    } catch (e) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   112
        if (! (e instanceof TypeError)) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   113
            fail("#13 TypeError expected, got " + e);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   114
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   115
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   116
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   117
    try {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   118
        print(arguments.caller);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   119
        fail("#14 arguments.caller should have thrown TypeError");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   120
    } catch (e) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   121
        if (! (e instanceof TypeError)) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   122
            fail("#15 TypeError expected, got " + e);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   123
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   124
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   125
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   126
    try {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   127
        arguments.caller = 10;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   128
        fail("#16 arguments.caller assign should have thrown TypeError");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   129
    } catch (e) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   130
        if (! (e instanceof TypeError)) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   131
            fail("#17 TypeError expected, got " + e);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   132
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   133
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   134
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   135
    try {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   136
        arguments.callee = true;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   137
        fail("#18 arguments.callee assign should have thrown TypeError");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   138
    } catch (e) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   139
        if (! (e instanceof TypeError)) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   140
            fail("#19 TypeError expected, got " + e);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   141
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   142
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   143
}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   144
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   145
func2();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   146
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   147
// func.caller and func.arguments can't read or written in strict mode
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   148
function func3() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   149
    'use strict';
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   150
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   151
    try {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   152
        print(func3.arguments);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   153
        fail("#20 func.arguments should have thrown TypeError");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   154
    } catch (e) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   155
        if (! (e instanceof TypeError)) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   156
            fail("#21 TypeError expected, got " + e);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   157
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   158
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   159
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   160
    try {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   161
        print(func3.caller);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   162
        fail("#22 func3.caller should have thrown TypeError");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   163
    } catch (e) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   164
        if (! (e instanceof TypeError)) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   165
            fail("#23 TypeError expected, got " + e);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   166
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   167
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   168
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   169
    try {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   170
        func3.arguments = 10;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   171
        fail("#24 func3.arguments assign should have thrown TypeError");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   172
    } catch (e) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   173
        if (! (e instanceof TypeError)) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   174
            fail("#25 TypeError expected, got " + e);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   175
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   176
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   177
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   178
    try {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   179
        func3.caller = true;
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   180
        fail("#26 func3.caller assign should have thrown TypeError");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   181
    } catch (e) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   182
        if (! (e instanceof TypeError)) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   183
            fail("#27 TypeError expected, got " + e);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   184
        }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   185
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   186
}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   187
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   188
func3();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   189
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   190
try {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   191
    eval("function eval() { 'use strict'; }");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   192
    fail("#28 should have thrown SyntaxError");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   193
} catch (e) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   194
    if (! (e instanceof SyntaxError)) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   195
        fail("#29 SyntaxError expected, got " + e);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   196
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   197
}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   198
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   199
function func4() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   200
  'use \
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   201
strict';
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   202
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   203
    // The use strict directive can't contain line continuation.
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   204
    // So this is not a strict mode function!!
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   205
    with({}) {}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   206
}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   207
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   208
func4();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   209
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   210
function func5() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   211
   'use\u2028strict';
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   212
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   213
    // The use strict directive can't contain unicode whitespace escapes
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   214
    // So this is not a strict mode function!!
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   215
    with({}) {}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   216
}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   217
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   218
func5();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   219
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   220
function func6() {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   221
   'use\u2029strict';
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   222
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   223
    // The use strict directive can't contain unicode whitespace escapes
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   224
    // So this is not a strict mode function!!
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   225
    with({}) {}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   226
}
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   227
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   228
func6();
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   229
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   230
try {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   231
    eval("'bogus directive'; 'use strict'; eval = 10");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   232
    fail("#30 SyntaxError expected from eval");
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   233
} catch (e) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   234
    if (! (e instanceof SyntaxError)) {
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   235
        fail("#31 SyntaxError expected but got " + e);
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   236
    }
e63b63819133 8005403: Open-source Nashorn
jlaskey
parents:
diff changeset
   237
}